add the implementation of LP1768 wakeup based on the old WakeUp library
Dependencies: LPC1114_WakeInterruptIn
Fork of WakeUp by
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 FunctionPointer WakeUp::callback; 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 callback.call(); 00047 } 00048 00049 void WakeUp::calibrate(void) 00050 { 00051 cycles_per_ms = 5.0; 00052 set_ms(1100); 00053 wait_ms(10); //Give time to sync 00054 uint32_t count1 = LPC_WWDT->TV; 00055 wait_ms(100); 00056 uint32_t count2 = LPC_WWDT->TV; 00057 set_ms(0); 00058 count1 = count1 - count2; 00059 00060 cycles_per_ms = count1 / 100.0; 00061 } 00062 00063 #endif
Generated on Wed Jul 13 2022 02:11:11 by 1.7.2