Watchdog timer for the LPC4088

Files at this revision

API Documentation at this revision

Comitter:
loopsva
Date:
Fri Dec 20 19:42:32 2013 +0000
Commit message:
Initial cut. A Watchdog timer for the LPC4088.

Changed in this revision

Watchdog.cpp Show annotated file Show diff for this revision Revisions of this file
Watchdog.h Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r fc62d045ca0c Watchdog.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Watchdog.cpp	Fri Dec 20 19:42:32 2013 +0000
@@ -0,0 +1,15 @@
+#include "mbed.h"
+#include "Watchdog.h"
+
+void Watchdog::kick(int WDTseconds) {
+    if(WDTseconds < 1) WDTseconds = 1;      //minimum watchdog time is 1 sec
+    if(WDTseconds > 134) WDTseconds = 134;  //maximum watchdog time is 134 sec
+    LPC_WDT->TC = 125000 * WDTseconds;      //125000 * 8uS = 1.0 second tics
+    LPC_WDT->MOD = 0x3;                     //enable and restart watchdog
+    Watchdog::kick();
+}
+
+void Watchdog::kick() {
+    LPC_WDT->FEED = 0xaa;                   //kick sequence into FEED register
+    LPC_WDT->FEED = 0x55;
+}
diff -r 000000000000 -r fc62d045ca0c Watchdog.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Watchdog.h	Fri Dec 20 19:42:32 2013 +0000
@@ -0,0 +1,57 @@
+#ifndef WATCHDOG_4088_H
+#define WATCHDOG_4088_H
+
+#include "mbed.h"
+
+/** Routines to set and kick the Watchdog timer for the LPC4088.
+ *
+ *   The LPC4088 has a fixed, internal 500KHz oscillator which
+ *   is divided by 4 to give an 8uS master clock to the Watchdog countdown timer.
+ *
+ *   User inputs a value from 1 to 134 seconds when initializing the Watchdog
+ *   timer. The user's input number is multiplied by 125k and then placed into 
+ *   the countdown timer.
+ *
+ *   The user is responsible for "kicking" the Watchdog before the timeout interval 
+ *   expires, otherwise the LPC4088 will automatically reboot.
+ *
+ * @code
+ * #include "mbed.h"
+ * #include "Watchdog.h" 
+ *
+ * Watchdog wdt;
+ *
+ * int main() {
+ *     initialization code....
+ *     wdt.kick(20);           //init the watchdog for a 20 second timeout
+ *     while(1) {
+ *         wait_ms(1000);      //do some code
+ *         wdt.kick();         //kick the watchdog before 20 seconds is up
+ *     }
+ * }
+ * @endcode
+ *
+ */
+/* Watchdog controller class
+ */
+class Watchdog {
+
+public:
+    /** Create a Watchdog object and initialize timeout in seconds
+     *
+     * @param int timeout in seconds. Range (1 - 134)
+     */
+    void kick(int WDTseconds);
+    
+    
+    /** Keep alive by kicking the Watchdog occasionally
+     *
+     * @param NONE
+     */
+    void kick();
+
+private:
+    int WDTseconds;
+};
+
+#endif