Mbed OS Reference
Loading...
Searching...
No Matches
Watchdog Class Reference

A hardware watchdog timer that resets the system in the case of system failures or malfunctions. More...

#include <Watchdog.h>

Inheritance diagram for Watchdog:
NonCopyable< Watchdog >

Public Member Functions

bool start ()
 Start the Watchdog timer with the maximum timeout value available for the target. More...
 
bool start (uint32_t timeout)
 Start the Watchdog timer. More...
 
bool start (std::chrono::milliseconds timeout)
 Start the Watchdog timer. More...
 
bool stop ()
 Stop the Watchdog timer. More...
 
uint32_t get_timeout () const
 Get the Watchdog timer refresh value. More...
 
uint32_t get_max_timeout () const
 Get the maximum Watchdog refresh value for this platform. More...
 
bool is_running () const
 Check if the Watchdog timer is already running. More...
 
void kick ()
 Refresh the Watchdog timer. More...
 

Static Public Member Functions

static Watchdogget_instance ()
 Get a reference to the single Watchdog instance in the system. More...
 

Detailed Description

A hardware watchdog timer that resets the system in the case of system failures or malfunctions.

If you fail to refresh the Watchdog timer periodically, it resets the system after a set period of time.

There is only one instance of the Watchdog class in the system, which directly maps to the hardware. Use Watchdog::get_instance to obtain a reference.

Watchdog::start initializes a system timer with a time period specified in timeout param. This timer counts down and triggers a system reset when it wraps. To prevent the system reset, you must periodically kick or refresh the timer by calling Watchdog::kick, which resets the countdown to the initial value.

Example:

watchdog.start(500);
while (true) {
// kick watchdog regularly within provided timeout
watchdog.kick();
// Application code
}
A hardware watchdog timer that resets the system in the case of system failures or malfunctions.
Definition: Watchdog.h:65
void kick()
Refresh the Watchdog timer.
static Watchdog & get_instance()
Get a reference to the single Watchdog instance in the system.
Definition: Watchdog.h:72
bool start()
Start the Watchdog timer with the maximum timeout value available for the target.
Note
Synchronization level: Interrupt safe

Definition at line 65 of file Watchdog.h.

Member Function Documentation

◆ get_instance()

static Watchdog & get_instance ( )
static

Get a reference to the single Watchdog instance in the system.

Returns
A reference to the single Watchdog instance present in the system.

Definition at line 72 of file Watchdog.h.

◆ start() [1/3]

bool start ( )

Start the Watchdog timer with the maximum timeout value available for the target.

Note
The timeout is set to a value returned by Watchdog::get_max_timeout.

If the Watchdog timer is already running, this function does nothing.

Returns
true if the Watchdog timer was started successfully; false if the Watchdog timer was not started or if the Watchdog timer is already running.

◆ start() [2/3]

bool start ( uint32_t  timeout)

Start the Watchdog timer.

Note
Asserts that the timeout param is supported by the target (0 < timeout <= Watchdog::get_max_timeout).
Parameters
timeoutWatchdog timeout in milliseconds.
Returns
true if the Watchdog timer was started successfully; false if Watchdog timer was not started or if setting a new watchdog timeout was not possible.

◆ start() [3/3]

bool start ( std::chrono::milliseconds  timeout)

Start the Watchdog timer.

Note
Asserts that the timeout param is supported by the target (0 < timeout <= Watchdog::get_max_timeout).
Parameters
timeoutWatchdog timeout in chrono milliseconds.
Returns
true if the Watchdog timer was started successfully; false if Watchdog timer was not started or if setting a new watchdog timeout was not possible.

Definition at line 118 of file Watchdog.h.

◆ stop()

bool stop ( )

Stop the Watchdog timer.

Calling this function disables a running Watchdog peripheral if the platform supports it.

Returns
true if the Watchdog timer was successfully stopped; false if the Watchdog timer cannot be disabled on this platform or if the Watchdog timer has not been started.

◆ get_timeout()

uint32_t get_timeout ( ) const

Get the Watchdog timer refresh value.

This function returns the refresh timeout of the watchdog peripheral.

Returns
Reload value for the Watchdog timer in milliseconds.

◆ get_max_timeout()

uint32_t get_max_timeout ( ) const

Get the maximum Watchdog refresh value for this platform.

Returns
Maximum reload value supported by the Watchdog timer for this platform in milliseconds.

◆ is_running()

bool is_running ( ) const

Check if the Watchdog timer is already running.

Returns
true if the Watchdog timer is running and false otherwise.

◆ kick()

void kick ( )

Refresh the Watchdog timer.

Call this function periodically before the Watchdog times out. Otherwise, the system resets.

If the Watchdog timer is not running, this function does nothing.