From 4d5f5887487cc7e711ca8b9802d59aeff2475cc0 Mon Sep 17 00:00:00 2001 From: MichaelDvP Date: Mon, 18 Oct 2021 11:25:41 +0200 Subject: [PATCH] reset reason to system info --- src/system.cpp | 38 ++++++++++++++++++++++++++++++++++++++ src/system.h | 2 ++ 2 files changed, 40 insertions(+) diff --git a/src/system.cpp b/src/system.cpp index 0eefdef50..a0ea88328 100644 --- a/src/system.cpp +++ b/src/system.cpp @@ -23,6 +23,20 @@ #include "test/test.h" #endif +#ifdef ESP_IDF_VERSION_MAJOR // IDF 4+ +#if CONFIG_IDF_TARGET_ESP32 // ESP32/PICO-D4 +#include "../esp32/rom/rtc.h" +#elif CONFIG_IDF_TARGET_ESP32S2 +#include "../esp32s2/rom/rtc.h" +#elif CONFIG_IDF_TARGET_ESP32C3 +#include "../esp32c3/rom/rtc.h" +#else +#error Target CONFIG_IDF_TARGET is not supported +#endif +#else // ESP32 Before IDF 4.0 +#include "../rom/rtc.h" +#endif + namespace emsesp { uuid::log::Logger System::logger_{F_(system), uuid::log::Facility::KERN}; @@ -937,6 +951,7 @@ bool System::command_info(const char * value, const int8_t id, JsonObject & json #ifndef EMSESP_STANDALONE node["freemem"] = ESP.getFreeHeap() / 1000L; // kilobytes #endif + node["reset_reason"] = EMSESP::system_.reset_reason(0) + " / " + EMSESP::system_.reset_reason(1); node = json.createNestedObject("Status"); @@ -1041,4 +1056,27 @@ bool System::command_restart(const char * value, const int8_t id) { return true; } +const std::string System::reset_reason(uint8_t cpu) { + switch (rtc_get_reset_reason(cpu)) { + case 1: return ("Power on reset"); + // case 2 :reset pin not on esp32 + case 3: return ("Software reset"); + case 4: return ("Legacy watch dog reset"); + case 5: return ("Deep sleep reset"); + case 6: return ("Reset by SDIO"); + case 7: return ("Timer group0 watch dog reset"); + case 8: return ("Timer group1 watch dog reset"); + case 9: return ("RTC watch dog reset"); + case 10: return ("Intrusion reset CPU"); + case 11: return ("Timer group reset CPU"); + case 12: return ("Software reset CPU"); + case 13: return ("RTC watch dog reset: CPU"); + case 14: return ("APP CPU reseted by PRO CPU"); + case 15: return ("Brownout reset"); + case 16: return ("RTC watch dog reset: CPU+RTC"); + default: break; + } + return ("Unkonwn"); +} + } // namespace emsesp diff --git a/src/system.h b/src/system.h index 16bd35aa2..2dfac2144 100644 --- a/src/system.h +++ b/src/system.h @@ -63,6 +63,8 @@ class System { static bool command_settings(const char * value, const int8_t id, JsonObject & json); static bool command_commands(const char * value, const int8_t id, JsonObject & json); + const std::string reset_reason(uint8_t cpu); + void system_restart(); void format(uuid::console::Shell & shell); void upload_status(bool in_progress);