TaskWdt.h
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #ifndef TASK_WDT_H | ||
| 2 | #define TASK_WDT_H | ||
| 3 | #include <esp_task_wdt.h> | ||
| 4 | |||
| 5 | // Task watchdog calls that are safe from any task. | ||
| 6 | // | ||
| 7 | // Only loop() is subscribed to the watchdog. Code it shares with other tasks | ||
| 8 | // is not: the WiFi event task runs ESPNetwork::setConnected() and async_tcp | ||
| 9 | // runs the web and socket handlers. A plain esp_task_wdt_reset() there logs | ||
| 10 | // "esp_task_wdt_reset(707): task not found", and an esp_task_wdt_add() there | ||
| 11 | // subscribes a task that nothing resets, so it panics once the timeout runs out. | ||
| 12 | |||
| 13 | // Resets the watchdog if the calling task is subscribed to it. | ||
| 14 | 2 | inline void resetTaskWdt() { | |
| 15 | 2 | if(esp_task_wdt_status(NULL) == ESP_OK) esp_task_wdt_reset(); | |
| 16 | 2 | } | |
| 17 | // Stops watching the calling task around a call that blocks past the timeout. | ||
| 18 | // True when it was watched, so resumeTaskWdt() knows to add it back. | ||
| 19 | 2 | inline bool pauseTaskWdt() { return esp_task_wdt_delete(NULL) == ESP_OK; } | |
| 20 | 2 | inline void resumeTaskWdt(bool paused) { if(paused) esp_task_wdt_add(NULL); } | |
| 21 | #endif | ||
| 22 |