Wake-up timer library to wake from deepsleep/power-down

Dependencies:   LPC1114_WakeInterruptIn

Fork of WakeUp by Erik -

Files at this revision

API Documentation at this revision

Comitter:
Sissors
Date:
Thu Feb 20 18:12:42 2014 +0000
Parent:
4:ec26a6713bb9
Child:
6:815bef56e136
Commit message:
Support al KLxx devices and properly use new ticker timer setups

Changed in this revision

WakeUp_KLxxZ.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/WakeUp_KLxxZ.cpp	Sun Jan 12 14:58:22 2014 +0000
+++ b/WakeUp_KLxxZ.cpp	Thu Feb 20 18:12:42 2014 +0000
@@ -1,4 +1,4 @@
-#if defined TARGET_KL25Z || defined TARGET_KL46Z
+#if defined TARGET_KLXX
 
 #include "WakeUp.h"
 #include "us_ticker_api.h"
@@ -8,6 +8,7 @@
 
 static uint16_t remainder_count;
 static uint32_t oldvector;
+static uint8_t oldPSR;
 
 void restore(void);
 
@@ -18,15 +19,17 @@
     
     //Check if it is running, in that case, store current values
     remainder_count = 0;
-    if (NVIC_GetVector(LPTimer_IRQn) != (uint32_t)WakeUp::irq_handler)
+    if (NVIC_GetVector(LPTimer_IRQn) != (uint32_t)WakeUp::irq_handler) {
         oldvector = NVIC_GetVector(LPTimer_IRQn);
+        oldPSR = LPTMR0->PSR;
         
-    if (LPTMR0->CSR & LPTMR_CSR_TIE_MASK) {
-        //Write first to sync value
-        LPTMR0->CNR = 0;
-        uint16_t countval = LPTMR0->CNR;
-        if (countval < LPTMR0->CMR)
-            remainder_count = countval - LPTMR0->CMR;
+        if (LPTMR0->CSR & LPTMR_CSR_TIE_MASK) {
+            //Write first to sync value
+            LPTMR0->CNR = 0;
+            uint16_t countval = LPTMR0->CNR;
+            if (countval < LPTMR0->CMR)
+                remainder_count = countval - LPTMR0->CMR;
+        }
     }
     
     LPTMR0->CSR = 0;
@@ -95,8 +98,7 @@
     NVIC_EnableIRQ(LPTimer_IRQn);
     
     /* Clock at (1)MHz -> (1)tick/us */
-    LPTMR0->PSR = LPTMR_PSR_PCS(3);       // OSCERCLK -> 8MHz
-    LPTMR0->PSR |= LPTMR_PSR_PRESCALE(2); // divide by 8
+    LPTMR0->PSR = oldPSR;
 
     if (remainder_count) {  
         /* Set the compare register */