Watchdog Timer
The watchdog timer is a very useful feature for projects that are intended to run for extended periods of time or contain unstable loops of code. The watchdog is essentially a small timer that will force a full system restart if the timer is not updated within a preset time. For more information and APIs about memory status, please visit MbedOS.
Assembly
Arduino.h
Summary
Constructors |
---|
Watchdog - Watchdog() |
Methods |
---|
configure - bool configure(float timeoutInMs) |
resetTimer - void resetTimer() |
resetTriggered - bool resetTriggered(); |
Constructor
Watchdog
Watchdog()
Constructor of
Watchdog
class
Methods
configure
bool configure(float timeoutInMs)
Configure Watchdog timer with reset interval.
Parameters
Type Name Description float timeoutInMs timeout interval in milliseconds, as a float Return value
Returns true if the Watchdog is configured successfully, false for invalid input.
resetTimer
void resetTimer()
Reset Watchdog timer to prevent it from a system reset.
Parameters
None
Return value
None
resetTriggered
bool resetTriggered()
Get the flag to indicate if the Watchdog trigger a system reset.
Parameters
None
Return value
Returns true if the Watchdog reset is triggered, else return false.
Sample code
#include "Arduino.h"
Watchdog watchdog;
void setup() {
// setup a 10 second timeout on watchdog timer hardware
bool ret = watchdog.configure(10000);
if (!ret)
{
Serial.println("Configure watchdog failed.");
}
}
void loop() {
// Main program loop - reset watchdog timer to prevent a system reset
watchdog.resetTimer();
// Do other work
Serial.println("loop");
delay(1000);
}