Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of WakeUp by
Diff: Device/WakeUp_LPC11u24.cpp
- Revision:
- 18:e71f388710b7
- Parent:
- 7:bb411115f814
- Child:
- 19:c1fc9bb48d2b
--- a/Device/WakeUp_LPC11u24.cpp Wed Apr 22 20:36:13 2015 +0000
+++ b/Device/WakeUp_LPC11u24.cpp Thu Jun 25 08:18:26 2015 +0000
@@ -11,6 +11,7 @@
FunctionPointer WakeUp::callback;
float WakeUp::cycles_per_ms = 5.0;
+uint32_t WakeUp::timeoutSet = 0;
void WakeUp::set_ms(uint32_t ms)
{
@@ -19,25 +20,26 @@
LPC_SYSCON->PDRUNCFG &= ~(1<<6);
LPC_SYSCON->PDSLEEPCFG &= ~(1<<6);
LPC_SYSCON->STARTERP1 |= 1<<12;
-
+
//Set oscillator for 20kHz = 5kHz after divide by 4 in WDT
LPC_SYSCON->WDTOSCCTRL = 14 | (1<<5);
-
+
LPC_WWDT->MOD = 1; //Enable WDT
- LPC_WWDT->TC = (uint32_t)((float)ms * cycles_per_ms);
+ timeoutSet = (uint32_t)((float)ms * cycles_per_ms);
+ LPC_WWDT->TC = timeoutSet;
LPC_WWDT->CLKSEL = 1; //WDTOSC
LPC_WWDT->WARNINT = 0;
-
+
NVIC_SetVector(WDT_IRQn, (uint32_t)WakeUp::irq_handler);
-
+
//Feeeeeed me
LPC_WWDT->FEED = 0xAA;
LPC_WWDT->FEED = 0x55;
-
+
NVIC_EnableIRQ(WDT_IRQn);
} else
NVIC_DisableIRQ(WDT_IRQn);
-
+
}
void WakeUp::irq_handler(void)
@@ -56,8 +58,13 @@
uint32_t count2 = LPC_WWDT->TV;
set_ms(0);
count1 = count1 - count2;
-
+
cycles_per_ms = count1 / 100.0;
}
+uint32_t WakeUp::timeRemaining(void)
+{
+ return (uint32_t)((LPC_WWDT->TV - timeoutSet) / cycles_per_ms);
+}
+
#endif
