Skip to content

Commit aee378e

Browse files
committed
fix(esp_hw_support): fix coverity defects in sleep code
1 parent 9b5809d commit aee378e

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

components/esp_hw_support/sleep_modes.c

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -968,6 +968,14 @@ static esp_err_t IRAM_ATTR esp_sleep_start(uint32_t pd_flags, esp_sleep_mode_t m
968968
#endif // SOC_PM_SUPPORT_DEEPSLEEP_CHECK_STUB_ONLY
969969
#endif
970970

971+
#if SOC_DCDC_SUPPORTED
972+
uint64_t ldo_increased_us = rtc_time_slowclk_to_us(rtc_time_get() - s_config.rtc_ticks_at_ldo_prepare, s_config.rtc_clk_cal_period);
973+
if (ldo_increased_us < LDO_POWER_TAKEOVER_PREPARATION_TIME_US) {
974+
esp_rom_delay_us(LDO_POWER_TAKEOVER_PREPARATION_TIME_US - ldo_increased_us);
975+
}
976+
pmu_sleep_shutdown_dcdc();
977+
#endif
978+
971979
// Enter Deep Sleep
972980
#if!ESP_ROM_SUPPORT_DEEP_SLEEP_WAKEUP_STUB || SOC_PM_SUPPORT_DEEPSLEEP_CHECK_STUB_ONLY || !CONFIG_ESP_SYSTEM_ALLOW_RTC_FAST_MEM_AS_HEAP
973981
#if SOC_PMU_SUPPORTED
@@ -994,19 +1002,12 @@ static esp_err_t IRAM_ATTR esp_sleep_start(uint32_t pd_flags, esp_sleep_mode_t m
9941002
#endif
9951003
#endif
9961004

997-
#if SOC_DCDC_SUPPORTED
998-
#if CONFIG_ESP_SLEEP_KEEP_DCDC_ALWAYS_ON
999-
if (!deep_sleep) {
1000-
// Keep DCDC always on during light sleep, no need to adjust LDO voltage.
1001-
} else
1002-
#endif
1003-
{
1004-
uint64_t ldo_increased_us = rtc_time_slowclk_to_us(rtc_time_get() - s_config.rtc_ticks_at_ldo_prepare, s_config.rtc_clk_cal_period);
1005-
if (ldo_increased_us < LDO_POWER_TAKEOVER_PREPARATION_TIME_US) {
1006-
esp_rom_delay_us(LDO_POWER_TAKEOVER_PREPARATION_TIME_US - ldo_increased_us);
1007-
}
1008-
pmu_sleep_shutdown_dcdc();
1005+
#if SOC_DCDC_SUPPORTED && !CONFIG_ESP_SLEEP_KEEP_DCDC_ALWAYS_ON
1006+
uint64_t ldo_increased_us = rtc_time_slowclk_to_us(rtc_time_get() - s_config.rtc_ticks_at_ldo_prepare, s_config.rtc_clk_cal_period);
1007+
if (ldo_increased_us < LDO_POWER_TAKEOVER_PREPARATION_TIME_US) {
1008+
esp_rom_delay_us(LDO_POWER_TAKEOVER_PREPARATION_TIME_US - ldo_increased_us);
10091009
}
1010+
pmu_sleep_shutdown_dcdc();
10101011
#endif
10111012

10121013
#if SOC_PMU_SUPPORTED

0 commit comments

Comments
 (0)