Igor Galarraga
/
WatchdogExample
Completion of http://mbed.org/users/simon/programs/WatchdogExample
Revision 0:f6684fa81520, committed 2012-04-21
- Comitter:
- IgorGZ
- Date:
- Sat Apr 21 14:38:29 2012 +0000
- Commit message:
- WatchdogExample with power up state detect.
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
mbed.bld | Show annotated file Show diff for this revision Revisions of this file |
diff -r 000000000000 -r f6684fa81520 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Sat Apr 21 14:38:29 2012 +0000 @@ -0,0 +1,53 @@ +#include "mbed.h" + +DigitalOut led(LED1); + +class Watchdog { +public: + void kick(float s) { + 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 = s * (float)clk; + LPC_WDT->WDMOD = (LPC_WDT->WDMOD|0x3); // Enabled and Reset, without clear WD time-out flag. + kick(); + } + + void kick() { + LPC_WDT->WDFEED = 0xAA; + LPC_WDT->WDFEED = 0x55; + } + + /* You only can do IsWatchdogReset once... because flag must be cleared. */ + bool IsWatchdogReset() { + if (LPC_WDT->WDMOD & 0x4) { + LPC_WDT->WDMOD=(LPC_WDT->WDMOD&(~0x4)); /* Clear timeout flag. */ + return true; + } + else return false; + } +}; + +Watchdog w; + +int main() { + /* First activate WD */ + w.kick(2.5); + + printf("Hello World!\n"); + + if (w.IsWatchdogReset()) + printf("MAIN: WD RESET Power up!!\r\n"); + + int hang = 0; + while(1) { + printf("loop...\n"); + wait(0.1); + + if(hang == 10) { + while(1); + } + + w.kick(); + hang++; + } +}
diff -r 000000000000 -r f6684fa81520 mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Sat Apr 21 14:38:29 2012 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/49a220cc26e0