Skip to content

Commit 9ffd8aa

Browse files
esp-wzhespressif-bot
authored andcommitted
fix(esp_hw_support): fix coverity defects in sleep code
1 parent dde0b46 commit 9ffd8aa

File tree

2 files changed

+20
-15
lines changed

2 files changed

+20
-15
lines changed

components/esp_hw_support/port/esp32p4/io_mux.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
#include "sdkconfig.h"
88
#include "esp_attr.h"
9+
#include "esp_check.h"
910
#include "freertos/FreeRTOS.h"
1011
#include "esp_private/esp_clk_tree_common.h"
1112
#include "esp_private/io_mux.h"
@@ -14,6 +15,8 @@
1415
#include "hal/rtc_io_ll.h"
1516
#include "soc/soc_caps.h"
1617

18+
static const char __attribute__((__unused__)) *IOMUX_TAG = "IO_MUX";
19+
1720
#define RTCIO_RCC_ATOMIC() PERIPH_RCC_ATOMIC()
1821

1922
static portMUX_TYPE s_io_mux_spinlock = portMUX_INITIALIZER_UNLOCKED;
@@ -52,6 +55,7 @@ esp_err_t io_mux_set_clock_source(soc_module_clk_t clk_src)
5255

5356
void io_mux_enable_lp_io_clock(gpio_num_t gpio_num, bool enable)
5457
{
58+
ESP_RETURN_ON_FALSE(rtc_gpio_is_valid_gpio(gpio_num), ESP_ERR_INVALID_ARG, IOMUX_TAG, "RTCIO number error");
5559
portENTER_CRITICAL(&s_io_mux_spinlock);
5660
if (enable) {
5761
if (s_rtc_io_status.rtc_io_enabled_cnt[gpio_num] == 0) {

components/esp_hw_support/sleep_modes.c

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -983,6 +983,14 @@ static esp_err_t IRAM_ATTR esp_sleep_start(uint32_t pd_flags, esp_sleep_mode_t m
983983
#endif // SOC_PM_SUPPORT_DEEPSLEEP_CHECK_STUB_ONLY
984984
#endif
985985

986+
#if SOC_DCDC_SUPPORTED
987+
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);
988+
if (ldo_increased_us < LDO_POWER_TAKEOVER_PREPARATION_TIME_US) {
989+
esp_rom_delay_us(LDO_POWER_TAKEOVER_PREPARATION_TIME_US - ldo_increased_us);
990+
}
991+
pmu_sleep_shutdown_dcdc();
992+
#endif
993+
986994
// Enter Deep Sleep
987995
#if!ESP_ROM_SUPPORT_DEEP_SLEEP_WAKEUP_STUB || SOC_PM_SUPPORT_DEEPSLEEP_CHECK_STUB_ONLY || !CONFIG_ESP_SYSTEM_ALLOW_RTC_FAST_MEM_AS_HEAP
988996
#if SOC_PMU_SUPPORTED
@@ -1016,27 +1024,20 @@ static esp_err_t IRAM_ATTR esp_sleep_start(uint32_t pd_flags, esp_sleep_mode_t m
10161024
}
10171025
#endif
10181026

1019-
#if SOC_DCDC_SUPPORTED
1020-
#if CONFIG_ESP_SLEEP_KEEP_DCDC_ALWAYS_ON
1021-
if (!deep_sleep) {
1022-
// Keep DCDC always on during light sleep, no need to adjust LDO voltage.
1023-
} else
1024-
#endif
1025-
{
1026-
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);
1027-
if (ldo_increased_us < LDO_POWER_TAKEOVER_PREPARATION_TIME_US) {
1028-
esp_rom_delay_us(LDO_POWER_TAKEOVER_PREPARATION_TIME_US - ldo_increased_us);
1029-
}
1030-
pmu_sleep_shutdown_dcdc();
1031-
}
1032-
#endif
1033-
10341027
#if CONFIG_PM_POWER_DOWN_PERIPHERAL_IN_LIGHT_SLEEP && SOC_PM_MMU_TABLE_RETENTION_WHEN_TOP_PD
10351028
if (pd_flags & PMU_SLEEP_PD_TOP) {
10361029
esp_sleep_mmu_retention(true);
10371030
}
10381031
#endif
10391032

1033+
#if SOC_DCDC_SUPPORTED && !CONFIG_ESP_SLEEP_KEEP_DCDC_ALWAYS_ON
1034+
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);
1035+
if (ldo_increased_us < LDO_POWER_TAKEOVER_PREPARATION_TIME_US) {
1036+
esp_rom_delay_us(LDO_POWER_TAKEOVER_PREPARATION_TIME_US - ldo_increased_us);
1037+
}
1038+
pmu_sleep_shutdown_dcdc();
1039+
#endif
1040+
10401041
#if SOC_PMU_SUPPORTED
10411042
#if SOC_PM_CPU_RETENTION_BY_SW && ESP_SLEEP_POWER_DOWN_CPU
10421043
esp_sleep_execute_event_callbacks(SLEEP_EVENT_HW_GOTO_SLEEP, (void *)0);

0 commit comments

Comments
 (0)