Skip to content

Commit

Permalink
Merge branch 'fix/bypass_some_restore_process_if_sleep_rejected_v5.0'…
Browse files Browse the repository at this point in the history
… into 'release/v5.0'

fix(esp_hw_support): skip some wakeup steps if sleep is rejected (v5.0)

See merge request espressif/esp-idf!34631
  • Loading branch information
Jiang Jiang Jian committed Nov 12, 2024
2 parents e00cb93 + b81dbfb commit bc82044
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions components/esp_hw_support/sleep_modes.c
Original file line number Diff line number Diff line change
Expand Up @@ -759,7 +759,7 @@ static esp_err_t esp_light_sleep_inner(uint32_t pd_flags,
}

// If SPI flash was powered down, wait for it to become ready
if (pd_flags & RTC_SLEEP_PD_VDDSDIO) {
if (!reject && (pd_flags & RTC_SLEEP_PD_VDDSDIO)) {
// Wait for the flash chip to start up
esp_rom_delay_us(flash_enable_time_us);
}
Expand Down Expand Up @@ -941,16 +941,18 @@ esp_err_t esp_light_sleep_start(void)

// System timer has been stopped for the duration of the sleep, correct for that.
uint64_t rtc_ticks_at_end = rtc_time_get();
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);

/**
* If sleep duration is too small(less than 1 rtc_slow_clk cycle), rtc_time_diff will be zero.
* In this case, just ignore the time compensation and keep esp_timer monotonic.
*/
if (rtc_time_diff > 0) {
esp_timer_private_set(high_res_time_at_start + rtc_time_diff);
if (s_light_sleep_wakeup) {
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);
/**
* If sleep duration is too small(less than 1 rtc_slow_clk cycle), rtc_time_diff will be zero.
* In this case, just ignore the time compensation and keep esp_timer monotonic.
*/
if (rtc_time_diff > 0) {
esp_timer_private_set(high_res_time_at_start + rtc_time_diff);
}
esp_set_time_from_rtc();
}
esp_set_time_from_rtc();

esp_clk_private_unlock();
esp_timer_private_unlock();
Expand All @@ -960,8 +962,6 @@ esp_err_t esp_light_sleep_start(void)
wdt_hal_disable(&rtc_wdt_ctx);
wdt_hal_write_protect_enable(&rtc_wdt_ctx);
}
portEXIT_CRITICAL(&light_sleep_lock);
s_config.sleep_time_overhead_out = (esp_cpu_get_cycle_count() - s_config.ccount_ticks_record) / (esp_clk_cpu_freq() / 1000000ULL);

#if CONFIG_ESP_TASK_WDT_USE_ESP_TIMER
/* Restart the Task Watchdog timer as it was stopped before sleeping. */
Expand All @@ -970,6 +970,11 @@ esp_err_t esp_light_sleep_start(void)
}
#endif // CONFIG_ESP_TASK_WDT_USE_ESP_TIMER

if (s_light_sleep_wakeup) {
s_config.sleep_time_overhead_out = (esp_cpu_get_cycle_count() - s_config.ccount_ticks_record) / (esp_clk_cpu_freq() / 1000000ULL);
}

portEXIT_CRITICAL(&light_sleep_lock);
return err;
}

Expand Down

0 comments on commit bc82044

Please sign in to comment.