reset.cpp: cleanup reset reasons
This commit is contained in:
parent
4b216fb564
commit
69fd3e51e2
@ -2,7 +2,7 @@
|
||||
#define _RESET_H
|
||||
|
||||
#include <driver/rtc_io.h>
|
||||
#include <rom/rtc.h>
|
||||
#include <soc/reset_reasons.h>
|
||||
|
||||
#include "i2c.h"
|
||||
#include "lorawan.h"
|
||||
|
@ -11,7 +11,6 @@ static const char TAG[] = __FILE__;
|
||||
// RTC_NOINIT_ATTR -> keep value after a software restart or system crash
|
||||
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 struct timeval RTC_sleep_start_time;
|
||||
RTC_DATA_ATTR unsigned long long RTC_millis = 0;
|
||||
@ -53,18 +52,17 @@ void do_after_reset(void) {
|
||||
#endif
|
||||
|
||||
switch (rtc_get_reset_reason(0)) {
|
||||
case POWERON_RESET: // 0x01 Vbat power on reset
|
||||
case RTCWDT_BROWN_OUT_RESET: // 0x0f Reset when the vdd voltage is not
|
||||
// stable
|
||||
case RESET_REASON_CHIP_POWER_ON:
|
||||
case RESET_REASON_SYS_BROWN_OUT:
|
||||
reset_rtc_vars();
|
||||
break;
|
||||
|
||||
case SW_CPU_RESET: // 0x0c Software reset CPU
|
||||
case RESET_REASON_CPU0_SW:
|
||||
// keep previous set runmode (update / normal / maintenance)
|
||||
RTC_restarts++;
|
||||
break;
|
||||
|
||||
case DEEPSLEEP_RESET: // 0x05 Deep Sleep reset digital core
|
||||
case RESET_REASON_CORE_DEEP_SLEEP:
|
||||
// calculate time spent in deep sleep
|
||||
gettimeofday(&sleep_stop_time, NULL);
|
||||
sleep_time_ms =
|
||||
@ -72,26 +70,13 @@ void do_after_reset(void) {
|
||||
(sleep_stop_time.tv_usec - RTC_sleep_start_time.tv_usec) / 1000;
|
||||
RTC_millis += sleep_time_ms; // increment system monotonic time
|
||||
ESP_LOGI(TAG, "Time spent in deep sleep: %d ms", sleep_time_ms);
|
||||
|
||||
// do we have a valid time? -> set global variable
|
||||
timeSource = timeIsValid(sleep_stop_time.tv_sec) ? _set : _unsynced;
|
||||
|
||||
// set wakeup state, not if we have pending OTA update
|
||||
if (RTC_runmode == RUNMODE_SLEEP)
|
||||
RTC_runmode = RUNMODE_WAKEUP;
|
||||
break;
|
||||
|
||||
case SW_RESET: // 0x03 Software reset digital core
|
||||
case OWDT_RESET: // 0x04 Legacy watch dog reset digital core
|
||||
case SDIO_RESET: // 0x06 Reset by SLC module, reset digital core
|
||||
case TG0WDT_SYS_RESET: // 0x07 Timer Group0 Watch dog reset digital core
|
||||
case TG1WDT_SYS_RESET: // 0x08 Timer Group1 Watch dog reset digital core
|
||||
case RTCWDT_SYS_RESET: // 0x09 RTC Watch dog Reset digital core
|
||||
case INTRUSION_RESET: // 0x0a Instrusion tested to reset CPU
|
||||
case TGWDT_CPU_RESET: // 0x0b Time Group reset CPU
|
||||
case RTCWDT_CPU_RESET: // 0x0d RTC Watch dog Reset CPU
|
||||
case EXT_CPU_RESET: // 0x0e for APP CPU, reseted by PRO CPU
|
||||
case RTCWDT_RTC_RESET: // 0x10 RTC Watch dog reset digital core and rtc mode
|
||||
default:
|
||||
RTC_runmode = RUNMODE_POWERCYCLE;
|
||||
RTC_restarts++;
|
||||
@ -108,7 +93,6 @@ void enter_deepsleep(const uint64_t wakeup_sec, gpio_num_t wakeup_gpio) {
|
||||
// validate wake up pin, if we have
|
||||
if (!GPIO_IS_VALID_GPIO(wakeup_gpio))
|
||||
wakeup_gpio = GPIO_NUM_MAX;
|
||||
|
||||
// stop further enqueuing of senddata and MAC processing
|
||||
libpax_counter_stop();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user