Reza Mashayekhi / WatchdogTimer
Revision:
0:dece639e483e
Child:
1:7d0312e56c87
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/WatchdogTimer.cpp	Fri Feb 09 11:13:11 2018 +0000
@@ -0,0 +1,22 @@
+#include "mbed.h"
+#include "WatchdogTimer.h"
+/*
+WatchdogTimer::WatchdogTimer(float TimeInSecond): _kick(TimeInSecond){
+    _kick();
+}
+*/
+// "kick" or "feed" the dog - reset the watchdog timer
+// by writing this required bit pattern
+void WatchdogTimer::kick() {
+    LPC_WDT->WDFEED = 0xAA;
+    LPC_WDT->WDFEED = 0x55;
+}
+// Load timeout value in watchdog timer and enable
+void WatchdogTimer::kick(float s) {
+    LPC_WDT->WDCLKSEL = 0x1;                // Set CLK src to PCLK
+    uint32_t clk = SystemCoreClock / 16;    // WD has a fixed /4 prescaler, PCLK default is /4
+    LPC_WDT->WDTC = s * (float)clk;
+    LPC_WDT->WDMOD = 0x3;                   // Enabled and Reset
+    kick();
+}
+