Public Access
45 lines
1.3 KiB
C
45 lines
1.3 KiB
C
#pragma once
|
|||
|
|
|
||
|
|
#include <stdint.h>
|
||
|
|
|
||
|
|
// Decides how the ESP32 starts after a reset, so OTA keeps working even when the firmware
|
||
|
|
// crashes. Pure logic, tested in test/test_esp32.
|
||
|
|
//
|
||
|
|
// Power on normal start, crash counter cleared
|
||
|
|
// Software reset normal start (e.g. after an OTA update)
|
||
|
|
// Crash (panic, watchdog) crash counter + 1, then:
|
||
|
|
// < SAFE_MODE_CRASHES OTA-only for OTA_PANIC_WINDOW, then normal
|
||
|
|
// >= SAFE_MODE_CRASHES safe mode: OTA only for SAFE_MODE_TIME
|
||
|
|
// Other (brownout, ...) normal start, counter kept
|
||
|
|
|
||
|
|
enum class ResetKind
|
||
|
|
{
|
||
|
|
PowerOn,
|
||
|
|
Software,
|
||
|
|
Crash,
|
||
|
|
Other,
|
||
|
|
};
|
||
|
|
|
||
|
|
enum class BootMode
|
||
|
|
{
|
||
|
|
Normal,
|
||
|
|
PanicWindow, // OTA only for a short time, then normal
|
||
|
|
SafeMode, // OTA only for a long time, then restart
|
||
|
|
};
|
||
|
|
|
||
|
|
struct BootDecision
|
||
|
|
{
|
||
|
|
BootMode mode;
|
||
|
|
uint8_t crash_count;
|
||
|
|
};
|
||
|
|
|
||
|
|
BootDecision decideBoot(ResetKind reset, uint8_t crash_count);
|
||
|
|
|
||
|
|
// Crash counter after safe mode ends: one more crash brings safe mode back
|
||
|
|
uint8_t crashCountAfterSafeMode();
|
||
|
|
|
||
|
|
// A new OTA firmware is accepted (no rollback) once it ran this long with WiFi
|
||
|
|
bool shouldMarkFirmwareValid(uint32_t running_ms, bool wifi_connected);
|
||
|
|
|
||
|
|
// Running this long without a crash clears the crash counter
|
||
|
|
bool shouldClearCrashCount(uint32_t running_ms);
|