reset logic fixed (initialize RTC vars after OTA)
This commit is contained in:
parent
75e23973a3
commit
cc4daa0954
@ -2,6 +2,7 @@
|
||||
#define _CONFIGMANAGER_H
|
||||
|
||||
#include "globals.h"
|
||||
#include "reset.h"
|
||||
#include <Preferences.h>
|
||||
|
||||
void saveConfig(bool erase = false);
|
||||
|
@ -9,6 +9,7 @@
|
||||
#include "display.h"
|
||||
#include "power.h"
|
||||
|
||||
void reset_rtc_vars(void);
|
||||
void do_reset(bool warmstart);
|
||||
void do_after_reset(void);
|
||||
void enter_deepsleep(const uint64_t wakeup_sec = 60,
|
||||
@ -16,5 +17,6 @@ void enter_deepsleep(const uint64_t wakeup_sec = 60,
|
||||
unsigned long long uptime(void);
|
||||
|
||||
extern RTC_NOINIT_ATTR runmode_t RTC_runmode;
|
||||
extern RTC_NOINIT_ATTR uint32_t RTC_restarts;
|
||||
|
||||
#endif // _RESET_H
|
@ -48,7 +48,7 @@ static void defaultConfig(configData_t *myconfig) {
|
||||
myconfig->blescantime =
|
||||
BLESCANINTERVAL /
|
||||
10; // BT channel scan cycle [seconds/100], default 1 (= 10ms)
|
||||
myconfig->blescan = BLECOUNTER; // 0=disabled, 1=enabled
|
||||
myconfig->blescan = BLECOUNTER; // 0=disabled, 1=enabled
|
||||
myconfig->wifiscan = WIFICOUNTER; // 0=disabled, 1=enabled
|
||||
myconfig->wifiant = 0; // 0=internal, 1=external (for LoPy/LoPy4)
|
||||
myconfig->macfilter = MACFILTER; // 0=disabled, 1=enabled
|
||||
@ -159,4 +159,7 @@ int version_compare(const String v1, const String v2) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
void eraseConfig(void) { saveConfig(true); }
|
||||
void eraseConfig(void) {
|
||||
reset_rtc_vars();
|
||||
saveConfig(true);
|
||||
}
|
@ -140,6 +140,7 @@ void setup() {
|
||||
esp_log_level_set("*", ESP_LOG_NONE);
|
||||
#endif
|
||||
|
||||
// load device configuration from NVRAM and set runmode
|
||||
do_after_reset();
|
||||
|
||||
// print chip information on startup if in verbose mode after coldstart
|
||||
@ -206,9 +207,6 @@ void setup() {
|
||||
strcat_P(features, " PMU");
|
||||
#endif
|
||||
|
||||
// read (and initialize on first run) runtime settings from NVRAM
|
||||
_ASSERT(loadConfig()); // includes initialize if necessary
|
||||
|
||||
// now that we are powered, we scan i2c bus for devices
|
||||
if (RTC_runmode == RUNMODE_POWERCYCLE)
|
||||
i2c_scan();
|
||||
|
@ -306,7 +306,7 @@ void get_status(uint8_t val[]) {
|
||||
payload.reset();
|
||||
payload.addStatus(read_voltage(), (uint64_t)(uptime() / 1000ULL),
|
||||
temperatureRead(), getFreeRAM(), rtc_get_reset_reason(0),
|
||||
rtc_get_reset_reason(1));
|
||||
(uint8_t)RTC_restarts);
|
||||
SendPayload(STATUSPORT);
|
||||
};
|
||||
|
||||
|
@ -18,6 +18,11 @@ RTC_DATA_ATTR unsigned long long RTC_millis = 0;
|
||||
|
||||
timeval sleep_stop_time;
|
||||
|
||||
void reset_rtc_vars(void) {
|
||||
RTC_runmode = RUNMODE_POWERCYCLE;
|
||||
RTC_restarts = 0;
|
||||
}
|
||||
|
||||
void do_reset(bool warmstart) {
|
||||
if (warmstart) {
|
||||
ESP_LOGI(TAG, "restarting device (warmstart)");
|
||||
@ -38,13 +43,15 @@ void do_after_reset(void) {
|
||||
struct timeval sleep_stop_time;
|
||||
uint64_t sleep_time_ms;
|
||||
|
||||
// read (and initialize on first run) runtime settings from NVRAM
|
||||
loadConfig();
|
||||
|
||||
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
|
||||
RTC_runmode = RUNMODE_POWERCYCLE;
|
||||
RTC_restarts = 0;
|
||||
reset_rtc_vars();
|
||||
break;
|
||||
|
||||
case SW_CPU_RESET: // 0x0c Software reset CPU
|
||||
|
Loading…
Reference in New Issue
Block a user