add the implementation of LP1768 wakeup based on the old WakeUp library
Dependencies: LPC1114_WakeInterruptIn
Fork of WakeUp by
Diff: WakeUp_LPC1768.cpp
- Revision:
- 7:542c0ca509e5
diff -r 815bef56e136 -r 542c0ca509e5 WakeUp_LPC1768.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/WakeUp_LPC1768.cpp Mon Jul 21 13:45:48 2014 +0000 @@ -0,0 +1,59 @@ +/** +Due to lack of another option for the LPC11u24 the watchdog timer is used as wakeup source. +Since if the reset on watchdog event bit is set, I cannot remove it again, this means if you also got watchdog code running +the most likely result is that it just resets your board. +**/ + + +#ifdef TARGET_LPC1768 + +#include "WakeUp.h" + +FunctionPointer WakeUp::callback; +float WakeUp::cycles_per_ms = 5.0; + +void WakeUp::set_ms(uint32_t ms) +{ + + LPC_WDT->WDCLKSEL = 0x2; // Set CLK src to PCLK + //uint32_t clk = SystemCoreClock / 16; // WD has a fixed /4 prescaler, PCLK default is /4 + // LPC_WDT->WDTC = ms * (float)clk/1000; + LPC_WDT->WDTC = (ms/4.0)*32768/1000; + LPC_WDT->WDMOD = 0x3; // Enabled and Reset enabled, if not reset, WDINT will not be clearred + + NVIC_SetVector(WDT_IRQn, (uint32_t)WakeUp::irq_handler); + + //Feeeeeed me + LPC_WDT->WDFEED = 0xAA; + LPC_WDT->WDFEED = 0x55; + NVIC_ClearPendingIRQ(WDT_IRQn); + NVIC_EnableIRQ(WDT_IRQn); + +} + +void WakeUp::irq_handler(void) +{ //SCB->AIRCR |= 1<< SCB_AIRCR_SYSRESETREQ_Pos; // request a reset to get out of deepesleep + LPC_WDT->WDMOD = 1<<3; + // LPC_WDT->WDMOD &= ~(1<<2); + // LPC_WDT->WDMOD |= 1<<2; + // SCB->AIRCR |= 1<< SCB_AIRCR_SYSRESETREQ_Pos; // request a reset to get out of deepesleep + NVIC_DisableIRQ(WDT_IRQn); + callback.call(); +} + +void WakeUp::calibrate(void) +{ + cycles_per_ms = 5.0; + set_ms(1100); + wait_ms(10); //Give time to sync + uint32_t count1 = LPC_WDT->WDTV; + wait_ms(100); + uint32_t count2 = LPC_WDT->WDTV; + set_ms(0); + count1 = count1 - count2; + + cycles_per_ms = count1 / 100.0; +} + +#endif +