From f87cb009400921cab2cd9a70890cba55e77a53c3 Mon Sep 17 00:00:00 2001 From: geeksville Date: Sun, 8 Mar 2020 14:05:12 -0700 Subject: [PATCH] show reason for last reset --- release/latest/curfirmwareversion.xml | 2 +- src/sleep.cpp | 30 ++++++++++++++++++--------- 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/release/latest/curfirmwareversion.xml b/release/latest/curfirmwareversion.xml index d692f8b3c..1321ab787 100644 --- a/release/latest/curfirmwareversion.xml +++ b/release/latest/curfirmwareversion.xml @@ -5,5 +5,5 @@ release. It is used by the android app for forcing software updates. Do not ed Generated by bin/buildall.sh --> - 0.1.0 + 0.1.3 diff --git a/src/sleep.cpp b/src/sleep.cpp index 91b3785a7..a9989f0de 100644 --- a/src/sleep.cpp +++ b/src/sleep.cpp @@ -19,7 +19,7 @@ #ifdef T_BEAM_V10 #include "axp20x.h" extern AXP20X_Class axp; -#endif +#endif // deep sleep support RTC_DATA_ATTR int bootCount = 0; @@ -28,8 +28,6 @@ esp_sleep_source_t wakeCause; // the reason we booted this time #define xstr(s) str(s) #define str(s) #s - - // ----------------------------------------------------------------------------- // Application // ----------------------------------------------------------------------------- @@ -63,7 +61,7 @@ void setLed(bool ledOn) void setGPSPower(bool on) { - DEBUG_MSG("Setting GPS power=%d\n", on); + DEBUG_MSG("Setting GPS power=%d\n", on); #ifdef T_BEAM_V10 if (axp192_found) @@ -84,9 +82,24 @@ void initDeepSleep() wakeButtons = ((uint64_t)1) << buttons.gpios[0]; */ - DEBUG_MSG("booted, wake cause %d (boot count %d)\n", wakeCause, bootCount); -} + // If we booted because our timer ran out or the user pressed reset, send those as fake events + const char *reason = "reset"; // our best guess + RESET_REASON hwReason = rtc_get_reset_reason(0); + if (hwReason == RTCWDT_BROWN_OUT_RESET) + reason = "brownout"; + + if (hwReason == TG0WDT_SYS_RESET) + reason = "taskWatchdog"; + + if (hwReason == TG1WDT_SYS_RESET) + reason = "intWatchdog"; + + if (wakeCause == ESP_SLEEP_WAKEUP_TIMER) + reason = "timeout"; + + DEBUG_MSG("booted, wake cause %d (boot count %d), reset_reason=%s\n", wakeCause, bootCount, reason); +} void doDeepSleep(uint64_t msecToWake) { @@ -175,9 +188,6 @@ void doDeepSleep(uint64_t msecToWake) esp_deep_sleep_start(); // TBD mA sleep current (battery) } - - - /** * enter light sleep (preserves ram but stops everything about CPU). * @@ -188,7 +198,7 @@ esp_sleep_wakeup_cause_t doLightSleep(uint64_t sleepMsec) // FIXME, use a more r //DEBUG_MSG("Enter light sleep\n"); uint64_t sleepUsec = sleepMsec * 1000LL; - Serial.flush(); // send all our characters before we stop cpu clock + Serial.flush(); // send all our characters before we stop cpu clock setBluetoothEnable(false); // has to be off before calling light sleep // NOTE! ESP docs say we must disable bluetooth and wifi before light sleep