Fork of original library to fix mbed 5 deprecation warnings

Dependencies:   LPC1114_WakeInterruptIn

Dependents:   low-power-sleep

Fork of WakeUp by Erik -

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers WakeUp_LPC11u24.cpp Source File

WakeUp_LPC11u24.cpp

00001 /**
00002 Due to lack of another option for the LPC11u24 the watchdog timer is used as wakeup source.
00003 Since if the reset on watchdog event bit is set, I cannot remove it again, this means if you also got watchdog code running
00004 the most likely result is that it just resets your board.
00005 **/
00006 
00007 
00008 #ifdef TARGET_LPC11U24
00009 
00010 #include "WakeUp.h"
00011 
00012 Callback<void()> WakeUp::cbk;
00013 float WakeUp::cycles_per_ms = 5.0;
00014 
00015 void WakeUp::set_ms(uint32_t ms)
00016 {
00017     if (ms != 0) {
00018         LPC_SYSCON->SYSAHBCLKCTRL |= 0x8000;
00019         LPC_SYSCON->PDRUNCFG &= ~(1<<6);
00020         LPC_SYSCON->PDSLEEPCFG &= ~(1<<6);
00021         LPC_SYSCON->STARTERP1 |= 1<<12;
00022         
00023         //Set oscillator for 20kHz = 5kHz after divide by 4 in WDT
00024         LPC_SYSCON->WDTOSCCTRL = 14 | (1<<5);
00025         
00026         LPC_WWDT->MOD = 1;      //Enable WDT
00027         LPC_WWDT->TC = (uint32_t)((float)ms * cycles_per_ms);
00028         LPC_WWDT->CLKSEL = 1;   //WDTOSC
00029         LPC_WWDT->WARNINT = 0;
00030         
00031         NVIC_SetVector(WDT_IRQn, (uint32_t)WakeUp::irq_handler);
00032         
00033         //Feeeeeed me
00034         LPC_WWDT->FEED = 0xAA;
00035         LPC_WWDT->FEED = 0x55;
00036         
00037         NVIC_EnableIRQ(WDT_IRQn);
00038     } else
00039         NVIC_DisableIRQ(WDT_IRQn);
00040     
00041 }
00042 
00043 void WakeUp::irq_handler(void)
00044 {
00045     LPC_WWDT->MOD = 1<<3;
00046     if (cbk) {
00047         cbk.call();
00048     }
00049 }
00050 
00051 void WakeUp::calibrate(void)
00052 {
00053     cycles_per_ms = 5.0;
00054     set_ms(1100);
00055     wait_ms(10);    //Give time to sync
00056     uint32_t count1 = LPC_WWDT->TV;
00057     wait_ms(100);
00058     uint32_t count2 = LPC_WWDT->TV;
00059     set_ms(0);
00060     count1 = count1 - count2;
00061     
00062     cycles_per_ms = count1 / 100.0;
00063 }
00064 
00065 #endif