ESPHome 2025.9.0-dev
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 esp_task_wdt_config_t wdt_config = {
42 .timeout_ms = timeout_ms,
43 .idle_core_mask = (1 << SOC_CPU_CORES_NUM) - 1,
44 .trigger_panic = true,
45 };
46 esp_task_wdt_reconfigure(&wdt_config);
47#endif // USE_ESP32
48
49#ifdef USE_RP2040
50 watchdog_enable(timeout_ms, true);
51#endif
52}
53
54uint32_t WatchdogManager::get_timeout_() {
55 uint32_t timeout_ms = 0;
56
57#ifdef USE_ESP32
58 timeout_ms = (uint32_t) CONFIG_ESP_TASK_WDT_TIMEOUT_S * 1000;
59#endif // USE_ESP32
60
61#ifdef USE_RP2040
62 timeout_ms = watchdog_get_count() / 1000;
63#endif
64
65 ESP_LOGVV(TAG, "get_timeout: %" PRIu32 "ms", timeout_ms);
66
67 return timeout_ms;
68}
69
70} // namespace watchdog
71} // 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