This is the documentation for the latest (main) development branch of Zephyr. If you are looking for the documentation of previous releases, use the drop-down menu on the left and select the desired version.



API Reference

group watchdog_interface

Watchdog Interface.





Watchdog options


Pause watchdog timer when CPU is in sleep state.


Pause watchdog timer when CPU is halted by the debugger.

Watchdog behavior flags


Reset: none.


Reset: CPU core.


Reset: SoC.


typedef void (*wdt_callback_t)(const struct device *dev, int channel_id)

Watchdog callback.

Param dev:

Watchdog device instance.

Param channel_id:

Channel identifier.


int wdt_setup(const struct device *dev, uint8_t options)

Set up watchdog instance.

This function is used for configuring global watchdog settings that affect all timeouts. It should be called after installing timeouts. After successful return, all installed timeouts are valid and must be serviced periodically by calling wdt_feed().

  • dev – Watchdog device instance.

  • options – Configuration options (see WDT_OPT).

Return values:
  • 0 – If successful.

  • -ENOTSUP – If any of the set options is not supported.

  • -EBUSY – If watchdog instance has been already setup.

  • -errno – In case of any other failure.

int wdt_disable(const struct device *dev)

Disable watchdog instance.

This function disables the watchdog instance and automatically uninstalls all timeouts. To set up a new watchdog, install timeouts and call wdt_setup() again. Not all watchdogs can be restarted after they are disabled.

  • dev – Watchdog device instance.

Return values:
  • 0 – If successful.

  • -EFAULT – If watchdog instance is not enabled.

  • -EPERM – If watchdog can not be disabled directly by application code.

  • -errno – In case of any other failure.

static inline int wdt_install_timeout(const struct device *dev, const struct wdt_timeout_cfg *cfg)

Install a new timeout.


This function must be used before wdt_setup(). Changes applied here have no effects until wdt_setup() is called.

  • dev – Watchdog device instance.

  • cfg[in] Timeout configuration.

Return values:
  • channel_id – If successful, a non-negative value indicating the index of the channel to which the timeout was assigned. This value is supposed to be used as the parameter in calls to wdt_feed().

  • -EBUSY – If timeout can not be installed while watchdog has already been setup.

  • -ENOMEM – If no more timeouts can be installed.

  • -ENOTSUP – If any of the set flags is not supported.

  • -EINVAL – If any of the window timeout value is out of possible range. This value is also returned if watchdog supports only one timeout value for all timeouts and the supplied timeout window differs from windows for alarms installed so far.

  • -errno – In case of any other failure.

int wdt_feed(const struct device *dev, int channel_id)

Feed specified watchdog timeout.

  • dev – Watchdog device instance.

  • channel_id – Channel index.

Return values:
  • 0 – If successful.

  • -EAGAIN – If completing the feed operation would stall the caller, for example due to an in-progress watchdog operation such as a previous wdt_feed() call.

  • -EINVAL – If there is no installed timeout for supplied channel.

  • -errno – In case of any other failure.

struct wdt_window
#include <watchdog.h>

Watchdog timeout window.

Each installed timeout needs feeding within the specified time window, otherwise the watchdog will trigger. If the watchdog instance does not support window timeouts then min value must be equal to 0.


If specified values can not be precisely set they are always rounded up.

Public Members

uint32_t min

Lower limit of watchdog feed timeout in milliseconds.

uint32_t max

Upper limit of watchdog feed timeout in milliseconds.

struct wdt_timeout_cfg
#include <watchdog.h>

Watchdog timeout configuration.

Public Members

struct wdt_window window

Timing parameters of watchdog timeout.

wdt_callback_t callback

Timeout callback (can be NULL).

struct wdt_timeout_cfg *next

Pointer to the next timeout configuration.

This field is only available if CONFIG_WDT_MULTISTAGE is enabled (watchdogs with staged timeouts functionality). Value must be NULL for single stage timeout.

uint8_t flags

Flags (see WDT_FLAGS).