Simple library to manage the WatchDog timer, tested on LPC1768
Revision 0:3744cb611b63, committed 2015-01-03
- Comitter:
- wyunreal
- Date:
- Sat Jan 03 13:26:51 2015 +0000
- Commit message:
- Simple library to manage the WatchDog timer
Changed in this revision
WatchDogTimer.cpp | Show annotated file Show diff for this revision Revisions of this file |
WatchDogTimer.h | Show annotated file Show diff for this revision Revisions of this file |
diff -r 000000000000 -r 3744cb611b63 WatchDogTimer.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/WatchDogTimer.cpp Sat Jan 03 13:26:51 2015 +0000 @@ -0,0 +1,24 @@ +/** + * Apache License + * Version 2.0, January 2004 + * http://www.apache.org/licenses/ + */ + +#include "WatchDogTimer.h" + +int WatchDogTimer::systemResetReason() { + return ((LPC_WDT->WDMOD >> 2) & 1) ? SYSTEM_RESET_WATCH_DOG : SYSTEM_RESET_NORMAL; +} + +WatchDogTimer::WatchDogTimer(float seconds) { + 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 = seconds * (float)clk; // Load WD Timer Constant with value determined by float s + LPC_WDT->WDMOD = 0x3; // Enabled and Reset + feed(); +} + +void WatchDogTimer::feed() { + LPC_WDT->WDFEED = 0xAA; + LPC_WDT->WDFEED = 0x55; +} \ No newline at end of file
diff -r 000000000000 -r 3744cb611b63 WatchDogTimer.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/WatchDogTimer.h Sat Jan 03 13:26:51 2015 +0000 @@ -0,0 +1,23 @@ +/** + * Apache License + * Version 2.0, January 2004 + * http://www.apache.org/licenses/ + */ + +#ifndef WATCH_DOG_TIMER_H +#define WATCH_DOG_TIMER_H + +#include "mbed.h" + +class WatchDogTimer { +public: + + static const int SYSTEM_RESET_NORMAL = 1; + static const int SYSTEM_RESET_WATCH_DOG = 2; + + WatchDogTimer(float seconds); + void feed(); + static int systemResetReason(); +}; + +#endif \ No newline at end of file