From d8141bdf513aeb01ba1aeae95784533ee6191d1d Mon Sep 17 00:00:00 2001 From: jingli Date: Wed, 26 Oct 2022 17:07:07 +0800 Subject: [PATCH] esp_hw_support/sleep: fix light sleep wakeup flag light sleep wakeup flag is true to indicate the most recent successful wakeup from light sleep, which means the most recent light sleep occurred successfully and then wakes up by wakeup source --- components/esp_system/sleep_modes.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/components/esp_system/sleep_modes.c b/components/esp_system/sleep_modes.c index 7d626b52fa..f1e59e9e6b 100644 --- a/components/esp_system/sleep_modes.c +++ b/components/esp_system/sleep_modes.c @@ -830,15 +830,20 @@ esp_err_t esp_light_sleep_start(void) int64_t final_sleep_duration_us = (int64_t)s_config.sleep_duration - (int64_t)s_config.sleep_time_adjustment; int64_t min_sleep_duration_us = rtc_time_slowclk_to_us(RTC_CNTL_MIN_SLP_VAL_MIN, s_config.rtc_clk_cal_period); + // reset light sleep wakeup flag before a new light sleep + s_light_sleep_wakeup = false; + // if rtc timer wakeup source is enabled, need to compare final sleep duration and min sleep duration to avoid late wakeup if ((s_config.wakeup_triggers & RTC_TIMER_TRIG_EN) && (final_sleep_duration_us <= min_sleep_duration_us)) { err = ESP_ERR_SLEEP_TOO_SHORT_SLEEP_DURATION; } else { // Enter sleep, then wait for flash to be ready on wakeup err = esp_light_sleep_inner(pd_flags, flash_enable_time_us, vddsdio_config); - s_light_sleep_wakeup = true; } + // light sleep wakeup flag only makes sense after a successful light sleep + s_light_sleep_wakeup = (err == ESP_OK); + // FRC1 has been clock gated for the duration of the sleep, correct for that. #ifdef CONFIG_IDF_TARGET_ESP32C3 /**