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

main.cpp

Committer:
jcady92
Date:
2015-06-30
Revision:
0:882d720a2cc6

File content as of revision 0:882d720a2cc6:

#include "mbed.h"
#include "WatchdogTimer.h"

DigitalOut led(LED1);
WatchdogTimer watchdogTimer(3); //Watchdog timer with 3 second timeout

int main()
{
    Timer timer;
    timer.start();
    
    //NOTE: Ensure your main loop operations don't take longer than the watchdog timeout you set
    while(1)
    {
        //Flash LED for five seconds
        if (timer.read_ms() < 5000)
        {
            led = 1;
            wait(0.2);
            led = 0;
            wait(0.2);
        }
        else
        {
            //Simulate hard fault
            while(1) {}
        }
        
        //Kick the watchdog to reset its timer
        watchdogTimer.kick();
    }
}