Test program for watchdog timer library. LED will flash for 5 seconds then simulate a hard fault. Watchdog timer will timeout after 3 seconds and reset the system.

Dependencies:   WatchdogTimer mbed

Committer:
jcady92
Date:
Tue Jun 30 16:45:14 2015 +0000
Revision:
0:882d720a2cc6
Test program for the watchdog timer library. Flashes LED for 5 seconds, then simulates a hard fault. Watchdog timer will kick in and reset the system 3 seconds after hard fault.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jcady92 0:882d720a2cc6 1 #include "mbed.h"
jcady92 0:882d720a2cc6 2 #include "WatchdogTimer.h"
jcady92 0:882d720a2cc6 3
jcady92 0:882d720a2cc6 4 DigitalOut led(LED1);
jcady92 0:882d720a2cc6 5 WatchdogTimer watchdogTimer(3); //Watchdog timer with 3 second timeout
jcady92 0:882d720a2cc6 6
jcady92 0:882d720a2cc6 7 int main()
jcady92 0:882d720a2cc6 8 {
jcady92 0:882d720a2cc6 9 Timer timer;
jcady92 0:882d720a2cc6 10 timer.start();
jcady92 0:882d720a2cc6 11
jcady92 0:882d720a2cc6 12 //NOTE: Ensure your main loop operations don't take longer than the watchdog timeout you set
jcady92 0:882d720a2cc6 13 while(1)
jcady92 0:882d720a2cc6 14 {
jcady92 0:882d720a2cc6 15 //Flash LED for five seconds
jcady92 0:882d720a2cc6 16 if (timer.read_ms() < 5000)
jcady92 0:882d720a2cc6 17 {
jcady92 0:882d720a2cc6 18 led = 1;
jcady92 0:882d720a2cc6 19 wait(0.2);
jcady92 0:882d720a2cc6 20 led = 0;
jcady92 0:882d720a2cc6 21 wait(0.2);
jcady92 0:882d720a2cc6 22 }
jcady92 0:882d720a2cc6 23 else
jcady92 0:882d720a2cc6 24 {
jcady92 0:882d720a2cc6 25 //Simulate hard fault
jcady92 0:882d720a2cc6 26 while(1) {}
jcady92 0:882d720a2cc6 27 }
jcady92 0:882d720a2cc6 28
jcady92 0:882d720a2cc6 29 //Kick the watchdog to reset its timer
jcady92 0:882d720a2cc6 30 watchdogTimer.kick();
jcady92 0:882d720a2cc6 31 }
jcady92 0:882d720a2cc6 32 }