watchdog timer. this is a derived work.

Dependents:   Embedded_RTOS_Project

Committer:
gatedClock
Date:
Tue Sep 17 15:03:56 2013 +0000
Revision:
0:f27d373a8e28
add watchdog library.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
gatedClock 0:f27d373a8e28 1 /*----------------------------------------------//----------------------------*/
gatedClock 0:f27d373a8e28 2 // Simon's Watchdog code from
gatedClock 0:f27d373a8e28 3 // http://mbed.org/forum/mbed/topic/508/
gatedClock 0:f27d373a8e28 4 class Watchdog
gatedClock 0:f27d373a8e28 5 {
gatedClock 0:f27d373a8e28 6 public:
gatedClock 0:f27d373a8e28 7
gatedClock 0:f27d373a8e28 8 void kick(float s) // Load timeout value in watchdog timer and enable
gatedClock 0:f27d373a8e28 9 {
gatedClock 0:f27d373a8e28 10 LPC_WDT->WDCLKSEL = 0x1; // Set CLK src to PCLK
gatedClock 0:f27d373a8e28 11 uint32_t clk = SystemCoreClock / 16; // WD has a fixed /4 prescaler, PCLK default is /4
gatedClock 0:f27d373a8e28 12 LPC_WDT->WDTC = s * (float)clk;
gatedClock 0:f27d373a8e28 13 LPC_WDT->WDMOD = 0x3; // Enabled and Reset
gatedClock 0:f27d373a8e28 14 kick();
gatedClock 0:f27d373a8e28 15 }
gatedClock 0:f27d373a8e28 16
gatedClock 0:f27d373a8e28 17
gatedClock 0:f27d373a8e28 18 void kick() // reset timer.
gatedClock 0:f27d373a8e28 19 {
gatedClock 0:f27d373a8e28 20 LPC_WDT->WDFEED = 0xAA;
gatedClock 0:f27d373a8e28 21 LPC_WDT->WDFEED = 0x55;
gatedClock 0:f27d373a8e28 22 }
gatedClock 0:f27d373a8e28 23 };
gatedClock 0:f27d373a8e28 24 /*----------------------------------------------//----------------------------*/