Modified WakeUp program to run on STM32L152RE

Dependencies:   mbed LPC1114_WakeInterruptIn

Fork of WakeUp by Erik -

Revision:
12:779d866b8a2d
Parent:
11:72db657fc572
Child:
13:fd24cec76d5a
--- a/Device/WakeUp_LPC11XX.cpp	Wed Jul 30 09:53:58 2014 +0000
+++ b/Device/WakeUp_LPC11XX.cpp	Wed Jul 30 15:07:08 2014 +0000
@@ -6,6 +6,7 @@
 
 #include "WakeUp.h"
 #include "WakeInterruptIn.h"
+#include "pinmap.h"
 
 //Pin used, allowed pins = P0_1 (dp24, default), P0_8 (dp1) and P0_9 (dp2)
 //By defining WakeUpPin in for example your main.cpp this can be overridden
@@ -106,6 +107,28 @@
 
 void WakeUp::calibrate(void)
 {
+    //Set oscillator for 20kHz
+    LPC_SYSCON->PDRUNCFG &= ~PDRUNCFG_WDTOSC_PD;
+    LPC_SYSCON->WDTOSCCTRL = 14 | (1<<5);
+    
+    //Direct WDT to the CLKOUT pin (dp24), sample it back
+    DigitalIn din(dp24);
+    Timer timer;
+    
+    LPC_SYSCON->CLKOUTDIV = 1;
+    LPC_SYSCON->CLKOUTCLKSEL = 0x2;
+    LPC_SYSCON->CLKOUTUEN = 0;
+    LPC_SYSCON->CLKOUTUEN = CLKOUTUEN_ENA;
+    pin_function(dp24, 1);
+    
+    int count = 0;
+    timer.start();
+    while (timer.read_ms() < 100) {
+        while (din.read() == 0);
+        while (din.read() == 1);
+        count++;
+    }
+    cycles_per_ms = (float)count / 100.0f;
 }
 
 static inline void restore(void) {