Espressif ESP32-S2 Programming Manual page 1060

Table of Contents

Advertisement

Chapter 2. API Reference
Task Watchdog API Reference
A full example using the Task Watchdog is available in esp-idf:
Header File
components/esp_system/include/esp_task_wdt.h
Functions
esp_err_t
esp_task_wdt_init(uint32_t timeout, bool panic)
Initialize the Task Watchdog Timer (TWDT)
This function configures and initializes the TWDT. If the TWDT is already initialized when this function is
called, this function will update the TWDT' s timeout period and panic configurations instead. After initializing
the TWDT, any task can elect to be watched by the TWDT by subscribing to it using esp_task_wdt_add().
Return
• ESP_OK: Initialization was successful
• ESP_ERR_NO_MEM: Initialization failed due to lack of memory
Note esp_task_wdt_init() must only be called after the scheduler started
Parameters
• [in] timeout: Timeout period of TWDT in seconds
• [in] panic: Flag that controls whether the panic handler will be executed when the TWDT
times out
esp_err_t
esp_task_wdt_deinit(void)
Deinitialize the Task Watchdog Timer (TWDT)
This function will deinitialize the TWDT. Calling this function whilst tasks are still subscribed to the TWDT,
or when the TWDT is already deinitialized, will result in an error code being returned.
Return
• ESP_OK: TWDT successfully deinitialized
• ESP_ERR_INVALID_STATE: Error, tasks are still subscribed to the TWDT
• ESP_ERR_NOT_FOUND: Error, TWDT has already been deinitialized
esp_err_t esp_task_wdt_add(TaskHandle_t
Subscribe a task to the Task Watchdog Timer (TWDT)
This function subscribes a task to the TWDT. Each subscribed task must periodically call esp_task_wdt_reset()
to prevent the TWDT from elapsing its timeout period. Failure to do so will result in a TWDT timeout. If the
task being subscribed is one of the Idle Tasks, this function will automatically enable esp_task_wdt_reset() to
called from the Idle Hook of the Idle Task. Calling this function whilst the TWDT is uninitialized or attempting
to subscribe an already subscribed task will result in an error code being returned.
Return
• ESP_OK: Successfully subscribed the task to the TWDT
• ESP_ERR_INVALID_ARG: Error, the task is already subscribed
• ESP_ERR_NO_MEM: Error, could not subscribe the task due to lack of memory
• ESP_ERR_INVALID_STATE: Error, the TWDT has not been initialized yet
Parameters
• [in] handle: Handle of the task. Input NULL to subscribe the current running task to the
TWDT
esp_err_t
esp_task_wdt_reset(void)
Reset the Task Watchdog Timer (TWDT) on behalf of the currently running task.
This function will reset the TWDT on behalf of the currently running task. Each subscribed task must pe-
riodically call this function to prevent the TWDT from timing out. If one or more subscribed tasks fail to
reset the TWDT on their own behalf, a TWDT timeout will occur. If the IDLE tasks have been subscribed to
the TWDT, they will automatically call this function from their idle hooks. Calling this function from a task
that has not subscribed to the TWDT, or when the TWDT is uninitialized will result in an error code being
returned.
Espressif Systems
system/task_watchdog
handle)
1049
Submit Document Feedback
Release v4.4

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the ESP32-S2 and is the answer not in the manual?

Subscribe to Our Youtube Channel

Table of Contents

Save PDF