4180 lab 1

Dependencies:   mbed MCP23S17 PinDetect USBDevice

Revision:
7:b7720a8623b5
Child:
10:0886afdfb170
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/watchdog_ec.h	Tue Jan 21 20:02:09 2020 +0000
@@ -0,0 +1,49 @@
+#include "mbed.h"
+
+class Watchdog {
+public:
+// Load timeout value in watchdog timer and enable
+    void 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();
+    }
+// "kick" or "feed" the dog - reset the watchdog timer
+// by writing this required bit pattern
+    void kick() {
+        LPC_WDT->WDFEED = 0xAA;
+        LPC_WDT->WDFEED = 0x55;
+    }
+};
+ 
+// Setup the watchdog timer
+Watchdog wdt;
+
+DigitalIn pb(p22);
+DigitalOut myled(p26);
+
+int prev;
+int count = 0;
+
+int run_watchdogEC() {
+    wdt.kick(10.0);
+    
+    prev = pb;
+    
+    while(1) {
+        if (prev != pb) {
+            count++;
+        }
+        myled = !pb;
+        
+        if (count == 2) {
+            while (1) {
+                ;
+            }
+        }
+        
+        wdt.kick();
+    }
+}
\ No newline at end of file