Merge branch 'feature/enable_sleep_reject_for_deep_sleep' into 'master'

sleep: enable sleep reject when entering deepsleep

Closes WIFI-6010

See merge request espressif/esp-idf!24127
This commit is contained in:
Wu Zheng Hui 2023-06-25 00:02:32 +08:00
commit c41abacb3a
5 changed files with 19 additions and 32 deletions

View File

@ -441,18 +441,6 @@ esp_err_t esp_light_sleep_start(void);
* Call to this function is equivalent to a call to esp_deep_sleep_enable_timer_wakeup
* followed by a call to esp_deep_sleep_start.
*
* esp_deep_sleep does not shut down WiFi, BT, and higher level protocol
* connections gracefully.
* Make sure relevant WiFi and BT stack functions are called to close any
* connections and deinitialize the peripherals. These include:
* - esp_bluedroid_disable
* - esp_bt_controller_disable
* - esp_wifi_stop
*
* This function does not return.
*
* @note The device will wake up immediately if the deep-sleep time is set to 0
*
* @param time_in_us deep-sleep time, unit: microsecond
*/
void esp_deep_sleep(uint64_t time_in_us) __attribute__((__noreturn__));

View File

@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
@ -527,7 +527,7 @@ inline static void IRAM_ATTR misc_modules_wake_prepare(void)
inline static uint32_t call_rtc_sleep_start(uint32_t reject_triggers, uint32_t lslp_mem_inf_fpu, bool dslp);
static uint32_t IRAM_ATTR esp_sleep_start(uint32_t pd_flags, esp_sleep_mode_t mode)
static esp_err_t IRAM_ATTR esp_sleep_start(uint32_t pd_flags, esp_sleep_mode_t mode)
{
// Stop UART output so that output is not lost due to APB frequency change.
// For light sleep, suspend UART output — it will resume after wakeup.
@ -618,13 +618,10 @@ static uint32_t IRAM_ATTR esp_sleep_start(uint32_t pd_flags, esp_sleep_mode_t mo
}
#endif
uint32_t reject_triggers = 0;
if (!deep_sleep) {
/* Light sleep, enable sleep reject for faster return from this function,
* in case the wakeup is already triggerred.
*/
reject_triggers = (s_config.wakeup_triggers & RTC_SLEEP_REJECT_MASK) | sleep_modem_reject_triggers();
}
/* Enable sleep reject for faster return from this function,
* in case the wakeup is already triggerred.
*/
uint32_t reject_triggers = (s_config.wakeup_triggers & RTC_SLEEP_REJECT_MASK) | sleep_modem_reject_triggers();
//Append some flags in addition to power domains
uint32_t sleep_flags = pd_flags;
@ -756,7 +753,7 @@ static uint32_t IRAM_ATTR esp_sleep_start(uint32_t pd_flags, esp_sleep_mode_t mo
// re-enable UART output
resume_uarts();
s_lightsleep_cnt++;
return result;
return result ? ESP_ERR_SLEEP_REJECT : ESP_OK;
}
inline static uint32_t IRAM_ATTR call_rtc_sleep_start(uint32_t reject_triggers, uint32_t lslp_mem_inf_fpu, bool dslp)
@ -829,7 +826,9 @@ void IRAM_ATTR esp_deep_sleep_start(void)
#endif
// Enter sleep
esp_sleep_start(force_pd_flags | pd_flags, ESP_SLEEP_MODE_DEEP_SLEEP);
if (esp_sleep_start(force_pd_flags | pd_flags, ESP_SLEEP_MODE_DEEP_SLEEP) == ESP_ERR_SLEEP_REJECT) {
ESP_EARLY_LOGW(TAG, "Deep sleep request is rejected");
}
// Because RTC is in a slower clock domain than the CPU, it
// can take several CPU cycles for the sleep mode to start.
@ -852,7 +851,7 @@ static esp_err_t esp_light_sleep_inner(uint32_t pd_flags,
uint32_t flash_enable_time_us)
{
// Enter sleep
uint32_t reject = esp_sleep_start(pd_flags, ESP_SLEEP_MODE_LIGHT_SLEEP);
esp_err_t reject = esp_sleep_start(pd_flags, ESP_SLEEP_MODE_LIGHT_SLEEP);
#if SOC_CONFIGURABLE_VDDSDIO_SUPPORTED
rtc_vddsdio_config_t vddsdio_config = rtc_vddsdio_get_config();
@ -869,7 +868,7 @@ static esp_err_t esp_light_sleep_inner(uint32_t pd_flags,
esp_rom_delay_us(flash_enable_time_us);
}
return reject ? ESP_ERR_SLEEP_REJECT : ESP_OK;
return reject;
}
/**

View File

@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2021-2023 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
@ -384,11 +384,11 @@ static void trigger_deepsleep(void)
esp_clk_slowclk_cal_set(esp_clk_slowclk_cal_get() / 2);
// Delay for error accumulation.
vTaskDelay(pdMS_TO_TICKS(1000));
vTaskDelay(pdMS_TO_TICKS(10*1000));
// Save start time. Deep sleep.
start = esp_rtc_get_time_us();
esp_sleep_enable_timer_wakeup(1000);
esp_sleep_enable_timer_wakeup(5000);
// In function esp_deep_sleep_start() uses function esp_sync_timekeeping_timers()
// to prevent a negative time after wake up.
esp_deep_sleep_start();
@ -404,11 +404,11 @@ static void check_time_deepsleep_1(void)
esp_clk_slowclk_cal_set(esp_clk_slowclk_cal_get() * 2);
// Delay for error accumulation.
vTaskDelay(pdMS_TO_TICKS(1000));
vTaskDelay(pdMS_TO_TICKS(10*1000));
start = esp_rtc_get_time_us();
esp_sleep_enable_timer_wakeup(1000);
esp_sleep_enable_timer_wakeup(5000);
// In function esp_deep_sleep_start() uses function esp_sync_timekeeping_timers()
// to prevent a negative time after wake up.
esp_deep_sleep_start();

View File

@ -586,7 +586,7 @@ static void trigger_deepsleep(void)
// Deinit NVS to prevent Unity from complaining "The test leaked too much memory"
TEST_ESP_OK(nvs_flash_deinit());
esp_sleep_enable_timer_wakeup(1000);
esp_sleep_enable_timer_wakeup(5000);
// In function esp_deep_sleep_start() uses function esp_sync_timekeeping_timers()
// to prevent a negative time after wake up.
esp_deep_sleep_start();

View File

@ -23,7 +23,7 @@ def test_gptimer_example(dut: Dut) -> None:
dut.expect_exact('Start timer, auto-reload at alarm event', timeout=5)
res = dut.expect(r'Timer reloaded, count=(\d+)', timeout=5)
reloaded_count = res.group(1).decode('utf8')
assert 0 <= int(reloaded_count) < 10
assert 0 <= int(reloaded_count) < 20
dut.expect_exact('Stop timer')
dut.expect_exact('Start timer, update alarm value dynamically')