Fix possible reboot loop regression

This commit is contained in:
Theo Arends 2019-11-18 11:02:04 +01:00
parent bb567b523c
commit 11c5947c23
4 changed files with 26 additions and 11 deletions

View File

@ -20,6 +20,26 @@
IPAddress syslog_host_addr; // Syslog host IP address
uint32_t syslog_host_hash = 0; // Syslog host name hash
extern "C" {
extern struct rst_info resetInfo;
}
uint32_t ResetReason(void)
{
/*
user_interface.h
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 wont change
REASON_SOFT_WDT_RST = 3, // software watch dog reset, GPIO status wont change
REASON_SOFT_RESTART = 4, // software restart ,system_restart , GPIO status wont change
REASON_DEEP_SLEEP_AWAKE = 5, // wake up from deep-sleep
REASON_EXT_SYS_RST = 6 // external system reset
*/
return resetInfo.reason;
}
/*********************************************************************************************\
* Watchdog extension (https://github.com/esp8266/Arduino/issues/1532)
\*********************************************************************************************/

View File

@ -615,7 +615,6 @@ void WifiShutdown(void)
void EspRestart(void)
{
WifiShutdown();
RtcRebootReset();
// ESP.restart(); // This results in exception 3 on restarts on core 2.3.0
ESP.reset();
}

View File

@ -1500,10 +1500,6 @@ void GpioInit(void)
XdrvCall(FUNC_PRE_INIT);
}
extern "C" {
extern struct rst_info resetInfo;
}
void setup(void)
{
global_state.data = 3; // Init global state (wifi_down, mqtt_down) to solve possible network issues
@ -1582,7 +1578,7 @@ void setup(void)
Settings.module = SONOFF_BASIC; // Reset module to Sonoff Basic
// Settings.last_module = SONOFF_BASIC;
}
AddLog_P2(LOG_LEVEL_DEBUG, PSTR(D_LOG_APPLICATION D_LOG_SOME_SETTINGS_RESET " (%d)"), RtcReboot.fast_reboot_count);
AddLog_P2(LOG_LEVEL_INFO, PSTR(D_LOG_APPLICATION D_LOG_SOME_SETTINGS_RESET " (%d)"), RtcReboot.fast_reboot_count);
}
}
@ -1605,7 +1601,7 @@ void setup(void)
if (POWER_ALL_ALWAYS_ON == Settings.poweronstate) {
SetDevicePower(1, SRC_RESTART);
} else {
if ((resetInfo.reason == REASON_DEFAULT_RST) || (resetInfo.reason == REASON_EXT_SYS_RST)) {
if ((ResetReason() == REASON_DEFAULT_RST) || (ResetReason() == REASON_EXT_SYS_RST)) {
switch (Settings.poweronstate) {
case POWER_ALL_OFF:
case POWER_ALL_OFF_PULSETIME_ON:

View File

@ -59,15 +59,15 @@ bool DeepSleepEnabled(void)
return true;
}
void DeepSleepInit(void)
void DeepSleepReInit(void)
{
if (DeepSleepEnabled()) {
RtcRebootReset();
if ((ResetReason() == REASON_DEEP_SLEEP_AWAKE) && DeepSleepEnabled()) {
if ((RtcSettings.ultradeepsleep > MAX_DEEPSLEEP_CYCLE) && (RtcSettings.ultradeepsleep < 1700000000)) {
// Go back to sleep after 60 minutes if requested deepsleep has not been reached
RtcSettings.ultradeepsleep = RtcSettings.ultradeepsleep - MAX_DEEPSLEEP_CYCLE;
AddLog_P2(LOG_LEVEL_ERROR, PSTR("DSL: Remain DeepSleep %d"), RtcSettings.ultradeepsleep);
RtcSettingsSave();
RtcRebootReset();
ESP.deepSleep(100 * RtcSettings.deepsleep_slip * (MAX_DEEPSLEEP_CYCLE < RtcSettings.ultradeepsleep ? MAX_DEEPSLEEP_CYCLE : RtcSettings.ultradeepsleep), WAKE_RF_DEFAULT);
yield();
// Sleeping
@ -198,7 +198,7 @@ bool Xdrv29(uint8_t function)
result = DecodeCommand(kDeepsleepCommands, DeepsleepCommand);
break;
case FUNC_PRE_INIT:
DeepSleepInit();
DeepSleepReInit();
break;
}
return result;