Completion of http://mbed.org/users/simon/programs/WatchdogExample
Embed:
(wiki syntax)
Show/hide line numbers
main.cpp
00001 #include "mbed.h" 00002 00003 DigitalOut led(LED1); 00004 00005 class Watchdog { 00006 public: 00007 void kick(float s) { 00008 LPC_WDT->WDCLKSEL = 0x1; // Set CLK src to PCLK 00009 uint32_t clk = SystemCoreClock / 16; // WD has a fixed /4 prescaler, PCLK default is /4 00010 LPC_WDT->WDTC = s * (float)clk; 00011 LPC_WDT->WDMOD = (LPC_WDT->WDMOD|0x3); // Enabled and Reset, without clear WD time-out flag. 00012 kick(); 00013 } 00014 00015 void kick() { 00016 LPC_WDT->WDFEED = 0xAA; 00017 LPC_WDT->WDFEED = 0x55; 00018 } 00019 00020 /* You only can do IsWatchdogReset once... because flag must be cleared. */ 00021 bool IsWatchdogReset() { 00022 if (LPC_WDT->WDMOD & 0x4) { 00023 LPC_WDT->WDMOD=(LPC_WDT->WDMOD&(~0x4)); /* Clear timeout flag. */ 00024 return true; 00025 } 00026 else return false; 00027 } 00028 }; 00029 00030 Watchdog w; 00031 00032 int main() { 00033 /* First activate WD */ 00034 w.kick(2.5); 00035 00036 printf("Hello World!\n"); 00037 00038 if (w.IsWatchdogReset()) 00039 printf("MAIN: WD RESET Power up!!\r\n"); 00040 00041 int hang = 0; 00042 while(1) { 00043 printf("loop...\n"); 00044 wait(0.1); 00045 00046 if(hang == 10) { 00047 while(1); 00048 } 00049 00050 w.kick(); 00051 hang++; 00052 } 00053 }
Generated on Thu Jul 14 2022 22:20:51 by
1.7.2