From e455315bbf08ffa64a2b5cb20f6c451f3fcfd837 Mon Sep 17 00:00:00 2001 From: Charles Date: Mon, 25 Jan 2016 00:43:03 +0100 Subject: [PATCH 1/3] Added comment on Reset reason --- tools/sdk/include/user_interface.h | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/tools/sdk/include/user_interface.h b/tools/sdk/include/user_interface.h index 470556c70..81868563b 100644 --- a/tools/sdk/include/user_interface.h +++ b/tools/sdk/include/user_interface.h @@ -23,13 +23,13 @@ #endif enum rst_reason { - REASON_DEFAULT_RST = 0, - REASON_WDT_RST = 1, - REASON_EXCEPTION_RST = 2, - REASON_SOFT_WDT_RST = 3, - REASON_SOFT_RESTART = 4, - REASON_DEEP_SLEEP_AWAKE = 5, - REASON_EXT_SYS_RST = 6 + REASON_DEFAULT_RST = 0, /* normal startup by power on */ + REASON_WDT_RST = 1, /* hardware watch dog reset */ + REASON_EXCEPTION_RST = 2, /* exception reset, GPIO status won’t change */ + REASON_SOFT_WDT_RST = 3, /* software watch dog reset, GPIO status won’t change */ + REASON_SOFT_RESTART = 4, /* software restart ,system_restart , GPIO status won’t change */ + REASON_DEEP_SLEEP_AWAKE = 5, /* wake up from deep-sleep */ + REASON_EXT_SYS_RST = 6 /* external system reset */ }; struct rst_info{ From d9a51f9fa1b42002c291c2f5796ff996f25bb637 Mon Sep 17 00:00:00 2001 From: Charles Date: Mon, 25 Jan 2016 00:43:57 +0100 Subject: [PATCH 2/3] Added getResetReason in human readable form --- cores/esp8266/Esp.cpp | 22 ++++++++++++++++++++++ cores/esp8266/Esp.h | 1 + 2 files changed, 23 insertions(+) diff --git a/cores/esp8266/Esp.cpp b/cores/esp8266/Esp.cpp index a0e5c6f41..3416c9b91 100644 --- a/cores/esp8266/Esp.cpp +++ b/cores/esp8266/Esp.cpp @@ -329,6 +329,28 @@ bool EspClass::checkFlashConfig(bool needsEquals) { return false; } +String EspClass::getResetReason(void) { + char buff[32]; + if (resetInfo.reason == REASON_DEFAULT_RST) { // normal startup by power on + strcpy_P(buff, PSTR("Power on")); + } else if (resetInfo.reason == REASON_WDT_RST) { // hardware watch dog reset + strcpy_P(buff, PSTR("Hardware Watchdog")); + } else if (resetInfo.reason == REASON_EXCEPTION_RST) { // exception reset, GPIO status won’t change + strcpy_P(buff, PSTR("Exception")); + } else if (resetInfo.reason == REASON_SOFT_WDT_RST) { // software watch dog reset, GPIO status won’t change + strcpy_P(buff, PSTR("Software Watchdog")); + } else if (resetInfo.reason == REASON_SOFT_RESTART) { // software restart ,system_restart , GPIO status won’t change + strcpy_P(buff, PSTR("Software/System restart")); + } else if (resetInfo.reason == REASON_DEEP_SLEEP_AWAKE) { // wake up from deep-sleep + strcpy_P(buff, PSTR("Deep-Sleep Wake")); + } else if (resetInfo.reason == REASON_EXT_SYS_RST) { // external system reset + strcpy_P(buff, PSTR("External System")); + } else { + strcpy_P(buff, PSTR("Unknown")); + } + return String(buff); +} + String EspClass::getResetInfo(void) { if(resetInfo.reason != 0) { char buff[200]; diff --git a/cores/esp8266/Esp.h b/cores/esp8266/Esp.h index f04dd0e4d..405a94c8e 100644 --- a/cores/esp8266/Esp.h +++ b/cores/esp8266/Esp.h @@ -131,6 +131,7 @@ class EspClass { uint32_t getFreeSketchSpace(); bool updateSketch(Stream& in, uint32_t size, bool restartOnFail = false, bool restartOnSuccess = true); + String getResetReason(); String getResetInfo(); struct rst_info * getResetInfoPtr(); From c81abd2a926796627834b1aa1ee15879a1b86471 Mon Sep 17 00:00:00 2001 From: Charles Date: Mon, 25 Jan 2016 00:48:46 +0100 Subject: [PATCH 3/3] Added getResetReason --- doc/changes.md | 1 + doc/libraries.md | 2 ++ 2 files changed, 3 insertions(+) diff --git a/doc/changes.md b/doc/changes.md index 1855121d5..bed0289f1 100644 --- a/doc/changes.md +++ b/doc/changes.md @@ -6,6 +6,7 @@ title: Change Log ### Core +- Add function to know last reset resaon. - Allow control of enabling debug and debug level from IDE - Make HardwareSerial::begin() and end() interrupt safe - Put HardwareSerial and cbuf methods called from interrupt context in RAM diff --git a/doc/libraries.md b/doc/libraries.md index 210171ec6..22e913bab 100644 --- a/doc/libraries.md +++ b/doc/libraries.md @@ -83,6 +83,8 @@ APIs related to deep sleep and watchdog timer are available in the `ESP` object, `ESP.restart()` restarts the CPU. +`ESP.getResetReason()` returns String containing the last reset resaon in human readable format. + `ESP.getFreeHeap()` returns the free heap size. `ESP.getChipId()` returns the ESP8266 chip ID as a 32-bit integer.