diff --git a/esphome/core/application.cpp b/esphome/core/application.cpp index d1aa461d0eb..84a1fc346fe 100644 --- a/esphome/core/application.cpp +++ b/esphome/core/application.cpp @@ -199,10 +199,9 @@ void Application::process_dump_config_() { void HOT Application::feed_wdt_slow_(uint32_t time) { // Use provided time if available, otherwise get current time uint32_t now = time ? time : millis(); - // Compare in milliseconds (3ms threshold). The inline wrapper already - // performs this check when time != 0; repeat it here for the time == 0 - // entry and as a safety net. - if (now - this->last_wdt_feed_ > 3) { + // The inline wrapper already performs this check when time != 0; + // repeat it here for the time == 0 entry and as a safety net. + if (now - this->last_wdt_feed_ > WDT_FEED_INTERVAL_MS) { arch_feed_wdt(); this->last_wdt_feed_ = now; #ifdef USE_STATUS_LED diff --git a/esphome/core/application.h b/esphome/core/application.h index f8e9b0e3607..7cde0bf85d9 100644 --- a/esphome/core/application.h +++ b/esphome/core/application.h @@ -385,6 +385,11 @@ class Application { void schedule_dump_config() { this->dump_config_at_ = 0; } + /// Minimum interval between real arch_feed_wdt() calls. Chosen to keep the + /// rate of HAL pokes low while still being small enough that any plausible + /// watchdog timeout (seconds) has orders of magnitude of safety margin. + static constexpr uint32_t WDT_FEED_INTERVAL_MS = 3; + /// Feed the task watchdog. Hot-path inline rate-limit check: callers that /// already have a timestamp in hand pay only a load + sub + branch on the /// common (no-op) path. The actual arch feed + status LED update live in @@ -393,7 +398,7 @@ class Application { /// Pass time==0 to request millis() be read for you (low-frequency callers /// only — always takes the slow path). void ESPHOME_ALWAYS_INLINE feed_wdt(uint32_t time = 0) { - if (time != 0 && static_cast(time - this->last_wdt_feed_) <= 3) { + if (time != 0 && static_cast(time - this->last_wdt_feed_) <= WDT_FEED_INTERVAL_MS) { return; } this->feed_wdt_slow_(time);