Interface exposing basic LPC1768 watchdog timer functionality.

Committer:
nr
Date:
Sun Sep 02 14:54:58 2012 +0000
Revision:
0:f39b85bbe46f
Initial commit.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
nr 0:f39b85bbe46f 1 #include "mbed.h"
nr 0:f39b85bbe46f 2 #include "WatchdogTimer.h"
nr 0:f39b85bbe46f 3
nr 0:f39b85bbe46f 4 WatchdogTimer::WatchdogTimer()
nr 0:f39b85bbe46f 5 {
nr 0:f39b85bbe46f 6 }
nr 0:f39b85bbe46f 7
nr 0:f39b85bbe46f 8 void WatchdogTimer::enable(float timeout)
nr 0:f39b85bbe46f 9 {
nr 0:f39b85bbe46f 10 // Set the clock source (use peripheral clock)
nr 0:f39b85bbe46f 11 LPC_WDT->WDCLKSEL = 0x1;
nr 0:f39b85bbe46f 12 // Set the watchdog timer constant (watchdog prescaler is always 1/4, PCLK default is 1/4)
nr 0:f39b85bbe46f 13 LPC_WDT->WDTC = timeout * SystemCoreClock / (4.0 * 4.0);
nr 0:f39b85bbe46f 14 // Enable and reset (WDEN | WDRESET)
nr 0:f39b85bbe46f 15 LPC_WDT->WDMOD = 0x3;
nr 0:f39b85bbe46f 16 feed();
nr 0:f39b85bbe46f 17 }
nr 0:f39b85bbe46f 18
nr 0:f39b85bbe46f 19 void WatchdogTimer::feed()
nr 0:f39b85bbe46f 20 {
nr 0:f39b85bbe46f 21 // Feed sequence is 0xAA, 0x55.
nr 0:f39b85bbe46f 22 LPC_WDT->WDFEED = 0xAA;
nr 0:f39b85bbe46f 23 LPC_WDT->WDFEED = 0x55;
nr 0:f39b85bbe46f 24 }
nr 0:f39b85bbe46f 25
nr 0:f39b85bbe46f 26 bool WatchdogTimer::causedReset()
nr 0:f39b85bbe46f 27 {
nr 0:f39b85bbe46f 28 // Read the watchdog time-out flag (WDTOF).
nr 0:f39b85bbe46f 29 return (LPC_WDT->WDMOD & 0x4);
nr 0:f39b85bbe46f 30 }