Interface exposing basic LPC1768 watchdog timer functionality.
Diff: WatchdogTimer.cpp
- Revision:
- 0:f39b85bbe46f
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/WatchdogTimer.cpp Sun Sep 02 14:54:58 2012 +0000 @@ -0,0 +1,30 @@ +#include "mbed.h" +#include "WatchdogTimer.h" + +WatchdogTimer::WatchdogTimer() +{ +} + +void WatchdogTimer::enable(float timeout) +{ + // Set the clock source (use peripheral clock) + LPC_WDT->WDCLKSEL = 0x1; + // Set the watchdog timer constant (watchdog prescaler is always 1/4, PCLK default is 1/4) + LPC_WDT->WDTC = timeout * SystemCoreClock / (4.0 * 4.0); + // Enable and reset (WDEN | WDRESET) + LPC_WDT->WDMOD = 0x3; + feed(); +} + +void WatchdogTimer::feed() +{ + // Feed sequence is 0xAA, 0x55. + LPC_WDT->WDFEED = 0xAA; + LPC_WDT->WDFEED = 0x55; +} + +bool WatchdogTimer::causedReset() +{ + // Read the watchdog time-out flag (WDTOF). + return (LPC_WDT->WDMOD & 0x4); +}