mirror of
https://github.com/esphome/esphome.git
synced 2026-05-25 10:26:10 +08:00
[core] Extract WDT_FEED_INTERVAL_MS constexpr
Replace the magic 3 in both the inline feed_wdt check and the slow path with a named constexpr so the rate-limit threshold is defined once.
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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<uint32_t>(time - this->last_wdt_feed_) <= 3) {
|
||||
if (time != 0 && static_cast<uint32_t>(time - this->last_wdt_feed_) <= WDT_FEED_INTERVAL_MS) {
|
||||
return;
|
||||
}
|
||||
this->feed_wdt_slow_(time);
|
||||
|
||||
Reference in New Issue
Block a user