This provides a basic Watchdog service, and includes a startup detection to determine if the reset was caused by the WD.

Dependents:   A_CANAdapter LeonardoMbos AVC_2012 RT_CAN ... more

Using this Watchdog Class

#include "Watchdog.h"

Watchdog wd;

...
void main() {
   if (wd.WatchdogCausedReset())
       pc.printf("Watchdog caused reset.\r\n");
      
   wd.Configure(3.0);       // sets the timeout interval
   for (;;) {
        wd.Service();       // kick the dog before the timeout
        // do other work
   }
}
Revision:
0:7a316f14da9c
Child:
2:2873f068f325
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Watchdog.cpp	Sun Mar 20 23:22:50 2011 +0000
@@ -0,0 +1,33 @@
+
+#include "mbed.h"
+#include "Watchdog.h"
+
+
+
+/// Watchdog gets instantiated at the module level
+Watchdog::Watchdog() {
+    wdreset = (LPC_WDT->WDMOD >> 2) & 1;
+}
+
+/// Load timeout value in watchdog timer and enable
+void Watchdog::Configure(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
+    Service();
+}
+
+/// "Service", "kick" or "feed" the dog - reset the watchdog timer
+/// by writing this required bit pattern
+void Watchdog::Service() {
+    LPC_WDT->WDFEED = 0xAA;
+    LPC_WDT->WDFEED = 0x55;
+}
+
+/// get the flag to indicate if the watchdog causes the reset
+bool Watchdog::WatchdogCausedReset() {
+    return wdreset;
+}
+
+