Remove s_crash_valid and crash_handler_read_and_clear

resetInfo is a global that persists until next reset — no need to
cache the crash validity in a separate bool. Check resetInfo.reason
directly in crash_handler_has_data() and crash_handler_log().
This eliminates the only RAM byte from the crash handler and removes
the now-empty crash_handler_read_and_clear() function and its call
from arch_init().
This commit is contained in:
J. Nick Koston
2026-04-05 12:43:18 -10:00
parent 9f008ba487
commit ca623ace1a
3 changed files with 6 additions and 21 deletions
+1 -8
View File
@@ -2,9 +2,6 @@
#include "core.h"
#include "esphome/core/defines.h"
#ifdef USE_ESP8266_CRASH_HANDLER
#include "crash_handler.h"
#endif
#include "esphome/core/hal.h"
#include "esphome/core/time_64.h"
#include "esphome/core/helpers.h"
@@ -31,11 +28,7 @@ void arch_restart() {
yield();
}
}
void arch_init() {
#ifdef USE_ESP8266_CRASH_HANDLER
esp8266::crash_handler_read_and_clear();
#endif
}
void arch_init() {}
void HOT arch_feed_wdt() { system_soft_wdt_feed(); }
uint8_t progmem_read_byte(const uint8_t *addr) {
+5 -10
View File
@@ -87,17 +87,12 @@ namespace esphome::esp8266 {
static const char *const TAG = "esp8266.crash";
// Whether the previous boot was a crash. Set once in crash_handler_read_and_clear().
// resetInfo and RTC backtrace data persist until the next reset, so no caching needed.
static bool s_crash_valid = false; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
bool crash_handler_has_data() { return s_crash_valid; }
void crash_handler_read_and_clear() {
uint32_t reason = resetInfo.reason;
s_crash_valid = (reason == REASON_WDT_RST || reason == REASON_EXCEPTION_RST || reason == REASON_SOFT_WDT_RST);
static inline bool is_crash_reason(uint32_t reason) {
return reason == REASON_WDT_RST || reason == REASON_EXCEPTION_RST || reason == REASON_SOFT_WDT_RST;
}
bool crash_handler_has_data() { return is_crash_reason(resetInfo.reason); }
// Xtensa exception cause names (shared with ESP32, same ISA).
// Keep in sync with Xtensa ISA reference manual Table 4-64.
// Uses if-else with LOG_STR instead of switch to avoid CSWTCH jump tables
@@ -195,7 +190,7 @@ static uint8_t read_rtc_backtrace(uint32_t *backtrace, size_t max_entries) {
// crashes again during boot, and allowing the CLI's process_stacktrace to match
// and decode each address individually.
void crash_handler_log() {
if (!s_crash_valid)
if (!is_crash_reason(resetInfo.reason))
return;
// Read and filter backtrace from RTC into stack-local buffer (no persistent RAM cost).
@@ -8,9 +8,6 @@
namespace esphome::esp8266 {
/// Check if previous boot was a crash and set validity flag.
void crash_handler_read_and_clear();
/// Log crash data if a crash was detected on previous boot.
void crash_handler_log();