Mistake on this page?
Report an issue in GitHub or email us

Watchdog

The Watchdog HAL API provides a low-level interface to the Independent Watchdog Timer of a target. Implementing the Watchdog API is not mandatory, but by implementing it, you can use the hardware watchdog timer to detect and recover from computer malfunctions.

Implement the ResetReason API when implementing the Watchdog API. The ResetReason API allows you to detect at boot time whether a watchdog caused the last reset.

Assumptions

Defined behavior

  • Sleep and debug modes don't stop the watchdog timer from counting down.
  • The function hal_watchdog_init is safe to call repeatedly. The function's implementation must not do anything if hal_watchdog_init has already initialized the hardware watchdog timer.
  • Maximum supported timeout is UINT32_MAX milliseconds; minimum timeout is 1ms.
  • The timeout must be accurate to the nearest millisecond.

Undefined behavior

  • Calling any function other than hal_watchdog_init or hal_watchdog_get_platform_features before you have initialized the watchdog.

Notes

  • A software reset may not stop the watchdog timer; the behavior is platform specific.
  • Timing on most platforms is based on the timeout registers and a prescaler value. They should be accurate to the nearest millisecond but may be off my a several µs.

Dependency

Hardware Independent Watchdog support.

Implementing Watchdog

You can find the API and specification for the Watchdog API in the following header file:

Public Member Functions
watchdog_status_t start (const uint32_t timeout)
 Start an independent watchdog timer with specified parameters. More...
void kick ()
 Refreshes the watchdog timer. More...
watchdog_status_t stop ()
 Stops the watchdog timer. More...
uint32_t reload_value () const
 Get the watchdog timer refresh value. More...
Static Public Member Functions
static uint32_t max_timeout ()
 Get the maximum refresh value for the current platform in milliseconds. More...

To enable Watchdog support in Mbed OS, add the WATCHDOG label in the device_has option of the target's section in the targets.json file.

Testing

The Mbed OS HAL provides a set of conformance tests for Watchdog. You can use these tests to validate the correctness of your implementation. To run the Watchdog HAL tests use the following command:

mbed test -t <toolchain> -m <target> -n "tests-mbed_hal-watchdog*"

You can read more about the test cases here:

Important Information for this Arm website

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies. If you are not happy with the use of these cookies, please review our Cookie Policy to learn how they can be disabled. By disabling cookies, some features of the site will not work.