Watchdog Timer for the K64F. User can set timeout value from 1 to 356 seconds with a one second resolution.

Dependents:   Telliskivi2_2014 mbed-IBooth-ETH TwitterReader

Revision:
0:2a46d40a176e
Child:
1:70e99b5845fd
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Watchdog.cpp	Mon Oct 20 23:40:26 2014 +0000
@@ -0,0 +1,31 @@
+#include "mbed.h"
+#include "Watchdog.h"
+
+void Watchdog::kick(int toVal) {  
+    const uint32_t K64FWDONESEC = 0x00B80000;   //approx 1 second delay
+    if((toVal < 1) || (toVal > 356)) toVal = 356;
+    WDOG_UNLOCK = 0xC520; 
+    WDOG_UNLOCK = 0xD928;
+    uint32_t wdogCntl = K64FWDONESEC * toVal;
+    WDOG_TOVALH = wdogCntl >> 16;
+    WDOG_TOVALL = wdogCntl & 0xFFFF;
+    EnableWDOG();
+}
+
+void Watchdog::kick() {
+    WDOG_REFRESH = 0xA602; 
+    WDOG_REFRESH = 0xB480; 
+}
+
+void Watchdog::DisableWDOG() {   
+    WDOG_UNLOCK = 0xC520; 
+    WDOG_UNLOCK = 0xD928; 
+    WDOG_STCTRLH &= 0xFFFE;
+}
+    
+void Watchdog::EnableWDOG() {   
+    WDOG_UNLOCK = 0xC520; 
+    WDOG_UNLOCK = 0xD928; 
+    WDOG_STCTRLH |= 0x0001;
+    kick();
+}
\ No newline at end of file