ESPHome 2026.5.0b1
Loading...
Searching...
No Matches
watchdog.cpp
Go to the documentation of this file.
1#include "watchdog.h"
2
4#include "esphome/core/log.h"
5
6#include <cinttypes>
7#include <cstdint>
8#ifdef USE_ESP32
9#include "esp_idf_version.h"
10#include "esp_task_wdt.h"
11#endif
12#ifdef USE_RP2040
13#include "hardware/watchdog.h"
14#include "pico/stdlib.h"
15#endif
16
18
19static const char *const TAG = "http_request.watchdog";
20
21WatchdogManager::WatchdogManager(uint32_t timeout_ms) : timeout_ms_(timeout_ms) {
22 if (timeout_ms == 0) {
23 return;
24 }
25 this->saved_timeout_ms_ = this->get_timeout_();
26 this->set_timeout_(timeout_ms);
27}
28
30 if (this->timeout_ms_ == 0) {
31 return;
32 }
33 this->set_timeout_(this->saved_timeout_ms_);
34}
35
36void WatchdogManager::set_timeout_(uint32_t timeout_ms) {
37 ESP_LOGV(TAG, "Adjusting WDT to %" PRIu32 "ms", timeout_ms);
38#ifdef USE_ESP32
39 esp_task_wdt_config_t wdt_config = {
40 .timeout_ms = timeout_ms,
41 .idle_core_mask = 0,
42 .trigger_panic = false,
43 };
44#if CONFIG_ESP_TASK_WDT_CHECK_IDLE_TASK_CPU0
45 wdt_config.idle_core_mask |= (1U << 0U);
46#endif
47#if CONFIG_ESP_TASK_WDT_CHECK_IDLE_TASK_CPU1
48 wdt_config.idle_core_mask |= (1U << 1U);
49#endif
50#if CONFIG_ESP_TASK_WDT_PANIC
51 wdt_config.trigger_panic = true;
52#endif
53 esp_task_wdt_reconfigure(&wdt_config);
54#endif // USE_ESP32
55
56#ifdef USE_RP2040
57 watchdog_enable(timeout_ms, true);
58#endif
59}
60
61uint32_t WatchdogManager::get_timeout_() {
62 uint32_t timeout_ms = 0;
63
64#ifdef USE_ESP32
65 timeout_ms = (uint32_t) CONFIG_ESP_TASK_WDT_TIMEOUT_S * 1000;
66#endif // USE_ESP32
67
68#ifdef USE_RP2040
69 timeout_ms = watchdog_get_count() / 1000;
70#endif
71
72 ESP_LOGVV(TAG, "get_timeout: %" PRIu32 "ms", timeout_ms);
73
74 return timeout_ms;
75}
76
77} // namespace esphome::watchdog
WatchdogManager(uint32_t timeout_ms)
Definition watchdog.cpp:21
static void uint32_t