From 5846013bb1ece712ff92052e590b3cd244be545b Mon Sep 17 00:00:00 2001 From: Ewoud Date: Sun, 31 Mar 2024 10:53:58 +0200 Subject: [PATCH] Move espTools functions to SysModSystem and use stack size functions General: remove static LedLeds: remove rotate (as PanTiltRol takes over) SysModSystem: - Move espTools functions to SysModSystem - stack vars: use sysTools_get_arduino_maxStackUsage and sysTools_get_webserver_maxStackUsage --- src/App/LedLeds.cpp | 6 +- src/App/LedLeds.h | 39 ------ src/App/LedModEffects.h | 5 +- src/Sys/SysModNetwork.h | 2 - src/Sys/SysModPrint.cpp | 6 +- src/Sys/SysModSystem.cpp | 194 +++++++++++++++++++++++++++-- src/Sys/SysModSystem.h | 17 +++ src/Sys/esp32Tools.cpp | 260 --------------------------------------- src/Sys/esp32Tools.h | 21 ---- src/main.cpp | 4 - 10 files changed, 207 insertions(+), 347 deletions(-) delete mode 100644 src/Sys/esp32Tools.cpp delete mode 100644 src/Sys/esp32Tools.h diff --git a/src/App/LedLeds.cpp b/src/App/LedLeds.cpp index dd2589ee..32390c3f 100644 --- a/src/App/LedLeds.cpp +++ b/src/App/LedLeds.cpp @@ -23,11 +23,7 @@ void fastled_fill_rainbow(struct CRGB * targetArray, int numToFill, unsigned8 in } unsigned16 Leds::XYZ(unsigned16 x, unsigned16 y, unsigned16 z) { - if (projectionNr == p_Rotate) { - Coord3D result = spinXY(x, y, size.x, size.y, proRollSpeed); - return result.x + result.y * size.x + result.z * size.x * size.y; - } - else if (projectionNr == p_PanTiltRoll || projectionNr == p_Preset1) { + if (projectionNr == p_PanTiltRoll || projectionNr == p_Preset1) { Coord3D result = Coord3D{x, y, z}; if (proPanSpeed) result = trigoPanTiltRoll.pan(result, size/2, millis() * 5 / (255 - proPanSpeed)); if (proTiltSpeed) result = trigoPanTiltRoll.tilt(result, size/2, millis() * 5 / (255 - proTiltSpeed)); diff --git a/src/App/LedLeds.h b/src/App/LedLeds.h index b5245b9a..577e204e 100644 --- a/src/App/LedLeds.h +++ b/src/App/LedLeds.h @@ -32,7 +32,6 @@ enum Projections { p_Default, p_Multiply, - p_Rotate, p_PanTiltRoll, p_DistanceFromPoint, p_Preset1, @@ -163,44 +162,6 @@ class SharedData { }; -static float sinrot = 0.0f; -static float cosrot = 1.0f; -static unsigned long last_millis = UINT_MAX; - -constexpr float projScaleMax = 1.0f; // full size -constexpr float projScaleMin = 0.701f; // 1/sqrt(2) -static float projScale = projScaleMax; - -static Coord3D spinXY(uint_fast16_t x, uint_fast16_t y, uint_fast16_t width, uint_fast16_t height, unsigned8 speed) { - if ((millis()/12) != last_millis) { - // update sin / cos for rotation - once each 12ms - float now = float(millis()/12) / (255 - speed); // this sets the rotation speed - //float now = float(strip.now) / 2000.0f; // error: 'strip' was not declared in this scope - sinrot = sinf(now); - cosrot = cosf(now); - last_millis = millis()/12; - // scale to fit - comment out the next lines to disable - // float maxProj = max(abs(width/2 * sinrot), abs(height/2 * cosrot)); - // int maxdim = max(width/2, height/2); - // float newScaling = maxProj / float(maxdim); - // projScale = max(min(newScaling, projScaleMax), projScaleMin); - } - // center - int x1 = int(x) - width/2; - int y1 = int(y) - height/2; - // matrix mult for rotation - float x2 = float(x1) * cosrot - float(y1) * sinrot; - float y2 = float(x1) * sinrot + float(y1) * cosrot; - // un-center - int x3 = lround(x2 * projScale) + width/2; // projScale adds some down-scaling, - int y3 = lround(y2 * projScale) + height/2; // so everything fits fully into the original matrix. Note to self: this is still sub-optimal. - // check bounds - - if ((x3 <0) || (x3 >= width) || (y3 <0) || (y3 >= height)) return Coord3D{0, 0, 0}; // outside of matrix - // deliver fish - else return Coord3D{(unsigned16)x3, (unsigned16)y3, 0}; -} - struct PhysMap { // bool isPhys = false; // 1 byte // union { diff --git a/src/App/LedModEffects.h b/src/App/LedModEffects.h index 2ba0ae9d..95dd160c 100644 --- a/src/App/LedModEffects.h +++ b/src/App/LedModEffects.h @@ -126,7 +126,6 @@ class LedModEffects:public SysModule { JsonArray options = ui->setOptions(var); // see enum Projections in LedFixture.h and keep the same order ! options.add("Default"); options.add("Multiply"); - options.add("Rotate"); options.add("PanTiltRoll"); options.add("Distance ⌛"); options.add("Preset 1"); @@ -204,7 +203,7 @@ class LedModEffects:public SysModule { default: return false; }}); } - if (proValue == p_Rotate || proValue == p_Preset1 || proValue == p_PanTiltRoll) { + if (proValue == p_Preset1 || proValue == p_PanTiltRoll) { ui->initSlider(var, "proRoll", 128, 0, 254, false, [this](JsonObject var, unsigned8 rowNr, unsigned8 funType) { switch (funType) { //varFun case f_UIFun: ui->setLabel(var, "Roll speed"); @@ -364,7 +363,7 @@ class LedModEffects:public SysModule { mdl->getValueRowNr = rowNr++; effects.loop(*leds); mdl->getValueRowNr = UINT8_MAX; - if (leds->projectionNr == p_PanTiltRoll || leds->projectionNr == p_Rotate || leds->projectionNr == p_Preset1) + if (leds->projectionNr == p_PanTiltRoll || leds->projectionNr == p_Preset1) leds->fadeToBlackBy(50); } } diff --git a/src/Sys/SysModNetwork.h b/src/Sys/SysModNetwork.h index 3580ffef..2f7784d2 100644 --- a/src/Sys/SysModNetwork.h +++ b/src/Sys/SysModNetwork.h @@ -61,8 +61,6 @@ class SysModNetwork:public SysModule { bool isConfirmedConnection = false; DNSServer dnsServer; byte stacO = 0; //stationCount - - //init static variables (https://www.tutorialspoint.com/cplusplus/cpp_static_members.htm) }; extern SysModNetwork *net; \ No newline at end of file diff --git a/src/Sys/SysModPrint.cpp b/src/Sys/SysModPrint.cpp index 0f045603..296f344b 100644 --- a/src/Sys/SysModPrint.cpp +++ b/src/Sys/SysModPrint.cpp @@ -14,7 +14,7 @@ #include "SysModUI.h" #include "SysModModel.h" #include "SysModWeb.h" -#include "esp32Tools.h" +#include "SysModSystem.h" SysModPrint::SysModPrint() :SysModule("Print") { @@ -42,9 +42,9 @@ SysModPrint::SysModPrint() :SysModule("Print") { delay(3000); // this extra delay avoids repeating disconnects on -s2 "Disconnected (ClearCommError failed" Serial.println(" **** COMMODORE BASIC V2 **** "); #endif - if (!sysTools_normal_startup() && Serial) { // only print if Serial is connected, and startup was not normal + if (!sys->sysTools_normal_startup() && Serial) { // only print if Serial is connected, and startup was not normal Serial.print("\nWARNING - possible crash: "); - Serial.println(sysTools_getRestartReason()); + Serial.println(sys->sysTools_getRestartReason()); Serial.println(""); } Serial.println("Ready.\n"); diff --git a/src/Sys/SysModSystem.cpp b/src/Sys/SysModSystem.cpp index e28ffbe1..da3e875c 100644 --- a/src/Sys/SysModSystem.cpp +++ b/src/Sys/SysModSystem.cpp @@ -14,11 +14,24 @@ #include "SysModUI.h" #include "SysModWeb.h" #include "SysModModel.h" -#include "esp32Tools.h" #include "SysModWorkFlow.h" // #include -#include + +// get the right RTC.H for each MCU +#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(4, 0, 0) + #if CONFIG_IDF_TARGET_ESP32S2 + #include + #elif CONFIG_IDF_TARGET_ESP32C3 + #include + #elif CONFIG_IDF_TARGET_ESP32S3 + #include + #elif CONFIG_IDF_TARGET_ESP32 // ESP32/PICO-D4 + #include + #endif +#else // ESP32 Before IDF 4.0 + #include +#endif SysModSystem::SysModSystem() :SysModule("System") {}; @@ -90,28 +103,28 @@ void SysModSystem::setup() { }}); } - ui->initProgress(parentVar, "mainStack", UINT16_MAX, 0, getArduinoLoopTaskStackSize(), true, [](JsonObject var, unsigned8 rowNr, unsigned8 funType) { switch (funType) { //varFun + ui->initProgress(parentVar, "mainStack", UINT16_MAX, 0, getArduinoLoopTaskStackSize(), true, [this](JsonObject var, unsigned8 rowNr, unsigned8 funType) { switch (funType) { //varFun case f_ValueFun: - mdl->setValue(var, uxTaskGetStackHighWaterMark(NULL)); + mdl->setValue(var, sysTools_get_arduino_maxStackUsage()); return true; case f_UIFun: ui->setLabel(var, "Main stack"); return true; case f_ChangeFun: - web->addResponseV(var["id"], "comment", "%d of %d B", uxTaskGetStackHighWaterMark(NULL), getArduinoLoopTaskStackSize()); + web->addResponseV(var["id"], "comment", "%d of %d B", sysTools_get_arduino_maxStackUsage(), getArduinoLoopTaskStackSize()); return true; default: return false; }}); - ui->initProgress(parentVar, "tcpStack", UINT16_MAX, 0, CONFIG_ASYNC_TCP_TASK_STACK_SIZE, true, [](JsonObject var, unsigned8 rowNr, unsigned8 funType) { switch (funType) { //varFun + ui->initProgress(parentVar, "tcpStack", UINT16_MAX, 0, CONFIG_ASYNC_TCP_TASK_STACK_SIZE, true, [this](JsonObject var, unsigned8 rowNr, unsigned8 funType) { switch (funType) { //varFun case f_ValueFun: - mdl->setValue(var, uxTaskGetStackHighWaterMark(xTaskGetHandle("async_tcp"))); + mdl->setValue(var, sysTools_get_webserver_maxStackUsage()); return true; case f_UIFun: ui->setLabel(var, "TCP stack"); return true; case f_ChangeFun: - web->addResponseV(var["id"], "comment", "%d of %d B", uxTaskGetStackHighWaterMark(xTaskGetHandle("async_tcp")), CONFIG_ASYNC_TCP_TASK_STACK_SIZE); + web->addResponseV(var["id"], "comment", "%d of %d B", sysTools_get_webserver_maxStackUsage(), CONFIG_ASYNC_TCP_TASK_STACK_SIZE); return true; default: return false; }}); @@ -166,7 +179,7 @@ void SysModSystem::setup() { default: return false; }}); - // static char msgbuf[32]; + // char msgbuf[32]; // snprintf(msgbuf, sizeof(msgbuf)-1, "%s rev.%d", ESP.getChipModel(), ESP.getChipRevision()); // ui->initText(parentVar, "e32model")] = msgbuf; // ui->initText(parentVar, "e32cores")] = ESP.getChipCores(); @@ -248,4 +261,165 @@ void SysModSystem::addRestartReasonsSelect(JsonArray options) { options.add(sysTools_restart2String( 8)); ////!< Reset after exiting deep sleep mode options.add(sysTools_restart2String( 9)); // //!< Brownout reset (software or hardware) options.add(sysTools_restart2String(10)); // //!< Reset over SDIO -} \ No newline at end of file +} + +//from esptools.h - public + +// check if estart was "normal" +bool SysModSystem::sysTools_normal_startup() { + esp_reset_reason_t restartCode = getRestartReason(); + if ((restartCode == ESP_RST_POWERON) || (restartCode == ESP_RST_SW)) return true; // poweron or esp_restart() + return false; +} + +// RESTART reason as long string +String SysModSystem::sysTools_getRestartReason() { + esp_reset_reason_t restartCode = getRestartReason(); + String reasonText = restartCode2InfoLong(restartCode); + String longText = String("(code ") + String((int)restartCode) + String( ") ") + reasonText; + + int core0code = getCoreResetReason(0); + int core1code = getCoreResetReason(1); + longText = longText + ". Core#0 (code " + String(core0code) + ") " + resetCode2Info(core0code); + if (core1code > 0) + longText = longText + "; Core#1 (code " + String(core1code) + ") " + resetCode2Info(core1code); + + longText = longText + "."; + return longText; +} + +// helper for SysModSystem::addRestartReasonsSelect. Returns "(#) ReasonText" +String SysModSystem::sysTools_restart2String(int reasoncode) { + esp_reset_reason_t restartCode = esp_reset_reason_t(reasoncode); // its a trick, not a sony ;-) + String longText = String("(") + String(reasoncode) + String( ") ") + restartCode2Info(restartCode); + return longText; +} + +// helper for SysModSystem::addResetReasonsSelect. Returns "CoreResetReasonText (#)" +String SysModSystem::sysTools_reset2String(int resetCode) { + String longText = resetCode2Info(resetCode) + String(" (") + String(resetCode) + String(")"); + return longText; +} + +int SysModSystem::sysTools_get_arduino_maxStackUsage(void) { + char * loop_taskname = pcTaskGetTaskName(loop_taskHandle); // ask for name of the known task (to make sure we are still looking at the right one) + + if ((loop_taskHandle == NULL) || (loop_taskname == NULL) || (strncmp(loop_taskname, "loopTask", 8) != 0)) { + loop_taskHandle = xTaskGetHandle("loopTask"); // need to look for the task by name. FreeRTOS docs say this is very slow, so we store the result for next time + } + + if (loop_taskHandle != NULL) return uxTaskGetStackHighWaterMark(loop_taskHandle); // got it !! + else return -1; +} + +int SysModSystem::sysTools_get_webserver_maxStackUsage(void) { + char * tcp_taskname = pcTaskGetTaskName(tcp_taskHandle); // ask for name of the known task (to make sure we are still looking at the right one) + + if ((tcp_taskHandle == NULL) || (tcp_taskname == NULL) || (strncmp(tcp_taskname, "async_tcp", 9) != 0)) { + tcp_taskHandle = xTaskGetHandle("async_tcp"); // need to look for the task by name. FreeRTOS docs say this is very slow, so we store the result for next time + } + + if (tcp_taskHandle != NULL) return uxTaskGetStackHighWaterMark(tcp_taskHandle); // got it !! + else return -1; +} + + +//from esptools.h - private + +// helper fuctions +int SysModSystem::getCoreResetReason(int core) { + if (core >= ESP.getChipCores()) return 0; + return((int)rtc_get_reset_reason(core)); +} + +String SysModSystem::resetCode2Info(int reason) { + switch(reason) { + + case 1 : // 1 = Vbat power on reset + return "power-on"; break; + case 2 : // 2 = this code is not defined on ESP32 + return "exception"; break; + case 3 : // 3 = Software reset digital core + return "SW reset"; break; + case 12: //12 = Software reset CPU + return "SW restart"; break; + case 5 : // 5 = Deep Sleep wakeup reset digital core + return "wakeup"; break; + case 14: //14 = for APP CPU, reset by PRO CPU + return "restart"; break; + case 15: //15 = Reset when the vdd voltage is not stable (brownout) + return "brown-out"; break; + + // watchdog resets + case 4 : // 4 = Legacy watch dog reset digital core + case 6 : // 6 = Reset by SLC module, reset digital core + case 7 : // 7 = Timer Group0 Watch dog reset digital core + case 8 : // 8 = Timer Group1 Watch dog reset digital core + case 9 : // 9 = RTC Watch dog Reset digital core + case 11: //11 = Time Group watchdog reset CPU + case 13: //13 = RTC Watch dog Reset CPU + case 16: //16 = RTC Watch dog reset digital core and rtc module + case 17: //17 = Time Group1 reset CPU + return "watchdog"; break; + case 18: //18 = super watchdog reset digital core and rtc module + return "super watchdog"; break; + + // misc + case 10: // 10 = Instrusion tested to reset CPU + return "intrusion"; break; + case 19: //19 = glitch reset digital core and rtc module + return "glitch"; break; + case 20: //20 = efuse reset digital core + return "EFUSE reset"; break; + case 21: //21 = usb uart reset digital core + return "USB UART reset"; break; + case 22: //22 = usb jtag reset digital core + return "JTAG reset"; break; + case 23: //23 = power glitch reset digital core and rtc module + return "power glitch"; break; + + // unknown reason code + case 0: + return "none"; break; + default: + return "unknown"; break; + } +} + +esp_reset_reason_t SysModSystem::getRestartReason() { + return(esp_reset_reason()); +} +String SysModSystem::restartCode2InfoLong(esp_reset_reason_t reason) { + switch (reason) { + case ESP_RST_UNKNOWN: return("Reset reason can not be determined"); break; + case ESP_RST_POWERON: return("Restart due to power-on event"); break; + case ESP_RST_EXT: return("Reset by external pin (not applicable for ESP32)"); break; + case ESP_RST_SW: return("Software restart via esp_restart()"); break; + case ESP_RST_PANIC: return("Software reset due to panic or unhandled exception (SW error)"); break; + case ESP_RST_INT_WDT: return("Reset (software or hardware) due to interrupt watchdog"); break; + case ESP_RST_TASK_WDT: return("Reset due to task watchdog"); break; + case ESP_RST_WDT: return("Reset due to other watchdogs"); break; + case ESP_RST_DEEPSLEEP:return("Restart after exiting deep sleep mode"); break; + case ESP_RST_BROWNOUT: return("Brownout Reset (software or hardware)"); break; + case ESP_RST_SDIO: return("Reset over SDIO"); break; + } + return("unknown"); +} + +String SysModSystem::restartCode2Info(esp_reset_reason_t reason) { + switch (reason) { + case ESP_RST_UNKNOWN: return("unknown reason"); break; + case ESP_RST_POWERON: return("power-on event"); break; + case ESP_RST_EXT: return("external pin reset"); break; + case ESP_RST_SW: return("SW restart by esp_restart()"); break; + case ESP_RST_PANIC: return("SW error - panic or exception"); break; + case ESP_RST_INT_WDT: return("interrupt watchdog"); break; + case ESP_RST_TASK_WDT: return("task watchdog"); break; + case ESP_RST_WDT: return("other watchdog"); break; + case ESP_RST_DEEPSLEEP:return("exit from deep sleep"); break; + case ESP_RST_BROWNOUT: return("Brownout Reset"); break; + case ESP_RST_SDIO: return("Reset over SDIO"); break; + } + return("unknown"); +} + diff --git a/src/Sys/SysModSystem.h b/src/Sys/SysModSystem.h index 3ad52359..3d452fb9 100644 --- a/src/Sys/SysModSystem.h +++ b/src/Sys/SysModSystem.h @@ -25,6 +25,13 @@ class SysModSystem:public SysModule { void loop1s(); void loop10s(); + //from esp32Tools + bool sysTools_normal_startup(void); // FALSE if unusual startup code --> use next function to get more info + String sysTools_getRestartReason(void); // long string including restart codes from system, Core#0 and Core#1 (if availeable) + String sysTools_restart2String(int reasoncode); // helper for SysModSystem::addRestartReasonsSelect. Returns "(#) ReasonText" + String sysTools_reset2String(int resetCode); // helper for SysModSystem::addResetReasonsSelect. Returns "shortResetReasonText (#)" + int sysTools_get_arduino_maxStackUsage(void); // to query max used stack of the arduino task. returns "-1" if unknown + int sysTools_get_webserver_maxStackUsage(void); // to query max used stack of the webserver task. returns "-1" if unknown private: unsigned long loopCounter = 0; @@ -32,6 +39,16 @@ class SysModSystem:public SysModule { void addResetReasonsSelect(JsonArray select); void addRestartReasonsSelect(JsonArray select); + // from esp32Tools: helper fuctions + int getCoreResetReason(int core); + String resetCode2Info(int reason); + esp_reset_reason_t getRestartReason(); + String restartCode2InfoLong(esp_reset_reason_t reason); + String restartCode2Info(esp_reset_reason_t reason); + + TaskHandle_t loop_taskHandle = NULL; // to store the task handle for later calls + TaskHandle_t tcp_taskHandle = NULL; // to store the task handle for later calls + }; extern SysModSystem *sys; \ No newline at end of file diff --git a/src/Sys/esp32Tools.cpp b/src/Sys/esp32Tools.cpp deleted file mode 100644 index baa35b67..00000000 --- a/src/Sys/esp32Tools.cpp +++ /dev/null @@ -1,260 +0,0 @@ -/* - @title StarMod - @file esp32Tools.cpp - @date 20240121 - @repo https://github.com/ewowi/StarMod - @Authors https://github.com/ewowi/StarMod/commits/main - @Copyright © 2024 Github StarMod Commit Authors - @license GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007 - @license For non GPL-v3 usage, commercial licenses must be purchased. Contact moonmodules@icloud.com -*/ - -// This is a collection of ESP32 specific low-level functions. - -#if defined(ARDUINO_ARCH_ESP32) - -#include -#include "esp32Tools.h" - -#include "soc/soc.h" -#include "soc/rtc_cntl_reg.h" - -#include -// get the right RTC.H for each MCU -#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(4, 0, 0) -#if CONFIG_IDF_TARGET_ESP32S2 -#include -#elif CONFIG_IDF_TARGET_ESP32C3 -#include -#elif CONFIG_IDF_TARGET_ESP32S3 -#include -#elif CONFIG_IDF_TARGET_ESP32 // ESP32/PICO-D4 -#include -#endif -#else // ESP32 Before IDF 4.0 -#include -#endif - -// forward declarations of local helper functions -static esp_reset_reason_t getRestartReason(); -static int getCoreResetReason(int core); -static String resetCode2Info(int reason); -static String restartCode2InfoLong(esp_reset_reason_t reason); -static String restartCode2Info(esp_reset_reason_t reason); - - -// check if estart was "normal" -bool sysTools_normal_startup() { - esp_reset_reason_t restartCode = getRestartReason(); - if ((restartCode == ESP_RST_POWERON) || (restartCode == ESP_RST_SW)) return true; // poweron or esp_restart() - return false; -} - -// RESTART reason as long string -String sysTools_getRestartReason() { - esp_reset_reason_t restartCode = getRestartReason(); - String reasonText = restartCode2InfoLong(restartCode); - String longText = String("(code ") + String((int)restartCode) + String( ") ") + reasonText; - - int core0code = getCoreResetReason(0); - int core1code = getCoreResetReason(1); - longText = longText + ". Core#0 (code " + String(core0code) + ") " + resetCode2Info(core0code); - if (core1code > 0) - longText = longText + "; Core#1 (code " + String(core1code) + ") " + resetCode2Info(core1code); - - longText = longText + "."; - return longText; -} - -// helper for SysModSystem::addRestartReasonsSelect. Returns "(#) ReasonText" -String sysTools_restart2String(int reasoncode) { - esp_reset_reason_t restartCode = esp_reset_reason_t(reasoncode); // its a trick, not a sony ;-) - String longText = String("(") + String(reasoncode) + String( ") ") + restartCode2Info(restartCode); - return longText; -} - -// helper for SysModSystem::addResetReasonsSelect. Returns "CoreResetReasonText (#)" -String sysTools_reset2String(int resetCode) { - String longText = resetCode2Info(resetCode) + String(" (") + String(resetCode) + String(")"); - return longText; -} - - -// stack debug tools - find loopTask task, and queries it's free stack size - -#if INCLUDE_xTaskGetHandle // only supported on newer frameworks -int sysTools_get_arduino_maxStackUsage(void) { - static TaskHandle_t loop_taskHandle = NULL; // to store the task handle for later calls - char * loop_taskname = pcTaskGetTaskName(loop_taskHandle); // ask for name of the known task (to make sure we are still looking at the right one) - - if ((loop_taskHandle == NULL) || (loop_taskname == NULL) || (strncmp(loop_taskname, "loopTask", 8) != 0)) { - loop_taskHandle = xTaskGetHandle("loopTask"); // need to look for the task by name. FreeRTOS docs say this is very slow, so we store the result for next time - } - - if (loop_taskHandle != NULL) return uxTaskGetStackHighWaterMark(loop_taskHandle); // got it !! - else return -1; -} - -int sysTools_get_webserver_maxStackUsage(void) { - static TaskHandle_t tcp_taskHandle = NULL; // to store the task handle for later calls - char * tcp_taskname = pcTaskGetTaskName(tcp_taskHandle); // ask for name of the known task (to make sure we are still looking at the right one) - - if ((tcp_taskHandle == NULL) || (tcp_taskname == NULL) || (strncmp(tcp_taskname, "async_tcp", 9) != 0)) { - tcp_taskHandle = xTaskGetHandle("async_tcp"); // need to look for the task by name. FreeRTOS docs say this is very slow, so we store the result for next time - } - - if (tcp_taskHandle != NULL) return uxTaskGetStackHighWaterMark(tcp_taskHandle); // got it !! - else return -1; -} -#else -#warning cannot query task stacksize on your system -int sysTools_get_arduino_maxStackUsage(void) { return -1;} -int sysTools_get_webserver_maxStackUsage(void) { return -1;} -#endif - - -// helper fuctions -static int getCoreResetReason(int core) { - if (core >= ESP.getChipCores()) return 0; - return((int)rtc_get_reset_reason(core)); -} - -static String resetCode2Info(int reason) { - switch(reason) { - - case 1 : // 1 = Vbat power on reset - return "power-on"; break; - case 2 : // 2 = this code is not defined on ESP32 - return "exception"; break; - case 3 : // 3 = Software reset digital core - return "SW reset"; break; - case 12: //12 = Software reset CPU - return "SW restart"; break; - case 5 : // 5 = Deep Sleep wakeup reset digital core - return "wakeup"; break; - case 14: //14 = for APP CPU, reset by PRO CPU - return "restart"; break; - case 15: //15 = Reset when the vdd voltage is not stable (brownout) - return "brown-out"; break; - - // watchdog resets - case 4 : // 4 = Legacy watch dog reset digital core - case 6 : // 6 = Reset by SLC module, reset digital core - case 7 : // 7 = Timer Group0 Watch dog reset digital core - case 8 : // 8 = Timer Group1 Watch dog reset digital core - case 9 : // 9 = RTC Watch dog Reset digital core - case 11: //11 = Time Group watchdog reset CPU - case 13: //13 = RTC Watch dog Reset CPU - case 16: //16 = RTC Watch dog reset digital core and rtc module - case 17: //17 = Time Group1 reset CPU - return "watchdog"; break; - case 18: //18 = super watchdog reset digital core and rtc module - return "super watchdog"; break; - - // misc - case 10: // 10 = Instrusion tested to reset CPU - return "intrusion"; break; - case 19: //19 = glitch reset digital core and rtc module - return "glitch"; break; - case 20: //20 = efuse reset digital core - return "EFUSE reset"; break; - case 21: //21 = usb uart reset digital core - return "USB UART reset"; break; - case 22: //22 = usb jtag reset digital core - return "JTAG reset"; break; - case 23: //23 = power glitch reset digital core and rtc module - return "power glitch"; break; - - // unknown reason code - case 0: - return "none"; break; - default: - return "unknown"; break; - } -} - - -static esp_reset_reason_t getRestartReason() { - return(esp_reset_reason()); -} - -static String restartCode2InfoLong(esp_reset_reason_t reason) { - switch (reason) { - case ESP_RST_UNKNOWN: return("Reset reason can not be determined"); break; - case ESP_RST_POWERON: return("Restart due to power-on event"); break; - case ESP_RST_EXT: return("Reset by external pin (not applicable for ESP32)"); break; - case ESP_RST_SW: return("Software restart via esp_restart()"); break; - case ESP_RST_PANIC: return("Software reset due to panic or unhandled exception (SW error)"); break; - case ESP_RST_INT_WDT: return("Reset (software or hardware) due to interrupt watchdog"); break; - case ESP_RST_TASK_WDT: return("Reset due to task watchdog"); break; - case ESP_RST_WDT: return("Reset due to other watchdogs"); break; - case ESP_RST_DEEPSLEEP:return("Restart after exiting deep sleep mode"); break; - case ESP_RST_BROWNOUT: return("Brownout Reset (software or hardware)"); break; - case ESP_RST_SDIO: return("Reset over SDIO"); break; - } - return("unknown"); -} - -static String restartCode2Info(esp_reset_reason_t reason) { - switch (reason) { - case ESP_RST_UNKNOWN: return("unknown reason"); break; - case ESP_RST_POWERON: return("power-on event"); break; - case ESP_RST_EXT: return("external pin reset"); break; - case ESP_RST_SW: return("SW restart by esp_restart()"); break; - case ESP_RST_PANIC: return("SW error - panic or exception"); break; - case ESP_RST_INT_WDT: return("interrupt watchdog"); break; - case ESP_RST_TASK_WDT: return("task watchdog"); break; - case ESP_RST_WDT: return("other watchdog"); break; - case ESP_RST_DEEPSLEEP:return("exit from deep sleep"); break; - case ESP_RST_BROWNOUT: return("Brownout Reset"); break; - case ESP_RST_SDIO: return("Reset over SDIO"); break; - } - return("unknown"); -} - - -// from WLEDMM - will integrate this later -#if 0 - DEBUG_PRINT("esp32 "); - DEBUG_PRINTLN(ESP.getSdkVersion()); - #if defined(ESP_ARDUINO_VERSION) - DEBUG_PRINT"arduino-esp32 v%d.%d.%d\n", int(ESP_ARDUINO_VERSION_MAJOR), int(ESP_ARDUINO_VERSION_MINOR), int(ESP_ARDUINO_VERSION_PATCH)); // availeable since v2.0.0 - #else - DEBUG_PRINTLN("arduino-esp32 v1.0.x\n"); // we can't say in more detail. - #endif - - USER_PRINT("CPU: "); USER_PRINT(ESP.getChipModel()); - USER_PRINT(" rev."); USER_PRINT(ESP.getChipRevision()); - USER_PRINT(", "); USER_PRINT(ESP.getChipCores()); USER_PRINT(" core(s)"); - USER_PRINT(", "); USER_PRINT(ESP.getCpuFreqMHz()); USER_PRINTLN("MHz."); - - USER_PRINT("CPU "); - esp_reset_reason_t resetReason = getRestartReason(); - USER_PRINT(restartCode2InfoLong(resetReason)); - USER_PRINT(" (code "); - USER_PRINT((int)resetReason); - USER_PRINT(". "); - int core0code = getCoreResetReason(0); - int core1code = getCoreResetReason(1); - USER_PRINT"Core#0 %s (%d)", resetCode2Info(core0code).c_str(), core0code); - if (core1code > 0) {USER_PRINT"; Core#1 %s (%d)", resetCode2Info(core1code).c_str(), core1code);} - USER_PRINTLN("."); - - USER_PRINT("FLASH: "); USER_PRINT((ESP.getFlashChipSize()/1024)/1024); - USER_PRINT("MB, Mode "); USER_PRINT(ESP.getFlashChipMode()); - switch (ESP.getFlashChipMode()) { - // missing: Octal modes - case FM_QIO: DEBUG_PRINT(" (QIO)"); break; - case FM_QOUT: DEBUG_PRINT(" (QOUT)");break; - case FM_DIO: DEBUG_PRINT(" (DIO)"); break; - case FM_DOUT: DEBUG_PRINT(" (DOUT)");break; - default: break; - } - USER_PRINT(", speed "); USER_PRINT(ESP.getFlashChipSpeed()/1000000);USER_PRINTLN("MHz."); -#endif - - - -#else - #error SystemTools are not yet availeable for your environment -#endif \ No newline at end of file diff --git a/src/Sys/esp32Tools.h b/src/Sys/esp32Tools.h deleted file mode 100644 index ff478f0e..00000000 --- a/src/Sys/esp32Tools.h +++ /dev/null @@ -1,21 +0,0 @@ -/* - @title StarMod - @file esp32Tools.h - @date 20240121 - @repo https://github.com/ewowi/StarMod - @Authors https://github.com/ewowi/StarMod/commits/main - @Copyright © 2024 Github StarMod Commit Authors - @license GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007 - @license For non GPL-v3 usage, commercial licenses must be purchased. Contact moonmodules@icloud.com -*/ - -// This is a collection of ESP32 specific low-level functions. - -bool sysTools_normal_startup(void); // FALSE if unusual startup code --> use next function to get more info -String sysTools_getRestartReason(void); // long string including restart codes from system, Core#0 and Core#1 (if availeable) - -String sysTools_restart2String(int reasoncode); // helper for SysModSystem::addRestartReasonsSelect. Returns "(#) ReasonText" -String sysTools_reset2String(int resetCode); // helper for SysModSystem::addResetReasonsSelect. Returns "shortResetReasonText (#)" - -int sysTools_get_arduino_maxStackUsage(void); // to query max used stack of the arduino task. returns "-1" if unknown -int sysTools_get_webserver_maxStackUsage(void); // to query max used stack of the webserver task. returns "-1" if unknown diff --git a/src/main.cpp b/src/main.cpp index 97778c64..3d40aef0 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -156,8 +156,4 @@ void setup() { //loop all modules void loop() { mdls->loop(); - - // static bool onoff = false; - // onoff = !onoff; - // digitalWrite(LED_BUILTIN, onoff? HIGH:LOW); } \ No newline at end of file