ESPHome 2025.5.0
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 <soc/soc_caps.h>
10#include "esp_idf_version.h"
11#include "esp_task_wdt.h"
12#endif
13#ifdef USE_RP2040
14#include "hardware/watchdog.h"
15#include "pico/stdlib.h"
16#endif
17
18namespace esphome {
19namespace watchdog {
20
21static const char *const TAG = "http_request.watchdog";
22
23WatchdogManager::WatchdogManager(uint32_t timeout_ms) : timeout_ms_(timeout_ms) {
24 if (timeout_ms == 0) {
25 return;
26 }
27 this->saved_timeout_ms_ = this->get_timeout_();
28 this->set_timeout_(timeout_ms);
29}
30
32 if (this->timeout_ms_ == 0) {
33 return;
34 }
35 this->set_timeout_(this->saved_timeout_ms_);
36}
37
38void WatchdogManager::set_timeout_(uint32_t timeout_ms) {
39 ESP_LOGV(TAG, "Adjusting WDT to %" PRIu32 "ms", timeout_ms);
40#ifdef USE_ESP32
41#if ESP_IDF_VERSION_MAJOR >= 5
42 esp_task_wdt_config_t wdt_config = {
43 .timeout_ms = timeout_ms,
44 .idle_core_mask = (1 << SOC_CPU_CORES_NUM) - 1,
45 .trigger_panic = true,
46 };
47 esp_task_wdt_reconfigure(&wdt_config);
48#else
49 esp_task_wdt_init(timeout_ms / 1000, true);
50#endif // ESP_IDF_VERSION_MAJOR
51#endif // USE_ESP32
52
53#ifdef USE_RP2040
54 watchdog_enable(timeout_ms, true);
55#endif
56}
57
58uint32_t WatchdogManager::get_timeout_() {
59 uint32_t timeout_ms = 0;
60
61#ifdef USE_ESP32
62 timeout_ms = (uint32_t) CONFIG_ESP_TASK_WDT_TIMEOUT_S * 1000;
63#endif // USE_ESP32
64
65#ifdef USE_RP2040
66 timeout_ms = watchdog_get_count() / 1000;
67#endif
68
69 ESP_LOGVV(TAG, "get_timeout: %" PRIu32 "ms", timeout_ms);
70
71 return timeout_ms;
72}
73
74} // namespace watchdog
75} // namespace esphome
WatchdogManager(uint32_t timeout_ms)
Definition watchdog.cpp:23
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7