#pragma once #include #include // ════════════════════════════════════════════════════════════════════════════ // CRASH BREADCRUMBS — context that survives a panic reboot (F-070) // ════════════════════════════════════════════════════════════════════════════ // The coredump summary (see Telemetry::captureCrashReport) only knows the CPU // state at the moment the chip went down. For an abort() — unhandled C++ // exception, failed assert, FreeRTOS stack-overflow check — that state is // panic_abort()'s own deliberate write to address 0, so PC/cause/vaddr say // nothing about *why* (see F-055). Two things fill that gap, both kept in // RTC_NOINIT memory, which survives software/panic/watchdog resets but NOT // power-on or brownout: // // 1. The abort reason string — captured by wrapping esp_system_abort() at // link time (-Wl,--wrap=esp_system_abort in platformio.ini). Every abort // path in this SDK funnels through it: abort() ("abort() was called at PC // 0x... on core N" — that PC is abort()'s caller), assert ("assert failed: // func file:line (expr)"), and the FreeRTOS stack-overflow hook. // 2. A heap/uptime snapshot refreshed every second by TelemetryTask — the // last known state right before the reset (fragmentation killed us once). // // Both are consumed once at boot and cleared, so they're reported exactly once. struct PreCrashSnapshot { bool available = false; uint32_t uptimeMs = 0; // millis() at the last snapshot before the reset uint32_t freeHeap = 0; // free heap at that snapshot uint32_t largestBlock = 0; // largest allocatable block at that snapshot uint32_t minFreeHeap = 0; // lowest free heap ever seen during that boot char abortMsg[160] = {0}; // empty unless the reset came from esp_system_abort() }; namespace CrashBreadcrumbs { // Refresh the heap/uptime snapshot. Cheap; called from TelemetryTask every 1s. void updateSnapshot(); // Read whatever the previous boot left behind, then clear it. Call once, // early in boot, and only trust the result on a fault-class reset — RTC // memory is garbage after a power-on, which the magic check guards against. PreCrashSnapshot consume(); }