reset logic fixed, restart counter addes

This commit is contained in:
cyberman54 2021-03-21 18:41:02 +01:00
parent 9060ba2f4c
commit b0864c45b9
3 changed files with 14 additions and 19 deletions

View File

@ -95,8 +95,8 @@ void start_boot_menu(void) {
// (because esp_restart() from ISR would trigger the ESP32 task watchdog) // (because esp_restart() from ISR would trigger the ESP32 task watchdog)
xTaskCreate( xTaskCreate(
[](void *p) { [](void *p) {
vTaskSuspend(NULL); vTaskSuspend(NULL); // wait for task resume call by watchdog
ESP.restart(); esp_restart();
}, },
"Restart", configMINIMAL_STACK_SIZE, NULL, (3 | portPRIVILEGE_BIT), "Restart", configMINIMAL_STACK_SIZE, NULL, (3 | portPRIVILEGE_BIT),
&RestartHandle); &RestartHandle);
@ -148,7 +148,6 @@ void start_boot_menu(void) {
[]() { []() {
server.sendHeader("Connection", "close"); server.sendHeader("Connection", "close");
server.send(200, "text/plain", (Update.hasError()) ? "FAIL" : "OK"); server.send(200, "text/plain", (Update.hasError()) ? "FAIL" : "OK");
WiFi.disconnect(true);
esp_restart(); esp_restart();
}, },

View File

@ -291,16 +291,15 @@ void setup() {
#endif #endif
#if (BOOTMENU) #if (BOOTMENU)
// start local webserver after device powers up or on rcommand request // start local webserver after each coldstart
if ((RTC_runmode == RUNMODE_POWERCYCLE) || if (RTC_runmode == RUNMODE_POWERCYCLE)
(RTC_runmode == RUNMODE_MAINTENANCE))
start_boot_menu();
#else
// start local webserver on rcommand request only
if (RTC_runmode == RUNMODE_MAINTENANCE)
start_boot_menu(); start_boot_menu();
#endif #endif
// start local webserver on rcommand request
if (RTC_runmode == RUNMODE_MAINTENANCE)
start_boot_menu();
// start mac processing task // start mac processing task
ESP_LOGI(TAG, "Starting MAC processor..."); ESP_LOGI(TAG, "Starting MAC processor...");
macQueueInit(); macQueueInit();

View File

@ -10,6 +10,7 @@ static const char TAG[] = __FILE__;
// RTC_NOINIT_ATTR -> keep value after a software restart or system crash // RTC_NOINIT_ATTR -> keep value after a software restart or system crash
RTC_NOINIT_ATTR runmode_t RTC_runmode; RTC_NOINIT_ATTR runmode_t RTC_runmode;
RTC_NOINIT_ATTR uint32_t RTC_restarts;
// RTC_DATA_ATTR -> keep values after a wakeup from sleep // RTC_DATA_ATTR -> keep values after a wakeup from sleep
RTC_DATA_ATTR struct timeval RTC_sleep_start_time; RTC_DATA_ATTR struct timeval RTC_sleep_start_time;
@ -17,9 +18,6 @@ RTC_DATA_ATTR unsigned long long RTC_millis = 0;
timeval sleep_stop_time; timeval sleep_stop_time;
const char *runmode[6] = {"powercycle", "normal", "wakeup",
"update", "sleep", "maintenance"};
void do_reset(bool warmstart) { void do_reset(bool warmstart) {
if (warmstart) { if (warmstart) {
ESP_LOGI(TAG, "restarting device (warmstart)"); ESP_LOGI(TAG, "restarting device (warmstart)");
@ -46,13 +44,11 @@ void do_after_reset(void) {
case RTCWDT_BROWN_OUT_RESET: // 0x0f Reset when the vdd voltage is not case RTCWDT_BROWN_OUT_RESET: // 0x0f Reset when the vdd voltage is not
// stable // stable
RTC_runmode = RUNMODE_POWERCYCLE; RTC_runmode = RUNMODE_POWERCYCLE;
RTC_restarts = 0;
break; break;
case SW_CPU_RESET: // 0x0c Software reset CPU case SW_CPU_RESET: // 0x0c Software reset CPU
// keep previous runmode, if RTC_runmode has valid value // keep previous set runmode (update / normal / maintenance)
// sets runmode, if RTC_runmode is invalid (i.e. not initialized)
if ((RTC_runmode != RUNMODE_UPDATE) && (RTC_runmode != RUNMODE_NORMAL))
RTC_runmode = RUNMODE_POWERCYCLE;
break; break;
case DEEPSLEEP_RESET: // 0x05 Deep Sleep reset digital core case DEEPSLEEP_RESET: // 0x05 Deep Sleep reset digital core
@ -84,8 +80,9 @@ void do_after_reset(void) {
break; break;
} }
ESP_LOGI(TAG, "Starting Software v%s, runmode %s", PROGVERSION, RTC_restarts++;
runmode[RTC_runmode]); ESP_LOGI(TAG, "Starting Software v%s (runmode=%d / restarts=%d)", PROGVERSION,
RTC_runmode, RTC_restarts);
} }
void enter_deepsleep(const uint64_t wakeup_sec, gpio_num_t wakeup_gpio) { void enter_deepsleep(const uint64_t wakeup_sec, gpio_num_t wakeup_gpio) {