Skip to content

Commit df64e63

Browse files
author
Jiang Jiang Jian
committed
Merge branch 'fix/bypass_some_restore_process_if_sleep_rejected_v5.4' into 'release/v5.4'
fix(esp_hw_support): skip some wakeup steps if sleep is rejected (v5.4) See merge request espressif/esp-idf!34622
2 parents 3b0cf1a + 5923017 commit df64e63

File tree

1 file changed

+25
-24
lines changed

1 file changed

+25
-24
lines changed

components/esp_hw_support/sleep_modes.c

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1128,12 +1128,14 @@ static esp_err_t IRAM_ATTR esp_sleep_start(uint32_t pd_flags, esp_sleep_mode_t m
11281128
esp_sleep_execute_event_callbacks(SLEEP_EVENT_SW_CLK_READY, (void *)0);
11291129

11301130
if (!deep_sleep) {
1131-
s_config.ccount_ticks_record = esp_cpu_get_cycle_count();
1131+
if (result == ESP_OK) {
1132+
s_config.ccount_ticks_record = esp_cpu_get_cycle_count();
11321133
#if SOC_PM_RETENTION_SW_TRIGGER_REGDMA
1133-
if (pd_flags & PMU_SLEEP_PD_TOP) {
1134-
sleep_retention_do_system_retention(false);
1135-
}
1134+
if (pd_flags & PMU_SLEEP_PD_TOP) {
1135+
sleep_retention_do_system_retention(false);
1136+
}
11361137
#endif
1138+
}
11371139
misc_modules_wake_prepare(pd_flags);
11381140
}
11391141

@@ -1286,7 +1288,7 @@ static esp_err_t esp_light_sleep_inner(uint32_t pd_flags,
12861288
#endif
12871289

12881290
// If SPI flash was powered down, wait for it to become ready
1289-
if (pd_flags & RTC_SLEEP_PD_VDDSDIO) {
1291+
if (!reject && (pd_flags & RTC_SLEEP_PD_VDDSDIO)) {
12901292
#if SOC_PM_SUPPORT_TOP_PD
12911293
if (pd_flags & PMU_SLEEP_PD_TOP) {
12921294
uint32_t flash_ready_hw_waited_time_us = pmu_sleep_get_wakup_retention_cost();
@@ -1512,33 +1514,28 @@ esp_err_t esp_light_sleep_start(void)
15121514
// Enter sleep, then wait for flash to be ready on wakeup
15131515
err = esp_light_sleep_inner(pd_flags, flash_enable_time_us);
15141516
}
1515-
#if !CONFIG_FREERTOS_UNICORE && ESP_SLEEP_POWER_DOWN_CPU && SOC_PM_CPU_RETENTION_BY_SW
1516-
if (err != ESP_OK) {
1517-
esp_sleep_cpu_skip_retention();
1518-
}
1519-
#endif
15201517

15211518
// light sleep wakeup flag only makes sense after a successful light sleep
15221519
s_light_sleep_wakeup = (err == ESP_OK);
15231520

15241521
// System timer has been stopped for the duration of the sleep, correct for that.
15251522
uint64_t rtc_ticks_at_end = rtc_time_get();
1526-
uint64_t rtc_time_diff = rtc_time_slowclk_to_us(rtc_ticks_at_end - s_config.rtc_ticks_at_sleep_start, s_config.rtc_clk_cal_period);
15271523

1528-
#if CONFIG_ESP_SLEEP_DEBUG
1529-
if (s_sleep_ctx != NULL) {
1530-
s_sleep_ctx->sleep_out_rtc_time_stamp = rtc_ticks_at_end;
1531-
}
1524+
if (s_light_sleep_wakeup) {
1525+
uint64_t rtc_time_diff = rtc_time_slowclk_to_us(rtc_ticks_at_end - s_config.rtc_ticks_at_sleep_start, s_config.rtc_clk_cal_period);
1526+
/**
1527+
* If sleep duration is too small(less than 1 rtc_slow_clk cycle), rtc_time_diff will be zero.
1528+
* In this case, just ignore the time compensation and keep esp_timer monotonic.
1529+
*/
1530+
if (rtc_time_diff > 0) {
1531+
esp_timer_private_set(high_res_time_at_start + rtc_time_diff);
1532+
}
1533+
esp_set_time_from_rtc();
1534+
} else {
1535+
#if !CONFIG_FREERTOS_UNICORE && ESP_SLEEP_POWER_DOWN_CPU && SOC_PM_CPU_RETENTION_BY_SW
1536+
esp_sleep_cpu_skip_retention();
15321537
#endif
1533-
1534-
/**
1535-
* If sleep duration is too small(less than 1 rtc_slow_clk cycle), rtc_time_diff will be zero.
1536-
* In this case, just ignore the time compensation and keep esp_timer monotonic.
1537-
*/
1538-
if (rtc_time_diff > 0) {
1539-
esp_timer_private_set(high_res_time_at_start + rtc_time_diff);
15401538
}
1541-
esp_set_time_from_rtc();
15421539

15431540
esp_clk_private_unlock();
15441541
esp_timer_private_unlock();
@@ -1573,14 +1570,18 @@ esp_err_t esp_light_sleep_start(void)
15731570
#endif // CONFIG_ESP_TASK_WDT_USE_ESP_TIMER
15741571

15751572
esp_sleep_execute_event_callbacks(SLEEP_EVENT_SW_EXIT_SLEEP, (void *)0);
1576-
s_config.sleep_time_overhead_out = (esp_cpu_get_cycle_count() - s_config.ccount_ticks_record) / (esp_clk_cpu_freq() / 1000000ULL);
15771573

15781574
#if CONFIG_ESP_SLEEP_DEBUG
15791575
if (s_sleep_ctx != NULL) {
1576+
s_sleep_ctx->sleep_out_rtc_time_stamp = rtc_ticks_at_end;
15801577
s_sleep_ctx->sleep_request_result = err;
15811578
}
15821579
#endif
15831580

1581+
if (s_light_sleep_wakeup) {
1582+
s_config.sleep_time_overhead_out = (esp_cpu_get_cycle_count() - s_config.ccount_ticks_record) / (esp_clk_cpu_freq() / 1000000ULL);
1583+
}
1584+
15841585
portEXIT_CRITICAL(&s_config.lock);
15851586
return err;
15861587
}

0 commit comments

Comments
 (0)