diff --git a/components/esp_adc/adc_oneshot.c b/components/esp_adc/adc_oneshot.c index 2d622687c0..bca7ba4ab6 100644 --- a/components/esp_adc/adc_oneshot.c +++ b/components/esp_adc/adc_oneshot.c @@ -127,7 +127,7 @@ esp_err_t adc_oneshot_new_unit(const adc_oneshot_unit_init_cfg_t *init_config, a sar_periph_ctrl_adc_oneshot_power_acquire(); } else { #if SOC_LIGHT_SLEEP_SUPPORTED || SOC_DEEP_SLEEP_SUPPORTED - esp_sleep_enable_adc_tsens_monitor(true); + esp_sleep_sub_mode_config(ESP_SLEEP_USE_ADC_TSEN_MONITOR_MODE, true); #endif } @@ -230,7 +230,7 @@ esp_err_t adc_oneshot_del_unit(adc_oneshot_unit_handle_t handle) sar_periph_ctrl_adc_oneshot_power_release(); } else { #if SOC_LIGHT_SLEEP_SUPPORTED || SOC_DEEP_SLEEP_SUPPORTED - esp_sleep_enable_adc_tsens_monitor(false); + esp_sleep_sub_mode_config(ESP_SLEEP_USE_ADC_TSEN_MONITOR_MODE, false); #endif } diff --git a/components/esp_hw_support/sleep_modes.c b/components/esp_hw_support/sleep_modes.c index 62f977532f..989934c98e 100644 --- a/components/esp_hw_support/sleep_modes.c +++ b/components/esp_hw_support/sleep_modes.c @@ -271,7 +271,6 @@ static bool s_light_sleep_wakeup = false; static portMUX_TYPE spinlock_rtc_deep_sleep = portMUX_INITIALIZER_UNLOCKED; static const char *TAG = "sleep"; -static RTC_FAST_ATTR bool s_adc_tsen_enabled = false; static RTC_FAST_ATTR int32_t s_sleep_sub_mode_ref_cnt[ESP_SLEEP_MODE_MAX] = { 0 }; //in this mode, 2uA is saved, but RTC memory can't use at high temperature, and RTCIO can't be used as INPUT. static bool s_ultra_low_enabled = false; @@ -679,7 +678,7 @@ FORCE_INLINE_ATTR void misc_modules_sleep_prepare(uint32_t pd_flags, bool deep_s #if !CONFIG_IDF_TARGET_ESP32P4 // TODO: IDF-7370 - if (!(deep_sleep && s_adc_tsen_enabled)){ + if (!(deep_sleep && (s_sleep_sub_mode_ref_cnt[ESP_SLEEP_USE_ADC_TSEN_MONITOR_MODE] != 0))){ sar_periph_ctrl_power_disable(); } #endif @@ -902,7 +901,7 @@ static esp_err_t IRAM_ATTR esp_sleep_start(uint32_t pd_flags, esp_sleep_mode_t m //Append some flags in addition to power domains uint32_t sleep_flags = pd_flags; - if (s_adc_tsen_enabled) { + if (s_sleep_sub_mode_ref_cnt[ESP_SLEEP_USE_ADC_TESEN_MONITOR_MODE]) { sleep_flags |= RTC_SLEEP_USE_ADC_TESEN_MONITOR; } if (!s_ultra_low_enabled) { diff --git a/components/esp_hw_support/test_apps/rtc_power_modes/main/test_rtc_power.c b/components/esp_hw_support/test_apps/rtc_power_modes/main/test_rtc_power.c index d29d2fa6dc..3e5201a65d 100644 --- a/components/esp_hw_support/test_apps/rtc_power_modes/main/test_rtc_power.c +++ b/components/esp_hw_support/test_apps/rtc_power_modes/main/test_rtc_power.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2021-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -31,7 +31,7 @@ static void test_deepsleep(void) // Deepsleep (with 8MD256 or ADC/TSEN in monitor) TEST_CASE("Power Test: DSLP_8MD256", "[pm]") { - esp_sleep_enable_adc_tsens_monitor(true); + esp_sleep_sub_mode_config(ESP_SLEEP_USE_ADC_TESEN_MONITOR_MODE, true); test_deepsleep(); } @@ -40,7 +40,7 @@ TEST_CASE("Power Test: DSLP_8MD256", "[pm]") // Deepsleep (default) TEST_CASE("Power Test: DSLP_DEFAULT", "[pm]") { - esp_sleep_enable_adc_tsens_monitor(false); //This is the default option. Add this line to avoid the case executing this case directly after the DSLP_8MD256 case. + esp_sleep_sub_mode_config(ESP_SLEEP_USE_ADC_TESEN_MONITOR_MODE, false); //This is the default option. Add this line to avoid the case executing this case directly after the DSLP_8MD256 case. test_deepsleep(); } @@ -48,7 +48,7 @@ TEST_CASE("Power Test: DSLP_DEFAULT", "[pm]") // Deepsleep (ultra-low power) TEST_CASE("Power Test: DSLP_ULTRA_LOW", "[pm]") { - esp_sleep_enable_adc_tsens_monitor(false); //This is the default option. Add this line to avoid the case executing this case directly after the DSLP_8MD256 case. + esp_sleep_sub_mode_config(ESP_SLEEP_USE_ADC_TESEN_MONITOR_MODE, false); //This is the default option. Add this line to avoid the case executing this case directly after the DSLP_8MD256 case. extern void rtc_sleep_enable_ultra_low(bool); rtc_sleep_enable_ultra_low(true); @@ -125,8 +125,7 @@ TEST_CASE("Power Test: LSLP_8MD256", "[pm]") // Lightsleep (with ADC/TSEN in monitor) TEST_CASE("Power Test: LSLP_ADC_TSENS", "[pm]") { - extern void esp_sleep_enable_adc_tsens_monitor(bool); - esp_sleep_enable_adc_tsens_monitor(true); + esp_sleep_sub_mode_config(ESP_SLEEP_USE_ADC_TESEN_MONITOR_MODE, true); test_lightsleep(); } @@ -134,7 +133,7 @@ TEST_CASE("Power Test: LSLP_ADC_TSENS", "[pm]") // Lightsleep (default) TEST_CASE("Power Test: LSLP_DEFAULT", "[pm]") { - esp_sleep_enable_adc_tsens_monitor(false); //This is the default option. Add this line to avoid the case executing this case directly after the DSLP_8MD256 case. + esp_sleep_sub_mode_config(ESP_SLEEP_USE_ADC_TESEN_MONITOR_MODE, false); //This is the default option. Add this line to avoid the case executing this case directly after the DSLP_8MD256 case. test_lightsleep(); }