From 28290c8da33fa2edf43b25697d4c0f3ee0ff64b0 Mon Sep 17 00:00:00 2001 From: sibeibei Date: Mon, 24 Feb 2025 19:38:19 +0800 Subject: [PATCH 1/3] fix(wifi):fix modem state rx bcn failed when tbtt update, support modem state for coexist --- .../esp_coex/include/private/esp_coexist_internal.h | 9 +++++++++ components/esp_rom/esp32c2/ld/esp32c2.rom.ld | 2 +- components/esp_rom/esp32c3/ld/esp32c3.rom.ld | 2 +- components/esp_rom/esp32c5/ld/esp32c5.rom.pp.ld | 4 ++-- components/esp_rom/esp32c6/ld/esp32c6.rom.pp.ld | 2 +- components/esp_rom/esp32c61/ld/esp32c61.rom.pp.ld | 6 +++--- components/esp_rom/esp32s3/ld/esp32s3.rom.ld | 2 +- components/esp_wifi/esp32/esp_adapter.c | 10 ++++++++++ components/esp_wifi/esp32c2/esp_adapter.c | 10 ++++++++++ components/esp_wifi/esp32c3/esp_adapter.c | 10 ++++++++++ components/esp_wifi/esp32c5/esp_adapter.c | 10 ++++++++++ components/esp_wifi/esp32c6/esp_adapter.c | 10 ++++++++++ components/esp_wifi/esp32c61/esp_adapter.c | 10 ++++++++++ components/esp_wifi/esp32p4/esp_adapter.c | 6 ++++++ components/esp_wifi/esp32s2/esp_adapter.c | 10 ++++++++++ components/esp_wifi/esp32s3/esp_adapter.c | 10 ++++++++++ .../esp_wifi/include/esp_private/wifi_os_adapter.h | 1 + components/esp_wifi/lib | 2 +- 18 files changed, 106 insertions(+), 10 deletions(-) diff --git a/components/esp_coex/include/private/esp_coexist_internal.h b/components/esp_coex/include/private/esp_coexist_internal.h index 5eac40b708..6e3799487f 100644 --- a/components/esp_coex/include/private/esp_coexist_internal.h +++ b/components/esp_coex/include/private/esp_coexist_internal.h @@ -396,6 +396,15 @@ int coex_schm_flexible_period_set(uint8_t period); uint8_t coex_schm_flexible_period_get(void); #endif +/** + * @brief Get coexistence scheme phase by phase index. + * + * @param phase_idx Coexistence phase index + * + * @return Coexistence scheme phase + */ +void * coex_schm_get_phase_by_idx(int phase_idx); + /** * @brief Check the MD5 values of the coexistence adapter header files in IDF and WiFi library * diff --git a/components/esp_rom/esp32c2/ld/esp32c2.rom.ld b/components/esp_rom/esp32c2/ld/esp32c2.rom.ld index 0079a7af02..a2855e2cf5 100644 --- a/components/esp_rom/esp32c2/ld/esp32c2.rom.ld +++ b/components/esp_rom/esp32c2/ld/esp32c2.rom.ld @@ -529,7 +529,7 @@ pm_enable_active_timer = 0x40001b84; pm_enable_sleep_delay_timer = 0x40001b88; pm_local_tsf_process = 0x40001b8c; pm_set_beacon_filter = 0x40001b90; -pm_is_in_wifi_slice_threshold = 0x40001b94; +/*pm_is_in_wifi_slice_threshold = 0x40001b94;*/ pm_is_waked = 0x40001b98; /*pm_keep_alive = 0x40001b9c;*/ /* pm_on_beacon_rx = 0x40001ba0; */ diff --git a/components/esp_rom/esp32c3/ld/esp32c3.rom.ld b/components/esp_rom/esp32c3/ld/esp32c3.rom.ld index ccfacca75b..5b1804c435 100644 --- a/components/esp_rom/esp32c3/ld/esp32c3.rom.ld +++ b/components/esp_rom/esp32c3/ld/esp32c3.rom.ld @@ -718,7 +718,7 @@ pm_enable_active_timer = 0x40001660; pm_enable_sleep_delay_timer = 0x40001664; pm_local_tsf_process = 0x40001668; pm_set_beacon_filter = 0x4000166c; -pm_is_in_wifi_slice_threshold = 0x40001670; +/*pm_is_in_wifi_slice_threshold = 0x40001670;*/ pm_is_waked = 0x40001674; /*pm_keep_alive = 0x40001678;*/ /* pm_on_beacon_rx = 0x4000167c; */ diff --git a/components/esp_rom/esp32c5/ld/esp32c5.rom.pp.ld b/components/esp_rom/esp32c5/ld/esp32c5.rom.pp.ld index 9030c954eb..cba31c7178 100644 --- a/components/esp_rom/esp32c5/ld/esp32c5.rom.pp.ld +++ b/components/esp_rom/esp32c5/ld/esp32c5.rom.pp.ld @@ -116,7 +116,7 @@ pm_mac_sleep = 0x40000d5c; pm_enable_sleep_delay_timer = 0x40000d64; pm_local_tsf_process = 0x40000d68; pm_set_beacon_filter = 0x40000d6c; -pm_is_in_wifi_slice_threshold = 0x40000d70; +/*pm_is_in_wifi_slice_threshold = 0x40000d70;*/ pm_is_waked = 0x40000d74; /*pm_keep_alive = 0x40000d78;*/ /*pm_on_beacon_rx = 0x40000d7c;*/ @@ -151,7 +151,7 @@ pm_is_twt_start = 0x40000dec; pm_twt_set_target_wdev_time = 0x40000df0; pm_twt_set_target_tsf = 0x40000df4; pm_enable_twt_keep_alive_timer = 0x40000df8; -pm_mac_try_enable_modem_state = 0x40000dfc; +/*pm_mac_try_enable_modem_state = 0x40000dfc;*/ pm_beacon_monitor_tbtt_timeout_process = 0x40000e00; /*pm_update_next_tbtt = 0x40000e04;*/ pm_twt_disallow_tx = 0x40000e08; diff --git a/components/esp_rom/esp32c6/ld/esp32c6.rom.pp.ld b/components/esp_rom/esp32c6/ld/esp32c6.rom.pp.ld index 43090c9bf3..7ff2770e50 100644 --- a/components/esp_rom/esp32c6/ld/esp32c6.rom.pp.ld +++ b/components/esp_rom/esp32c6/ld/esp32c6.rom.pp.ld @@ -66,7 +66,7 @@ pm_mac_sleep = 0x40000c84; pm_enable_sleep_delay_timer = 0x40000c8c; pm_local_tsf_process = 0x40000c90; //pm_set_beacon_filter = 0x40000c94; -pm_is_in_wifi_slice_threshold = 0x40000c98; +/*pm_is_in_wifi_slice_threshold = 0x40000c98;*/ pm_is_waked = 0x40000c9c; //pm_keep_alive = 0x40000ca0; /* pm_on_beacon_rx = 0x40000ca4; */ diff --git a/components/esp_rom/esp32c61/ld/esp32c61.rom.pp.ld b/components/esp_rom/esp32c61/ld/esp32c61.rom.pp.ld index d23d8cb19f..31ab72872b 100644 --- a/components/esp_rom/esp32c61/ld/esp32c61.rom.pp.ld +++ b/components/esp_rom/esp32c61/ld/esp32c61.rom.pp.ld @@ -120,10 +120,10 @@ pm_mac_sleep = 0x40000cc8; pm_enable_sleep_delay_timer = 0x40000cd0; pm_local_tsf_process = 0x40000cd4; pm_set_beacon_filter = 0x40000cd8; -pm_is_in_wifi_slice_threshold = 0x40000cdc; +/*pm_is_in_wifi_slice_threshold = 0x40000cdc;*/ pm_is_waked = 0x40000ce0; //pm_keep_alive = 0x40000ce4; -pm_on_beacon_rx = 0x40000ce8; +/*pm_on_beacon_rx = 0x40000ce8;*/ pm_on_data_rx = 0x40000cec; pm_on_data_tx = 0x40000cf0; pm_on_tbtt = 0x40000cf4; @@ -155,7 +155,7 @@ pm_is_twt_start = 0x40000d58; pm_twt_set_target_wdev_time = 0x40000d5c; pm_twt_set_target_tsf = 0x40000d60; pm_enable_twt_keep_alive_timer = 0x40000d64; -pm_mac_try_enable_modem_state = 0x40000d68; +/*pm_mac_try_enable_modem_state = 0x40000d68;*/ pm_beacon_monitor_tbtt_timeout_process = 0x40000d6c; pm_update_next_tbtt = 0x40000d70; pm_twt_disallow_tx = 0x40000d74; diff --git a/components/esp_rom/esp32s3/ld/esp32s3.rom.ld b/components/esp_rom/esp32s3/ld/esp32s3.rom.ld index eb786cfaff..c3799fb4cf 100644 --- a/components/esp_rom/esp32s3/ld/esp32s3.rom.ld +++ b/components/esp_rom/esp32s3/ld/esp32s3.rom.ld @@ -972,7 +972,7 @@ pm_enable_active_timer = 0x40005460; pm_enable_sleep_delay_timer = 0x4000546c; pm_local_tsf_process = 0x40005478; pm_set_beacon_filter = 0x40005484; -pm_is_in_wifi_slice_threshold = 0x40005490; +/*pm_is_in_wifi_slice_threshold = 0x40005490;*/ pm_is_waked = 0x4000549c; /*pm_keep_alive = 0x400054a8;*/ /* pm_on_beacon_rx = 0x400054b4; */ diff --git a/components/esp_wifi/esp32/esp_adapter.c b/components/esp_wifi/esp32/esp_adapter.c index 3d69706012..50be0e7eb9 100644 --- a/components/esp_wifi/esp32/esp_adapter.c +++ b/components/esp_wifi/esp32/esp_adapter.c @@ -594,6 +594,15 @@ static uint8_t coex_schm_flexible_period_get_wrapper(void) #endif } +static void * coex_schm_get_phase_by_idx_wrapper(int phase_idx) +{ +#if CONFIG_SW_COEXIST_ENABLE + return coex_schm_get_phase_by_idx(phase_idx); +#else + return NULL; +#endif +} + static void IRAM_ATTR esp_empty_wrapper(void) { @@ -730,5 +739,6 @@ wifi_osi_funcs_t g_wifi_osi_funcs = { ._coex_schm_register_cb = coex_schm_register_cb_wrapper, ._coex_schm_flexible_period_set = coex_schm_flexible_period_set_wrapper, ._coex_schm_flexible_period_get = coex_schm_flexible_period_get_wrapper, + ._coex_schm_get_phase_by_idx = coex_schm_get_phase_by_idx_wrapper, ._magic = ESP_WIFI_OS_ADAPTER_MAGIC, }; diff --git a/components/esp_wifi/esp32c2/esp_adapter.c b/components/esp_wifi/esp32c2/esp_adapter.c index 0ab7a81796..00cbf66040 100644 --- a/components/esp_wifi/esp32c2/esp_adapter.c +++ b/components/esp_wifi/esp32c2/esp_adapter.c @@ -535,6 +535,15 @@ static uint8_t coex_schm_flexible_period_get_wrapper(void) #endif } +static void * coex_schm_get_phase_by_idx_wrapper(int phase_idx) +{ +#if CONFIG_SW_COEXIST_ENABLE + return coex_schm_get_phase_by_idx(phase_idx); +#else + return NULL; +#endif +} + static void IRAM_ATTR esp_empty_wrapper(void) { @@ -670,5 +679,6 @@ wifi_osi_funcs_t g_wifi_osi_funcs = { ._coex_schm_register_cb = coex_schm_register_cb_wrapper, ._coex_schm_flexible_period_set = coex_schm_flexible_period_set_wrapper, ._coex_schm_flexible_period_get = coex_schm_flexible_period_get_wrapper, + ._coex_schm_get_phase_by_idx = coex_schm_get_phase_by_idx_wrapper, ._magic = ESP_WIFI_OS_ADAPTER_MAGIC, }; diff --git a/components/esp_wifi/esp32c3/esp_adapter.c b/components/esp_wifi/esp32c3/esp_adapter.c index 7c72f19c9f..4fc7a1158d 100644 --- a/components/esp_wifi/esp32c3/esp_adapter.c +++ b/components/esp_wifi/esp32c3/esp_adapter.c @@ -552,6 +552,15 @@ static uint8_t coex_schm_flexible_period_get_wrapper(void) #endif } +static void * coex_schm_get_phase_by_idx_wrapper(int phase_idx) +{ +#if CONFIG_SW_COEXIST_ENABLE + return coex_schm_get_phase_by_idx(phase_idx); +#else + return NULL; +#endif +} + static void IRAM_ATTR esp_empty_wrapper(void) { @@ -687,5 +696,6 @@ wifi_osi_funcs_t g_wifi_osi_funcs = { ._coex_schm_register_cb = coex_schm_register_cb_wrapper, ._coex_schm_flexible_period_set = coex_schm_flexible_period_set_wrapper, ._coex_schm_flexible_period_get = coex_schm_flexible_period_get_wrapper, + ._coex_schm_get_phase_by_idx = coex_schm_get_phase_by_idx_wrapper, ._magic = ESP_WIFI_OS_ADAPTER_MAGIC, }; diff --git a/components/esp_wifi/esp32c5/esp_adapter.c b/components/esp_wifi/esp32c5/esp_adapter.c index ad999cbb2f..c3264c6e1e 100644 --- a/components/esp_wifi/esp32c5/esp_adapter.c +++ b/components/esp_wifi/esp32c5/esp_adapter.c @@ -610,6 +610,15 @@ static uint8_t coex_schm_flexible_period_get_wrapper(void) #endif } +static void * coex_schm_get_phase_by_idx_wrapper(int phase_idx) +{ +#if CONFIG_SW_COEXIST_ENABLE + return coex_schm_get_phase_by_idx(phase_idx); +#else + return NULL; +#endif +} + static void IRAM_ATTR esp_empty_wrapper(void) { @@ -754,5 +763,6 @@ wifi_osi_funcs_t g_wifi_osi_funcs = { ._coex_schm_register_cb = coex_schm_register_cb_wrapper, ._coex_schm_flexible_period_set = coex_schm_flexible_period_set_wrapper, ._coex_schm_flexible_period_get = coex_schm_flexible_period_get_wrapper, + ._coex_schm_get_phase_by_idx = coex_schm_get_phase_by_idx_wrapper, ._magic = ESP_WIFI_OS_ADAPTER_MAGIC, }; diff --git a/components/esp_wifi/esp32c6/esp_adapter.c b/components/esp_wifi/esp32c6/esp_adapter.c index 1cefee5e36..de9f0c7aa3 100644 --- a/components/esp_wifi/esp32c6/esp_adapter.c +++ b/components/esp_wifi/esp32c6/esp_adapter.c @@ -541,6 +541,15 @@ static uint8_t coex_schm_flexible_period_get_wrapper(void) #endif } +static void * coex_schm_get_phase_by_idx_wrapper(int phase_idx) +{ +#if CONFIG_SW_COEXIST_ENABLE + return coex_schm_get_phase_by_idx(phase_idx); +#else + return NULL; +#endif +} + static void IRAM_ATTR esp_empty_wrapper(void) { @@ -692,5 +701,6 @@ wifi_osi_funcs_t g_wifi_osi_funcs = { ._coex_schm_register_cb = coex_schm_register_cb_wrapper, ._coex_schm_flexible_period_set = coex_schm_flexible_period_set_wrapper, ._coex_schm_flexible_period_get = coex_schm_flexible_period_get_wrapper, + ._coex_schm_get_phase_by_idx = coex_schm_get_phase_by_idx_wrapper, ._magic = ESP_WIFI_OS_ADAPTER_MAGIC, }; diff --git a/components/esp_wifi/esp32c61/esp_adapter.c b/components/esp_wifi/esp32c61/esp_adapter.c index 72f6429ef5..14e94d78a0 100644 --- a/components/esp_wifi/esp32c61/esp_adapter.c +++ b/components/esp_wifi/esp32c61/esp_adapter.c @@ -610,6 +610,15 @@ static uint8_t coex_schm_flexible_period_get_wrapper(void) #endif } +static void * coex_schm_get_phase_by_idx_wrapper(int phase_idx) +{ +#if CONFIG_SW_COEXIST_ENABLE + return coex_schm_get_phase_by_idx(phase_idx); +#else + return NULL; +#endif +} + static void IRAM_ATTR esp_empty_wrapper(void) { @@ -754,5 +763,6 @@ wifi_osi_funcs_t g_wifi_osi_funcs = { ._coex_schm_register_cb = coex_schm_register_cb_wrapper, ._coex_schm_flexible_period_set = coex_schm_flexible_period_set_wrapper, ._coex_schm_flexible_period_get = coex_schm_flexible_period_get_wrapper, + ._coex_schm_get_phase_by_idx = coex_schm_get_phase_by_idx_wrapper, ._magic = ESP_WIFI_OS_ADAPTER_MAGIC, }; diff --git a/components/esp_wifi/esp32p4/esp_adapter.c b/components/esp_wifi/esp32p4/esp_adapter.c index 4def952a2c..8843258dfc 100644 --- a/components/esp_wifi/esp32p4/esp_adapter.c +++ b/components/esp_wifi/esp32p4/esp_adapter.c @@ -554,6 +554,11 @@ static uint8_t coex_schm_flexible_period_get_wrapper(void) return 1; } +static void * coex_schm_get_phase_by_idx_wrapper(int phase_idx) +{ + return NULL; +} + static void IRAM_ATTR esp_empty_wrapper(void) { @@ -810,5 +815,6 @@ wifi_osi_funcs_t g_wifi_osi_funcs = { ._coex_schm_register_cb = coex_schm_register_cb_wrapper, ._coex_schm_flexible_period_set = coex_schm_flexible_period_set_wrapper, ._coex_schm_flexible_period_get = coex_schm_flexible_period_get_wrapper, + ._coex_schm_get_phase_by_idx = coex_schm_get_phase_by_idx_wrapper, ._magic = ESP_WIFI_OS_ADAPTER_MAGIC, }; diff --git a/components/esp_wifi/esp32s2/esp_adapter.c b/components/esp_wifi/esp32s2/esp_adapter.c index 725a553dba..9ff54c3ef0 100644 --- a/components/esp_wifi/esp32s2/esp_adapter.c +++ b/components/esp_wifi/esp32s2/esp_adapter.c @@ -589,6 +589,15 @@ static uint8_t coex_schm_flexible_period_get_wrapper(void) #endif } +static void * coex_schm_get_phase_by_idx_wrapper(int phase_idx) +{ +#if CONFIG_SW_COEXIST_ENABLE + return coex_schm_get_phase_by_idx(phase_idx); +#else + return NULL; +#endif +} + static void IRAM_ATTR esp_empty_wrapper(void) { @@ -724,5 +733,6 @@ wifi_osi_funcs_t g_wifi_osi_funcs = { ._coex_schm_register_cb = coex_schm_register_cb_wrapper, ._coex_schm_flexible_period_set = coex_schm_flexible_period_set_wrapper, ._coex_schm_flexible_period_get = coex_schm_flexible_period_get_wrapper, + ._coex_schm_get_phase_by_idx = coex_schm_get_phase_by_idx_wrapper, ._magic = ESP_WIFI_OS_ADAPTER_MAGIC, }; diff --git a/components/esp_wifi/esp32s3/esp_adapter.c b/components/esp_wifi/esp32s3/esp_adapter.c index 1e00fbbedb..40db5be231 100644 --- a/components/esp_wifi/esp32s3/esp_adapter.c +++ b/components/esp_wifi/esp32s3/esp_adapter.c @@ -606,6 +606,15 @@ static uint8_t coex_schm_flexible_period_get_wrapper(void) #endif } +static void * coex_schm_get_phase_by_idx_wrapper(int phase_idx) +{ +#if CONFIG_SW_COEXIST_ENABLE + return coex_schm_get_phase_by_idx(phase_idx); +#else + return NULL; +#endif +} + static void IRAM_ATTR esp_empty_wrapper(void) { @@ -741,5 +750,6 @@ wifi_osi_funcs_t g_wifi_osi_funcs = { ._coex_schm_register_cb = coex_schm_register_cb_wrapper, ._coex_schm_flexible_period_set = coex_schm_flexible_period_set_wrapper, ._coex_schm_flexible_period_get = coex_schm_flexible_period_get_wrapper, + ._coex_schm_get_phase_by_idx = coex_schm_get_phase_by_idx_wrapper, ._magic = ESP_WIFI_OS_ADAPTER_MAGIC, }; diff --git a/components/esp_wifi/include/esp_private/wifi_os_adapter.h b/components/esp_wifi/include/esp_private/wifi_os_adapter.h index 1e45e91736..ad06dce03f 100644 --- a/components/esp_wifi/include/esp_private/wifi_os_adapter.h +++ b/components/esp_wifi/include/esp_private/wifi_os_adapter.h @@ -155,6 +155,7 @@ typedef struct wifi_osi_funcs_t { #endif int (*_coex_schm_flexible_period_set)(uint8_t); uint8_t (*_coex_schm_flexible_period_get)(void); + void * (*_coex_schm_get_phase_by_idx)(int); int32_t _magic; } wifi_osi_funcs_t; diff --git a/components/esp_wifi/lib b/components/esp_wifi/lib index d152ee7b81..58ebdbff17 160000 --- a/components/esp_wifi/lib +++ b/components/esp_wifi/lib @@ -1 +1 @@ -Subproject commit d152ee7b81ac7073c5dce0d2a44bfbe4aa9dd2ae +Subproject commit 58ebdbff170aaf10e2c8d7dc6759c91378fd93de From 059c50e8c8778e3ee89dce7a94279e61fd60a684 Mon Sep 17 00:00:00 2001 From: Li Shuai Date: Tue, 1 Apr 2025 19:16:17 +0800 Subject: [PATCH 2/3] change(esp_hw_support): add interface to calculate slow clock period by clock frequency --- components/esp_hw_support/port/esp32/include/soc/rtc.h | 8 ++++++++ components/esp_hw_support/port/esp32/rtc_time.c | 2 ++ components/esp_hw_support/port/esp32c2/include/soc/rtc.h | 8 ++++++++ components/esp_hw_support/port/esp32c2/rtc_time.c | 2 ++ components/esp_hw_support/port/esp32c3/include/soc/rtc.h | 8 ++++++++ components/esp_hw_support/port/esp32c3/rtc_time.c | 2 ++ components/esp_hw_support/port/esp32c5/include/soc/rtc.h | 8 ++++++++ components/esp_hw_support/port/esp32c5/rtc_time.c | 2 ++ components/esp_hw_support/port/esp32c6/include/soc/rtc.h | 8 ++++++++ components/esp_hw_support/port/esp32c6/rtc_time.c | 2 ++ components/esp_hw_support/port/esp32c61/include/soc/rtc.h | 8 ++++++++ components/esp_hw_support/port/esp32c61/rtc_time.c | 2 ++ components/esp_hw_support/port/esp32h2/include/soc/rtc.h | 8 ++++++++ components/esp_hw_support/port/esp32h2/rtc_time.c | 2 ++ components/esp_hw_support/port/esp32h21/include/soc/rtc.h | 8 ++++++++ components/esp_hw_support/port/esp32h21/rtc_time.c | 2 ++ components/esp_hw_support/port/esp32h4/include/soc/rtc.h | 8 ++++++++ components/esp_hw_support/port/esp32h4/rtc_time.c | 2 ++ components/esp_hw_support/port/esp32p4/include/soc/rtc.h | 8 ++++++++ components/esp_hw_support/port/esp32p4/rtc_time.c | 2 ++ components/esp_hw_support/port/esp32s2/include/soc/rtc.h | 8 ++++++++ components/esp_hw_support/port/esp32s2/rtc_time.c | 2 ++ components/esp_hw_support/port/esp32s3/include/soc/rtc.h | 8 ++++++++ components/esp_hw_support/port/esp32s3/rtc_time.c | 2 ++ 24 files changed, 120 insertions(+) diff --git a/components/esp_hw_support/port/esp32/include/soc/rtc.h b/components/esp_hw_support/port/esp32/include/soc/rtc.h index f9548249d5..dc7b5beb1f 100644 --- a/components/esp_hw_support/port/esp32/include/soc/rtc.h +++ b/components/esp_hw_support/port/esp32/include/soc/rtc.h @@ -476,6 +476,14 @@ bool rtc_dig_8m_enabled(void); */ uint32_t rtc_clk_freq_cal(uint32_t cal_val); +/** + * @brief Calculate the slow clock period value by slow clock frequency + * + * @param freq_hz Frequency of the slow clock in Hz + * @return Fixed point value of slow clock period in microseconds + */ +uint32_t rtc_clk_freq_to_period(uint32_t freq_hz); + /** * @brief sleep configuration for rtc_sleep_init function */ diff --git a/components/esp_hw_support/port/esp32/rtc_time.c b/components/esp_hw_support/port/esp32/rtc_time.c index 447c109ec8..03695fc93c 100644 --- a/components/esp_hw_support/port/esp32/rtc_time.c +++ b/components/esp_hw_support/port/esp32/rtc_time.c @@ -191,6 +191,8 @@ uint32_t rtc_clk_freq_cal(uint32_t cal_val) return 1000000ULL * (1 << RTC_CLK_CAL_FRACT) / cal_val; } +uint32_t rtc_clk_freq_to_period(uint32_t) __attribute__((alias("rtc_clk_freq_cal"))); + /// @brief if the calibration is used, we need to enable the timer group0 first __attribute__((constructor)) static void enable_timer_group0_for_calibration(void) diff --git a/components/esp_hw_support/port/esp32c2/include/soc/rtc.h b/components/esp_hw_support/port/esp32c2/include/soc/rtc.h index d1be8f7944..bf2407a75f 100644 --- a/components/esp_hw_support/port/esp32c2/include/soc/rtc.h +++ b/components/esp_hw_support/port/esp32c2/include/soc/rtc.h @@ -503,6 +503,14 @@ bool rtc_dig_8m_enabled(void); */ uint32_t rtc_clk_freq_cal(uint32_t cal_val); +/** + * @brief Calculate the slow clock period value by slow clock frequency + * + * @param freq_hz Frequency of the slow clock in Hz + * @return Fixed point value of slow clock period in microseconds + */ +uint32_t rtc_clk_freq_to_period(uint32_t freq_hz); + /** * @brief Power down flags for rtc_sleep_pd function */ diff --git a/components/esp_hw_support/port/esp32c2/rtc_time.c b/components/esp_hw_support/port/esp32c2/rtc_time.c index 5c7470dad4..d724df17a1 100644 --- a/components/esp_hw_support/port/esp32c2/rtc_time.c +++ b/components/esp_hw_support/port/esp32c2/rtc_time.c @@ -191,6 +191,8 @@ uint32_t rtc_clk_freq_cal(uint32_t cal_val) return 1000000ULL * (1 << RTC_CLK_CAL_FRACT) / cal_val; } +uint32_t rtc_clk_freq_to_period(uint32_t) __attribute__((alias("rtc_clk_freq_cal"))); + /// @brief if the calibration is used, we need to enable the timer group0 first __attribute__((constructor)) static void enable_timer_group0_for_calibration(void) diff --git a/components/esp_hw_support/port/esp32c3/include/soc/rtc.h b/components/esp_hw_support/port/esp32c3/include/soc/rtc.h index 6af1ece0ab..a810371ec3 100644 --- a/components/esp_hw_support/port/esp32c3/include/soc/rtc.h +++ b/components/esp_hw_support/port/esp32c3/include/soc/rtc.h @@ -531,6 +531,14 @@ bool rtc_dig_8m_enabled(void); */ uint32_t rtc_clk_freq_cal(uint32_t cal_val); +/** + * @brief Calculate the slow clock period value by slow clock frequency + * + * @param freq_hz Frequency of the slow clock in Hz + * @return Fixed point value of slow clock period in microseconds + */ +uint32_t rtc_clk_freq_to_period(uint32_t freq_hz); + /** * @brief Power down flags for rtc_sleep_pd function */ diff --git a/components/esp_hw_support/port/esp32c3/rtc_time.c b/components/esp_hw_support/port/esp32c3/rtc_time.c index bf1aa97259..783aa93ffb 100644 --- a/components/esp_hw_support/port/esp32c3/rtc_time.c +++ b/components/esp_hw_support/port/esp32c3/rtc_time.c @@ -194,6 +194,8 @@ uint32_t rtc_clk_freq_cal(uint32_t cal_val) return 1000000ULL * (1 << RTC_CLK_CAL_FRACT) / cal_val; } +uint32_t rtc_clk_freq_to_period(uint32_t) __attribute__((alias("rtc_clk_freq_cal"))); + /// @brief if the calibration is used, we need to enable the timer group0 first __attribute__((constructor)) static void enable_timer_group0_for_calibration(void) diff --git a/components/esp_hw_support/port/esp32c5/include/soc/rtc.h b/components/esp_hw_support/port/esp32c5/include/soc/rtc.h index a11d201f20..20daadd268 100644 --- a/components/esp_hw_support/port/esp32c5/include/soc/rtc.h +++ b/components/esp_hw_support/port/esp32c5/include/soc/rtc.h @@ -411,6 +411,14 @@ bool rtc_dig_8m_enabled(void); */ uint32_t rtc_clk_freq_cal(uint32_t cal_val); +/** + * @brief Calculate the slow clock period value by slow clock frequency + * + * @param freq_hz Frequency of the slow clock in Hz + * @return Fixed point value of slow clock period in microseconds + */ +uint32_t rtc_clk_freq_to_period(uint32_t freq_hz); + #ifdef __cplusplus } #endif diff --git a/components/esp_hw_support/port/esp32c5/rtc_time.c b/components/esp_hw_support/port/esp32c5/rtc_time.c index 4dedda4a85..cb1b4ee6be 100644 --- a/components/esp_hw_support/port/esp32c5/rtc_time.c +++ b/components/esp_hw_support/port/esp32c5/rtc_time.c @@ -196,6 +196,8 @@ uint32_t rtc_clk_freq_cal(uint32_t cal_val) return 1000000ULL * (1 << RTC_CLK_CAL_FRACT) / cal_val; } +uint32_t rtc_clk_freq_to_period(uint32_t) __attribute__((alias("rtc_clk_freq_cal"))); + /// @brief if the calibration is used, we need to enable the timer group0 first __attribute__((constructor)) static void enable_timer_group0_for_calibration(void) diff --git a/components/esp_hw_support/port/esp32c6/include/soc/rtc.h b/components/esp_hw_support/port/esp32c6/include/soc/rtc.h index ae0a4ea43b..9d203c3b54 100644 --- a/components/esp_hw_support/port/esp32c6/include/soc/rtc.h +++ b/components/esp_hw_support/port/esp32c6/include/soc/rtc.h @@ -442,6 +442,14 @@ bool rtc_dig_8m_enabled(void); */ uint32_t rtc_clk_freq_cal(uint32_t cal_val); +/** + * @brief Calculate the slow clock period value by slow clock frequency + * + * @param freq_hz Frequency of the slow clock in Hz + * @return Fixed point value of slow clock period in microseconds + */ +uint32_t rtc_clk_freq_to_period(uint32_t freq_hz); + // -------------------------- CLOCK TREE DEFS ALIAS ---------------------------- // **WARNING**: The following are only for backwards compatibility. diff --git a/components/esp_hw_support/port/esp32c6/rtc_time.c b/components/esp_hw_support/port/esp32c6/rtc_time.c index ccd94fc1dd..5eefebca88 100644 --- a/components/esp_hw_support/port/esp32c6/rtc_time.c +++ b/components/esp_hw_support/port/esp32c6/rtc_time.c @@ -271,6 +271,8 @@ uint32_t rtc_clk_freq_cal(uint32_t cal_val) return 1000000ULL * (1 << RTC_CLK_CAL_FRACT) / cal_val; } +uint32_t rtc_clk_freq_to_period(uint32_t) __attribute__((alias("rtc_clk_freq_cal"))); + /// @brief if the calibration is used, we need to enable the timer group0 first __attribute__((constructor)) static void enable_timer_group0_for_calibration(void) diff --git a/components/esp_hw_support/port/esp32c61/include/soc/rtc.h b/components/esp_hw_support/port/esp32c61/include/soc/rtc.h index b041327339..374c3b4a94 100644 --- a/components/esp_hw_support/port/esp32c61/include/soc/rtc.h +++ b/components/esp_hw_support/port/esp32c61/include/soc/rtc.h @@ -411,6 +411,14 @@ bool rtc_dig_8m_enabled(void); */ uint32_t rtc_clk_freq_cal(uint32_t cal_val); +/** + * @brief Calculate the slow clock period value by slow clock frequency + * + * @param freq_hz Frequency of the slow clock in Hz + * @return Fixed point value of slow clock period in microseconds + */ +uint32_t rtc_clk_freq_to_period(uint32_t freq_hz); + #ifdef __cplusplus } #endif diff --git a/components/esp_hw_support/port/esp32c61/rtc_time.c b/components/esp_hw_support/port/esp32c61/rtc_time.c index ddc592e4e5..4181353442 100644 --- a/components/esp_hw_support/port/esp32c61/rtc_time.c +++ b/components/esp_hw_support/port/esp32c61/rtc_time.c @@ -196,6 +196,8 @@ uint32_t rtc_clk_freq_cal(uint32_t cal_val) return 1000000ULL * (1 << RTC_CLK_CAL_FRACT) / cal_val; } +uint32_t rtc_clk_freq_to_period(uint32_t) __attribute__((alias("rtc_clk_freq_cal"))); + /// @brief if the calibration is used, we need to enable the timer group0 first __attribute__((constructor)) static void enable_timer_group0_for_calibration(void) diff --git a/components/esp_hw_support/port/esp32h2/include/soc/rtc.h b/components/esp_hw_support/port/esp32h2/include/soc/rtc.h index 9934431037..5b1971e831 100644 --- a/components/esp_hw_support/port/esp32h2/include/soc/rtc.h +++ b/components/esp_hw_support/port/esp32h2/include/soc/rtc.h @@ -440,6 +440,14 @@ bool rtc_dig_8m_enabled(void); */ uint32_t rtc_clk_freq_cal(uint32_t cal_val); +/** + * @brief Calculate the slow clock period value by slow clock frequency + * + * @param freq_hz Frequency of the slow clock in Hz + * @return Fixed point value of slow clock period in microseconds + */ +uint32_t rtc_clk_freq_to_period(uint32_t freq_hz); + // -------------------------- CLOCK TREE DEFS ALIAS ---------------------------- // **WARNING**: The following are only for backwards compatibility. // Please use the declarations in soc/clk_tree_defs.h instead. diff --git a/components/esp_hw_support/port/esp32h2/rtc_time.c b/components/esp_hw_support/port/esp32h2/rtc_time.c index 49cc0c5956..47836cb3d8 100644 --- a/components/esp_hw_support/port/esp32h2/rtc_time.c +++ b/components/esp_hw_support/port/esp32h2/rtc_time.c @@ -271,6 +271,8 @@ uint32_t rtc_clk_freq_cal(uint32_t cal_val) return 1000000ULL * (1 << RTC_CLK_CAL_FRACT) / cal_val; } +uint32_t rtc_clk_freq_to_period(uint32_t) __attribute__((alias("rtc_clk_freq_cal"))); + /// @brief if the calibration is used, we need to enable the timer group0 first __attribute__((constructor)) static void enable_timer_group0_for_calibration(void) diff --git a/components/esp_hw_support/port/esp32h21/include/soc/rtc.h b/components/esp_hw_support/port/esp32h21/include/soc/rtc.h index 51f3514652..6fa0d4d65e 100644 --- a/components/esp_hw_support/port/esp32h21/include/soc/rtc.h +++ b/components/esp_hw_support/port/esp32h21/include/soc/rtc.h @@ -439,6 +439,14 @@ bool rtc_dig_8m_enabled(void); */ uint32_t rtc_clk_freq_cal(uint32_t cal_val); +/** + * @brief Calculate the slow clock period value by slow clock frequency + * + * @param freq_hz Frequency of the slow clock in Hz + * @return Fixed point value of slow clock period in microseconds + */ +uint32_t rtc_clk_freq_to_period(uint32_t freq_hz); + // -------------------------- CLOCK TREE DEFS ALIAS ---------------------------- // **WARNING**: The following are only for backwards compatibility. // Please use the declarations in soc/clk_tree_defs.h instead. diff --git a/components/esp_hw_support/port/esp32h21/rtc_time.c b/components/esp_hw_support/port/esp32h21/rtc_time.c index f71ff9e6d7..e2b9588d30 100644 --- a/components/esp_hw_support/port/esp32h21/rtc_time.c +++ b/components/esp_hw_support/port/esp32h21/rtc_time.c @@ -274,6 +274,8 @@ uint32_t rtc_clk_freq_cal(uint32_t cal_val) return 1000000ULL * (1 << RTC_CLK_CAL_FRACT) / cal_val; } +uint32_t rtc_clk_freq_to_period(uint32_t) __attribute__((alias("rtc_clk_freq_cal"))); + /// @brief if the calibration is used, we need to enable the timer group0 first __attribute__((constructor)) static void enable_timer_group0_for_calibration(void) diff --git a/components/esp_hw_support/port/esp32h4/include/soc/rtc.h b/components/esp_hw_support/port/esp32h4/include/soc/rtc.h index f5f47a2aa8..7639f84dbe 100644 --- a/components/esp_hw_support/port/esp32h4/include/soc/rtc.h +++ b/components/esp_hw_support/port/esp32h4/include/soc/rtc.h @@ -443,6 +443,14 @@ bool rtc_dig_8m_enabled(void); */ uint32_t rtc_clk_freq_cal(uint32_t cal_val); +/** + * @brief Calculate the slow clock period value by slow clock frequency + * + * @param freq_hz Frequency of the slow clock in Hz + * @return Fixed point value of slow clock period in microseconds + */ +uint32_t rtc_clk_freq_to_period(uint32_t freq_hz); + #ifdef __cplusplus } #endif diff --git a/components/esp_hw_support/port/esp32h4/rtc_time.c b/components/esp_hw_support/port/esp32h4/rtc_time.c index df85a59136..f36b58d847 100644 --- a/components/esp_hw_support/port/esp32h4/rtc_time.c +++ b/components/esp_hw_support/port/esp32h4/rtc_time.c @@ -262,6 +262,8 @@ uint32_t rtc_clk_freq_cal(uint32_t cal_val) return 1000000ULL * (1 << RTC_CLK_CAL_FRACT) / cal_val; } +uint32_t rtc_clk_freq_to_period(uint32_t) __attribute__((alias("rtc_clk_freq_cal"))); + /// @brief if the calibration is used, we need to enable the timer group0 first __attribute__((constructor)) static void enable_timer_group0_for_calibration(void) diff --git a/components/esp_hw_support/port/esp32p4/include/soc/rtc.h b/components/esp_hw_support/port/esp32p4/include/soc/rtc.h index 43acaa253f..7c627a03bd 100644 --- a/components/esp_hw_support/port/esp32p4/include/soc/rtc.h +++ b/components/esp_hw_support/port/esp32p4/include/soc/rtc.h @@ -460,6 +460,14 @@ bool rtc_dig_8m_enabled(void); */ uint32_t rtc_clk_freq_cal(uint32_t cal_val); +/** + * @brief Calculate the slow clock period value by slow clock frequency + * + * @param freq_hz Frequency of the slow clock in Hz + * @return Fixed point value of slow clock period in microseconds + */ +uint32_t rtc_clk_freq_to_period(uint32_t freq_hz); + /** * @brief Enable or disable APLL * diff --git a/components/esp_hw_support/port/esp32p4/rtc_time.c b/components/esp_hw_support/port/esp32p4/rtc_time.c index 6aa564e6ff..f9da6db541 100644 --- a/components/esp_hw_support/port/esp32p4/rtc_time.c +++ b/components/esp_hw_support/port/esp32p4/rtc_time.c @@ -222,6 +222,8 @@ uint32_t rtc_clk_freq_cal(uint32_t cal_val) return 1000000ULL * (1 << RTC_CLK_CAL_FRACT) / cal_val; } +uint32_t rtc_clk_freq_to_period(uint32_t) __attribute__((alias("rtc_clk_freq_cal"))); + /// @brief if the calibration is used, we need to enable the timer group0 first __attribute__((constructor)) static void enable_timer_group0_for_calibration(void) diff --git a/components/esp_hw_support/port/esp32s2/include/soc/rtc.h b/components/esp_hw_support/port/esp32s2/include/soc/rtc.h index cf9fb7c3de..1df74c1959 100644 --- a/components/esp_hw_support/port/esp32s2/include/soc/rtc.h +++ b/components/esp_hw_support/port/esp32s2/include/soc/rtc.h @@ -564,6 +564,14 @@ bool rtc_dig_8m_enabled(void); */ uint32_t rtc_clk_freq_cal(uint32_t cal_val); +/** + * @brief Calculate the slow clock period value by slow clock frequency + * + * @param freq_hz Frequency of the slow clock in Hz + * @return Fixed point value of slow clock period in microseconds + */ +uint32_t rtc_clk_freq_to_period(uint32_t freq_hz); + /** * @brief Power down flags for rtc_sleep_pd function */ diff --git a/components/esp_hw_support/port/esp32s2/rtc_time.c b/components/esp_hw_support/port/esp32s2/rtc_time.c index 76df279092..39e59e56a1 100644 --- a/components/esp_hw_support/port/esp32s2/rtc_time.c +++ b/components/esp_hw_support/port/esp32s2/rtc_time.c @@ -259,6 +259,8 @@ uint32_t rtc_clk_freq_cal(uint32_t cal_val) return 1000000ULL * (1 << RTC_CLK_CAL_FRACT) / cal_val; } +uint32_t rtc_clk_freq_to_period(uint32_t) __attribute__((alias("rtc_clk_freq_cal"))); + /// @brief if the calibration is used, we need to enable the timer group0 first __attribute__((constructor)) static void enable_timer_group0_for_calibration(void) diff --git a/components/esp_hw_support/port/esp32s3/include/soc/rtc.h b/components/esp_hw_support/port/esp32s3/include/soc/rtc.h index 57de5e4716..6a1e9a89c9 100644 --- a/components/esp_hw_support/port/esp32s3/include/soc/rtc.h +++ b/components/esp_hw_support/port/esp32s3/include/soc/rtc.h @@ -542,6 +542,14 @@ bool rtc_dig_8m_enabled(void); */ uint32_t rtc_clk_freq_cal(uint32_t cal_val); +/** + * @brief Calculate the slow clock period value by slow clock frequency + * + * @param freq_hz Frequency of the slow clock in Hz + * @return Fixed point value of slow clock period in microseconds + */ +uint32_t rtc_clk_freq_to_period(uint32_t freq_hz); + /** * @brief Power up flags for rtc_sleep_pd function */ diff --git a/components/esp_hw_support/port/esp32s3/rtc_time.c b/components/esp_hw_support/port/esp32s3/rtc_time.c index 834676a880..4b78096c5c 100644 --- a/components/esp_hw_support/port/esp32s3/rtc_time.c +++ b/components/esp_hw_support/port/esp32s3/rtc_time.c @@ -193,6 +193,8 @@ uint32_t rtc_clk_freq_cal(uint32_t cal_val) return 1000000ULL * (1 << RTC_CLK_CAL_FRACT) / cal_val; } +uint32_t rtc_clk_freq_to_period(uint32_t) __attribute__((alias("rtc_clk_freq_cal"))); + /// @brief if the calibration is used, we need to enable the timer group0 first __attribute__((constructor)) static void enable_timer_group0_for_calibration(void) From 29a470b53058f5c28862fef0fd54363fad434eba Mon Sep 17 00:00:00 2001 From: Li Shuai Date: Tue, 1 Apr 2025 19:24:42 +0800 Subject: [PATCH 3/3] fix(esp_hw_support): fix modem wakeup req always high caused by pmu min slp cycle update --- .../include/esp_private/esp_pmu.h | 7 ++-- .../esp_hw_support/port/esp32c5/pmu_sleep.c | 32 +++++++++++++++---- .../esp_hw_support/port/esp32c6/pmu_sleep.c | 32 +++++++++++++++---- .../esp_hw_support/port/esp32c61/pmu_sleep.c | 32 +++++++++++++++---- .../esp_hw_support/port/esp32h2/pmu_sleep.c | 3 +- .../esp_hw_support/port/esp32h21/pmu_sleep.c | 3 +- .../esp_hw_support/port/esp32p4/pmu_sleep.c | 6 ++-- components/esp_hw_support/sleep_modes.c | 5 +-- .../esp32c5/include/soc/Kconfig.soc_caps.in | 4 +++ components/soc/esp32c5/include/soc/soc_caps.h | 1 + .../esp32c6/include/soc/Kconfig.soc_caps.in | 4 +++ components/soc/esp32c6/include/soc/soc_caps.h | 1 + .../esp32c61/include/soc/Kconfig.soc_caps.in | 4 +++ .../soc/esp32c61/include/soc/soc_caps.h | 1 + 14 files changed, 109 insertions(+), 26 deletions(-) diff --git a/components/esp_hw_support/include/esp_private/esp_pmu.h b/components/esp_hw_support/include/esp_private/esp_pmu.h index 88c2c44b7b..c63b7d1486 100644 --- a/components/esp_hw_support/include/esp_private/esp_pmu.h +++ b/components/esp_hw_support/include/esp_private/esp_pmu.h @@ -12,6 +12,7 @@ #include #include "soc/soc_caps.h" +#include "soc/clk_tree_defs.h" #if SOC_PMU_SUPPORTED #include "hal/pmu_hal.h" @@ -228,12 +229,13 @@ uint32_t pmu_sleep_calculate_hp_hw_wait_time(uint32_t sleep_flags, uint32_t slow * @brief Calculate the hardware time overhead during sleep to compensate for sleep time * * @param sleep_flags flags indicates the power domain that will be powered down and the sleep submode + * @param slowclk_src slow clock source of pmu * @param slowclk_period re-calibrated slow clock period * @param fastclk_period re-calibrated fast clock period * * @return hardware time overhead in us */ -uint32_t pmu_sleep_calculate_hw_wait_time(uint32_t sleep_flags, uint32_t slowclk_period, uint32_t fastclk_period); +uint32_t pmu_sleep_calculate_hw_wait_time(uint32_t sleep_flags, soc_rtc_slow_clk_src_t slowclk_src, uint32_t slowclk_period, uint32_t fastclk_period); /** * @brief Get default sleep configuration @@ -241,6 +243,7 @@ uint32_t pmu_sleep_calculate_hw_wait_time(uint32_t sleep_flags, uint32_t slowclk * @param sleep_flags flags indicates the power domain that will be powered down and the sleep submode * @param clk_flags indicates the clock ICG cell that will be ungated * @param adjustment total software and hardware time overhead + * @param slowclk_src slow clock source of pmu * @param slowclk_period re-calibrated slow clock period in microseconds, * Q13.19 fixed point format * @param fastclk_period re-calibrated fast clock period in microseconds, @@ -249,7 +252,7 @@ uint32_t pmu_sleep_calculate_hw_wait_time(uint32_t sleep_flags, uint32_t slowclk * @return hardware time overhead in us */ -const pmu_sleep_config_t* pmu_sleep_config_default(pmu_sleep_config_t *config, uint32_t sleep_flags, uint32_t clk_flags, uint32_t adjustment, uint32_t slowclk_period, uint32_t fastclk_period, bool dslp); +const pmu_sleep_config_t* pmu_sleep_config_default(pmu_sleep_config_t *config, uint32_t sleep_flags, uint32_t clk_flags, uint32_t adjustment, soc_rtc_slow_clk_src_t slowclk_src, uint32_t slowclk_period, uint32_t fastclk_period, bool dslp); /** * @brief Prepare the chip to enter sleep mode diff --git a/components/esp_hw_support/port/esp32c5/pmu_sleep.c b/components/esp_hw_support/port/esp32c5/pmu_sleep.c index 493e5ff157..bd829132da 100644 --- a/components/esp_hw_support/port/esp32c5/pmu_sleep.c +++ b/components/esp_hw_support/port/esp32c5/pmu_sleep.c @@ -51,7 +51,7 @@ void pmu_sleep_disable_regdma_backup(void) } } -uint32_t pmu_sleep_calculate_hw_wait_time(uint32_t sleep_flags, uint32_t slowclk_period, uint32_t fastclk_period) +uint32_t pmu_sleep_calculate_hw_wait_time(uint32_t sleep_flags, soc_rtc_slow_clk_src_t slowclk_src, uint32_t slowclk_period, uint32_t fastclk_period) { const pmu_sleep_machine_constant_t *mc = (pmu_sleep_machine_constant_t *)PMU_instance()->mc; @@ -98,8 +98,20 @@ uint32_t pmu_sleep_calculate_hw_wait_time(uint32_t sleep_flags, uint32_t slowclk * | wake-up delay | */ #if SOC_PM_SUPPORT_PMU_MODEM_STATE && CONFIG_ESP_WIFI_ENHANCED_LIGHT_SLEEP + int min_slp_time_adjustment_us = 0; +#if SOC_PM_PMU_MIN_SLP_SLOW_CLK_CYCLE_FIXED + if (slowclk_src == SOC_RTC_SLOW_CLK_SRC_RC_SLOW) { + const uint32_t slowclk_period_fixed = rtc_clk_freq_to_period(SOC_CLK_RC_SLOW_FREQ_APPROX); + const int min_slp_cycle_fixed = rtc_time_us_to_slowclk(mc->hp.min_slp_time_us, slowclk_period_fixed); + const int min_slp_cycle_calib = rtc_time_us_to_slowclk(mc->hp.min_slp_time_us, slowclk_period); + const int min_slp_cycle_diff = (min_slp_cycle_calib > min_slp_cycle_fixed) ? \ + (min_slp_cycle_calib - min_slp_cycle_fixed) : (min_slp_cycle_fixed - min_slp_cycle_calib); + const int min_slp_time_diff = rtc_time_slowclk_to_us(min_slp_cycle_diff, slowclk_period_fixed); + min_slp_time_adjustment_us = (min_slp_cycle_calib > min_slp_cycle_fixed) ? min_slp_time_diff : -min_slp_time_diff; + } +#endif const int rf_on_protect_time_us = mc->hp.regdma_rf_on_work_time_us; - const int total_hw_wait_time_us = lp_hw_wait_time_us + hp_hw_wait_time_us + mc->hp.clock_domain_sync_time_us; + const int total_hw_wait_time_us = lp_hw_wait_time_us + hp_hw_wait_time_us + mc->hp.clock_domain_sync_time_us + min_slp_time_adjustment_us; #else const int rf_on_protect_time_us = 0; const int total_hw_wait_time_us = lp_hw_wait_time_us + hp_hw_wait_time_us; @@ -114,13 +126,20 @@ static inline pmu_sleep_param_config_t * pmu_sleep_param_config_default( pmu_sleep_power_config_t *power, /* We'll use the runtime power parameter to determine some hardware parameters */ const uint32_t sleep_flags, const uint32_t adjustment, + soc_rtc_slow_clk_src_t slowclk_src, const uint32_t slowclk_period, const uint32_t fastclk_period ) { const pmu_sleep_machine_constant_t *mc = (pmu_sleep_machine_constant_t *)PMU_instance()->mc; - param->hp_sys.min_slp_slow_clk_cycle = rtc_time_us_to_slowclk(mc->hp.min_slp_time_us, slowclk_period); +#if (SOC_PM_PMU_MIN_SLP_SLOW_CLK_CYCLE_FIXED && SOC_PM_SUPPORT_PMU_MODEM_STATE && CONFIG_ESP_WIFI_ENHANCED_LIGHT_SLEEP) + const uint32_t slowclk_period_fixed = (slowclk_src == SOC_RTC_SLOW_CLK_SRC_RC_SLOW) ? rtc_clk_freq_to_period(SOC_CLK_RC_SLOW_FREQ_APPROX) : slowclk_period; +#else + const uint32_t slowclk_period_fixed = slowclk_period; +#endif + + param->hp_sys.min_slp_slow_clk_cycle = rtc_time_us_to_slowclk(mc->hp.min_slp_time_us, slowclk_period_fixed); param->hp_sys.analog_wait_target_cycle = rtc_time_us_to_fastclk(mc->hp.analog_wait_time_us, fastclk_period); param->hp_sys.digital_power_supply_wait_cycle = rtc_time_us_to_fastclk(mc->hp.power_supply_wait_time_us, fastclk_period); param->hp_sys.digital_power_up_wait_cycle = rtc_time_us_to_fastclk(mc->hp.power_up_wait_time_us, fastclk_period); @@ -128,12 +147,12 @@ static inline pmu_sleep_param_config_t * pmu_sleep_param_config_default( param->hp_sys.isolate_wait_cycle = rtc_time_us_to_fastclk(mc->hp.isolate_wait_time_us, fastclk_period); param->hp_sys.reset_wait_cycle = rtc_time_us_to_fastclk(mc->hp.reset_wait_time_us, fastclk_period); - const int hw_wait_time_us = pmu_sleep_calculate_hw_wait_time(sleep_flags, slowclk_period, fastclk_period); + const int hw_wait_time_us = pmu_sleep_calculate_hw_wait_time(sleep_flags, slowclk_src, slowclk_period, fastclk_period); const int modem_state_skip_time_us = mc->hp.regdma_m2a_work_time_us + mc->hp.system_dfs_up_work_time_us + mc->lp.min_slp_time_us; const int modem_wakeup_wait_time_us = adjustment - hw_wait_time_us + modem_state_skip_time_us + mc->hp.regdma_rf_on_work_time_us; param->hp_sys.modem_wakeup_wait_cycle = rtc_time_us_to_fastclk(modem_wakeup_wait_time_us, fastclk_period); - param->lp_sys.min_slp_slow_clk_cycle = rtc_time_us_to_slowclk(mc->lp.min_slp_time_us, slowclk_period); + param->lp_sys.min_slp_slow_clk_cycle = rtc_time_us_to_slowclk(mc->lp.min_slp_time_us, slowclk_period_fixed); param->lp_sys.analog_wait_target_cycle = rtc_time_us_to_slowclk(mc->lp.analog_wait_time_us, slowclk_period); param->lp_sys.digital_power_supply_wait_cycle = rtc_time_us_to_fastclk(mc->lp.power_supply_wait_time_us, fastclk_period); param->lp_sys.digital_power_up_wait_cycle = rtc_time_us_to_fastclk(mc->lp.power_up_wait_time_us, fastclk_period); @@ -153,6 +172,7 @@ const pmu_sleep_config_t* pmu_sleep_config_default( uint32_t sleep_flags, uint32_t clk_flags, uint32_t adjustment, + soc_rtc_slow_clk_src_t slowclk_src, uint32_t slowclk_period, uint32_t fastclk_period, bool dslp @@ -162,7 +182,7 @@ const pmu_sleep_config_t* pmu_sleep_config_default( config->power = power_default; pmu_sleep_param_config_t param_default = PMU_SLEEP_PARAM_CONFIG_DEFAULT(sleep_flags); - config->param = *pmu_sleep_param_config_default(¶m_default, &power_default, sleep_flags, adjustment, slowclk_period, fastclk_period); + config->param = *pmu_sleep_param_config_default(¶m_default, &power_default, sleep_flags, adjustment, slowclk_src, slowclk_period, fastclk_period); if (dslp) { config->param.lp_sys.analog_wait_target_cycle = rtc_time_us_to_slowclk(PMU_LP_ANALOG_WAIT_TARGET_TIME_DSLP_US, slowclk_period); diff --git a/components/esp_hw_support/port/esp32c6/pmu_sleep.c b/components/esp_hw_support/port/esp32c6/pmu_sleep.c index d767463331..357a6962df 100644 --- a/components/esp_hw_support/port/esp32c6/pmu_sleep.c +++ b/components/esp_hw_support/port/esp32c6/pmu_sleep.c @@ -105,7 +105,7 @@ void pmu_sleep_disable_regdma_backup(void) } } -uint32_t pmu_sleep_calculate_hw_wait_time(uint32_t sleep_flags, uint32_t slowclk_period, uint32_t fastclk_period) +uint32_t pmu_sleep_calculate_hw_wait_time(uint32_t sleep_flags, soc_rtc_slow_clk_src_t slowclk_src, uint32_t slowclk_period, uint32_t fastclk_period) { const pmu_sleep_machine_constant_t *mc = (pmu_sleep_machine_constant_t *)PMU_instance()->mc; @@ -150,8 +150,20 @@ uint32_t pmu_sleep_calculate_hw_wait_time(uint32_t sleep_flags, uint32_t slowclk * | wake-up delay | */ #if SOC_PM_SUPPORT_PMU_MODEM_STATE && CONFIG_ESP_WIFI_ENHANCED_LIGHT_SLEEP + int min_slp_time_adjustment_us = 0; +#if SOC_PM_PMU_MIN_SLP_SLOW_CLK_CYCLE_FIXED + if (slowclk_src == SOC_RTC_SLOW_CLK_SRC_RC_SLOW) { + const uint32_t slowclk_period_fixed = rtc_clk_freq_to_period(SOC_CLK_RC_SLOW_FREQ_APPROX); + const int min_slp_cycle_fixed = rtc_time_us_to_slowclk(mc->hp.min_slp_time_us, slowclk_period_fixed); + const int min_slp_cycle_calib = rtc_time_us_to_slowclk(mc->hp.min_slp_time_us, slowclk_period); + const int min_slp_cycle_diff = (min_slp_cycle_calib > min_slp_cycle_fixed) ? \ + (min_slp_cycle_calib - min_slp_cycle_fixed) : (min_slp_cycle_fixed - min_slp_cycle_calib); + const int min_slp_time_diff = rtc_time_slowclk_to_us(min_slp_cycle_diff, slowclk_period_fixed); + min_slp_time_adjustment_us = (min_slp_cycle_calib > min_slp_cycle_fixed) ? min_slp_time_diff : -min_slp_time_diff; + } +#endif const int rf_on_protect_time_us = mc->hp.regdma_rf_on_work_time_us; - const int total_hw_wait_time_us = lp_hw_wait_time_us + hp_hw_wait_time_us + mc->hp.clock_domain_sync_time_us; + const int total_hw_wait_time_us = lp_hw_wait_time_us + hp_hw_wait_time_us + mc->hp.clock_domain_sync_time_us + min_slp_time_adjustment_us; #else const int rf_on_protect_time_us = 0; const int total_hw_wait_time_us = lp_hw_wait_time_us + hp_hw_wait_time_us; @@ -166,24 +178,31 @@ static inline pmu_sleep_param_config_t * pmu_sleep_param_config_default( pmu_sleep_power_config_t *power, /* We'll use the runtime power parameter to determine some hardware parameters */ const uint32_t sleep_flags, const uint32_t adjustment, + soc_rtc_slow_clk_src_t slowclk_src, const uint32_t slowclk_period, const uint32_t fastclk_period ) { const pmu_sleep_machine_constant_t *mc = (pmu_sleep_machine_constant_t *)PMU_instance()->mc; - param->hp_sys.min_slp_slow_clk_cycle = rtc_time_us_to_slowclk(mc->hp.min_slp_time_us, slowclk_period); +#if (SOC_PM_PMU_MIN_SLP_SLOW_CLK_CYCLE_FIXED && SOC_PM_SUPPORT_PMU_MODEM_STATE && CONFIG_ESP_WIFI_ENHANCED_LIGHT_SLEEP) + const uint32_t slowclk_period_fixed = (slowclk_src == SOC_RTC_SLOW_CLK_SRC_RC_SLOW) ? rtc_clk_freq_to_period(SOC_CLK_RC_SLOW_FREQ_APPROX) : slowclk_period; +#else + const uint32_t slowclk_period_fixed = slowclk_period; +#endif + + param->hp_sys.min_slp_slow_clk_cycle = rtc_time_us_to_slowclk(mc->hp.min_slp_time_us, slowclk_period_fixed); param->hp_sys.analog_wait_target_cycle = rtc_time_us_to_fastclk(mc->hp.analog_wait_time_us, fastclk_period); param->hp_sys.digital_power_supply_wait_cycle = rtc_time_us_to_fastclk(mc->hp.power_supply_wait_time_us, fastclk_period); param->hp_sys.digital_power_up_wait_cycle = rtc_time_us_to_fastclk(mc->hp.power_up_wait_time_us, fastclk_period); param->hp_sys.pll_stable_wait_cycle = rtc_time_us_to_fastclk(mc->hp.pll_wait_stable_time_us, fastclk_period); - const int hw_wait_time_us = pmu_sleep_calculate_hw_wait_time(sleep_flags, slowclk_period, fastclk_period); + const int hw_wait_time_us = pmu_sleep_calculate_hw_wait_time(sleep_flags, slowclk_src, slowclk_period, fastclk_period); const int modem_state_skip_time_us = mc->hp.regdma_m2a_work_time_us + mc->hp.system_dfs_up_work_time_us + mc->lp.min_slp_time_us; const int modem_wakeup_wait_time_us = adjustment - hw_wait_time_us + modem_state_skip_time_us + mc->hp.regdma_rf_on_work_time_us; param->hp_sys.modem_wakeup_wait_cycle = rtc_time_us_to_fastclk(modem_wakeup_wait_time_us, fastclk_period); - param->lp_sys.min_slp_slow_clk_cycle = rtc_time_us_to_slowclk(mc->lp.min_slp_time_us, slowclk_period); + param->lp_sys.min_slp_slow_clk_cycle = rtc_time_us_to_slowclk(mc->lp.min_slp_time_us, slowclk_period_fixed); param->lp_sys.analog_wait_target_cycle = rtc_time_us_to_slowclk(mc->lp.analog_wait_time_us, slowclk_period); param->lp_sys.digital_power_supply_wait_cycle = rtc_time_us_to_fastclk(mc->lp.power_supply_wait_time_us, fastclk_period); param->lp_sys.digital_power_up_wait_cycle = rtc_time_us_to_fastclk(mc->lp.power_up_wait_time_us, fastclk_period); @@ -201,6 +220,7 @@ const pmu_sleep_config_t* pmu_sleep_config_default( uint32_t sleep_flags, uint32_t clk_flags, uint32_t adjustment, + soc_rtc_slow_clk_src_t slowclk_src, uint32_t slowclk_period, uint32_t fastclk_period, bool dslp @@ -210,7 +230,7 @@ const pmu_sleep_config_t* pmu_sleep_config_default( config->power = power_default; pmu_sleep_param_config_t param_default = PMU_SLEEP_PARAM_CONFIG_DEFAULT(sleep_flags); - config->param = *pmu_sleep_param_config_default(¶m_default, &power_default, sleep_flags, adjustment, slowclk_period, fastclk_period); + config->param = *pmu_sleep_param_config_default(¶m_default, &power_default, sleep_flags, adjustment, slowclk_src, slowclk_period, fastclk_period); if (dslp) { config->param.lp_sys.analog_wait_target_cycle = rtc_time_us_to_slowclk(PMU_LP_ANALOG_WAIT_TARGET_TIME_DSLP_US, slowclk_period); diff --git a/components/esp_hw_support/port/esp32c61/pmu_sleep.c b/components/esp_hw_support/port/esp32c61/pmu_sleep.c index cd75f6d3c0..8b9a746952 100644 --- a/components/esp_hw_support/port/esp32c61/pmu_sleep.c +++ b/components/esp_hw_support/port/esp32c61/pmu_sleep.c @@ -51,7 +51,7 @@ void pmu_sleep_disable_regdma_backup(void) } } -uint32_t pmu_sleep_calculate_hw_wait_time(uint32_t sleep_flags, uint32_t slowclk_period, uint32_t fastclk_period) +uint32_t pmu_sleep_calculate_hw_wait_time(uint32_t sleep_flags, soc_rtc_slow_clk_src_t slowclk_src, uint32_t slowclk_period, uint32_t fastclk_period) { const pmu_sleep_machine_constant_t *mc = (pmu_sleep_machine_constant_t *)PMU_instance()->mc; @@ -98,8 +98,20 @@ uint32_t pmu_sleep_calculate_hw_wait_time(uint32_t sleep_flags, uint32_t slowclk * | wake-up delay | */ #if SOC_PM_SUPPORT_PMU_MODEM_STATE && CONFIG_ESP_WIFI_ENHANCED_LIGHT_SLEEP + int min_slp_time_adjustment_us = 0; +#if SOC_PM_PMU_MIN_SLP_SLOW_CLK_CYCLE_FIXED + if (slowclk_src == SOC_RTC_SLOW_CLK_SRC_RC_SLOW) { + const uint32_t slowclk_period_fixed = rtc_clk_freq_to_period(SOC_CLK_RC_SLOW_FREQ_APPROX); + const int min_slp_cycle_fixed = rtc_time_us_to_slowclk(mc->hp.min_slp_time_us, slowclk_period_fixed); + const int min_slp_cycle_calib = rtc_time_us_to_slowclk(mc->hp.min_slp_time_us, slowclk_period); + const int min_slp_cycle_diff = (min_slp_cycle_calib > min_slp_cycle_fixed) ? \ + (min_slp_cycle_calib - min_slp_cycle_fixed) : (min_slp_cycle_fixed - min_slp_cycle_calib); + const int min_slp_time_diff = rtc_time_slowclk_to_us(min_slp_cycle_diff, slowclk_period_fixed); + min_slp_time_adjustment_us = (min_slp_cycle_calib > min_slp_cycle_fixed) ? min_slp_time_diff : -min_slp_time_diff; + } +#endif const int rf_on_protect_time_us = mc->hp.regdma_rf_on_work_time_us; - const int total_hw_wait_time_us = lp_hw_wait_time_us + hp_hw_wait_time_us + mc->hp.clock_domain_sync_time_us; + const int total_hw_wait_time_us = lp_hw_wait_time_us + hp_hw_wait_time_us + mc->hp.clock_domain_sync_time_us + min_slp_time_adjustment_us; #else const int rf_on_protect_time_us = 0; const int total_hw_wait_time_us = lp_hw_wait_time_us + hp_hw_wait_time_us; @@ -114,13 +126,20 @@ static inline pmu_sleep_param_config_t * pmu_sleep_param_config_default( pmu_sleep_power_config_t *power, /* We'll use the runtime power parameter to determine some hardware parameters */ const uint32_t sleep_flags, const uint32_t adjustment, + soc_rtc_slow_clk_src_t slowclk_src, const uint32_t slowclk_period, const uint32_t fastclk_period ) { const pmu_sleep_machine_constant_t *mc = (pmu_sleep_machine_constant_t *)PMU_instance()->mc; - param->hp_sys.min_slp_slow_clk_cycle = rtc_time_us_to_slowclk(mc->hp.min_slp_time_us, slowclk_period); +#if (SOC_PM_PMU_MIN_SLP_SLOW_CLK_CYCLE_FIXED && SOC_PM_SUPPORT_PMU_MODEM_STATE && CONFIG_ESP_WIFI_ENHANCED_LIGHT_SLEEP) + const uint32_t slowclk_period_fixed = (slowclk_src == SOC_RTC_SLOW_CLK_SRC_RC_SLOW) ? rtc_clk_freq_to_period(SOC_CLK_RC_SLOW_FREQ_APPROX) : slowclk_period; +#else + const uint32_t slowclk_period_fixed = slowclk_period; +#endif + + param->hp_sys.min_slp_slow_clk_cycle = rtc_time_us_to_slowclk(mc->hp.min_slp_time_us, slowclk_period_fixed); param->hp_sys.analog_wait_target_cycle = rtc_time_us_to_fastclk(mc->hp.analog_wait_time_us, fastclk_period); param->hp_sys.digital_power_supply_wait_cycle = rtc_time_us_to_fastclk(mc->hp.power_supply_wait_time_us, fastclk_period); param->hp_sys.digital_power_up_wait_cycle = rtc_time_us_to_fastclk(mc->hp.power_up_wait_time_us, fastclk_period); @@ -128,12 +147,12 @@ static inline pmu_sleep_param_config_t * pmu_sleep_param_config_default( param->hp_sys.isolate_wait_cycle = rtc_time_us_to_fastclk(mc->hp.isolate_wait_time_us, fastclk_period); param->hp_sys.reset_wait_cycle = rtc_time_us_to_fastclk(mc->hp.reset_wait_time_us, fastclk_period); - const int hw_wait_time_us = pmu_sleep_calculate_hw_wait_time(sleep_flags, slowclk_period, fastclk_period); + const int hw_wait_time_us = pmu_sleep_calculate_hw_wait_time(sleep_flags, slowclk_src, slowclk_period, fastclk_period); const int modem_state_skip_time_us = mc->hp.regdma_m2a_work_time_us + mc->hp.system_dfs_up_work_time_us + mc->lp.min_slp_time_us; const int modem_wakeup_wait_time_us = adjustment - hw_wait_time_us + modem_state_skip_time_us + mc->hp.regdma_rf_on_work_time_us; param->hp_sys.modem_wakeup_wait_cycle = rtc_time_us_to_fastclk(modem_wakeup_wait_time_us, fastclk_period); - param->lp_sys.min_slp_slow_clk_cycle = rtc_time_us_to_slowclk(mc->lp.min_slp_time_us, slowclk_period); + param->lp_sys.min_slp_slow_clk_cycle = rtc_time_us_to_slowclk(mc->lp.min_slp_time_us, slowclk_period_fixed); param->lp_sys.analog_wait_target_cycle = rtc_time_us_to_slowclk(mc->lp.analog_wait_time_us, slowclk_period); param->lp_sys.digital_power_supply_wait_cycle = rtc_time_us_to_fastclk(mc->lp.power_supply_wait_time_us, fastclk_period); param->lp_sys.digital_power_up_wait_cycle = rtc_time_us_to_fastclk(mc->lp.power_up_wait_time_us, fastclk_period); @@ -153,6 +172,7 @@ const pmu_sleep_config_t* pmu_sleep_config_default( uint32_t sleep_flags, uint32_t clk_flags, uint32_t adjustment, + soc_rtc_slow_clk_src_t slowclk_src, uint32_t slowclk_period, uint32_t fastclk_period, bool dslp @@ -162,7 +182,7 @@ const pmu_sleep_config_t* pmu_sleep_config_default( config->power = power_default; pmu_sleep_param_config_t param_default = PMU_SLEEP_PARAM_CONFIG_DEFAULT(sleep_flags); - config->param = *pmu_sleep_param_config_default(¶m_default, &power_default, sleep_flags, adjustment, slowclk_period, fastclk_period); + config->param = *pmu_sleep_param_config_default(¶m_default, &power_default, sleep_flags, adjustment, slowclk_src, slowclk_period, fastclk_period); if (dslp) { config->param.lp_sys.analog_wait_target_cycle = rtc_time_us_to_slowclk(PMU_LP_ANALOG_WAIT_TARGET_TIME_DSLP_US, slowclk_period); diff --git a/components/esp_hw_support/port/esp32h2/pmu_sleep.c b/components/esp_hw_support/port/esp32h2/pmu_sleep.c index e1acf9896d..b0c6c7d434 100644 --- a/components/esp_hw_support/port/esp32h2/pmu_sleep.c +++ b/components/esp_hw_support/port/esp32h2/pmu_sleep.c @@ -63,7 +63,7 @@ void pmu_sleep_disable_regdma_backup(void) pmu_hal_hp_set_sleep_active_backup_disable(PMU_instance()->hal); } -uint32_t pmu_sleep_calculate_hw_wait_time(uint32_t sleep_flags, uint32_t slowclk_period, uint32_t fastclk_period) +uint32_t pmu_sleep_calculate_hw_wait_time(uint32_t sleep_flags, soc_rtc_slow_clk_src_t slowclk_src, uint32_t slowclk_period, uint32_t fastclk_period) { pmu_sleep_machine_constant_t *mc = (pmu_sleep_machine_constant_t *)PMU_instance()->mc; @@ -133,6 +133,7 @@ const pmu_sleep_config_t* pmu_sleep_config_default( uint32_t sleep_flags, uint32_t clk_flags, uint32_t adjustment, + soc_rtc_slow_clk_src_t slowclk_src, uint32_t slowclk_period, uint32_t fastclk_period, bool dslp diff --git a/components/esp_hw_support/port/esp32h21/pmu_sleep.c b/components/esp_hw_support/port/esp32h21/pmu_sleep.c index 9f5cf7cac5..06987dfe67 100644 --- a/components/esp_hw_support/port/esp32h21/pmu_sleep.c +++ b/components/esp_hw_support/port/esp32h21/pmu_sleep.c @@ -64,7 +64,7 @@ void pmu_sleep_disable_regdma_backup(void) pmu_hal_hp_set_sleep_active_backup_disable(PMU_instance()->hal); } -uint32_t pmu_sleep_calculate_hw_wait_time(uint32_t sleep_flags, uint32_t slowclk_period, uint32_t fastclk_period) +uint32_t pmu_sleep_calculate_hw_wait_time(uint32_t sleep_flags, soc_rtc_slow_clk_src_t slowclk_src, uint32_t slowclk_period, uint32_t fastclk_period) { pmu_sleep_machine_constant_t *mc = (pmu_sleep_machine_constant_t *)PMU_instance()->mc; @@ -133,6 +133,7 @@ const pmu_sleep_config_t* pmu_sleep_config_default( pmu_sleep_config_t *config, uint32_t sleep_flags, uint32_t adjustment, + soc_rtc_slow_clk_src_t slowclk_src, uint32_t slowclk_period, uint32_t fastclk_period, bool dslp diff --git a/components/esp_hw_support/port/esp32p4/pmu_sleep.c b/components/esp_hw_support/port/esp32p4/pmu_sleep.c index bc9eee8647..444117441b 100644 --- a/components/esp_hw_support/port/esp32p4/pmu_sleep.c +++ b/components/esp_hw_support/port/esp32p4/pmu_sleep.c @@ -106,7 +106,7 @@ uint32_t pmu_sleep_calculate_hp_hw_wait_time(uint32_t sleep_flags, uint32_t slow return (uint32_t)hp_hw_wait_time_us; } -uint32_t pmu_sleep_calculate_hw_wait_time(uint32_t sleep_flags, uint32_t slowclk_period, uint32_t fastclk_period) +uint32_t pmu_sleep_calculate_hw_wait_time(uint32_t sleep_flags, soc_rtc_slow_clk_src_t slowclk_src, uint32_t slowclk_period, uint32_t fastclk_period) { const uint32_t lp_hw_wait_time_us = pmu_sleep_calculate_lp_hw_wait_time(sleep_flags, slowclk_period, fastclk_period); const uint32_t hp_hw_wait_time_us = pmu_sleep_calculate_hp_hw_wait_time(sleep_flags, slowclk_period, fastclk_period); @@ -121,6 +121,7 @@ static inline pmu_sleep_param_config_t * pmu_sleep_param_config_default( pmu_sleep_power_config_t *power, /* We'll use the runtime power parameter to determine some hardware parameters */ const uint32_t sleep_flags, const uint32_t adjustment, + soc_rtc_slow_clk_src_t slowclk_src, const uint32_t slowclk_period, const uint32_t fastclk_period ) @@ -151,6 +152,7 @@ const pmu_sleep_config_t* pmu_sleep_config_default( uint32_t sleep_flags, uint32_t clk_flags, uint32_t adjustment, + soc_rtc_slow_clk_src_t slowclk_src, uint32_t slowclk_period, uint32_t fastclk_period, bool dslp @@ -226,7 +228,7 @@ const pmu_sleep_config_t* pmu_sleep_config_default( config->power = power_default; pmu_sleep_param_config_t param_default = PMU_SLEEP_PARAM_CONFIG_DEFAULT(sleep_flags); - config->param = *pmu_sleep_param_config_default(¶m_default, &power_default, sleep_flags, adjustment, slowclk_period, fastclk_period); + config->param = *pmu_sleep_param_config_default(¶m_default, &power_default, sleep_flags, adjustment, slowclk_src, slowclk_period, fastclk_period); return config; } diff --git a/components/esp_hw_support/sleep_modes.c b/components/esp_hw_support/sleep_modes.c index c2dd9cd207..b87190a460 100644 --- a/components/esp_hw_support/sleep_modes.c +++ b/components/esp_hw_support/sleep_modes.c @@ -953,7 +953,8 @@ static esp_err_t IRAM_ATTR esp_sleep_start(uint32_t sleep_flags, uint32_t clk_fl pmu_sleep_config_t config; pmu_sleep_init(pmu_sleep_config_default(&config, sleep_flags, clk_flags, s_config.sleep_time_adjustment, - s_config.rtc_clk_cal_period, s_config.fast_clk_cal_period, deep_sleep), deep_sleep); + rtc_clk_slow_src_get(), s_config.rtc_clk_cal_period, s_config.fast_clk_cal_period, + deep_sleep), deep_sleep); #else rtc_sleep_config_t config; rtc_sleep_get_default_config(sleep_flags, &config); @@ -1409,7 +1410,7 @@ esp_err_t esp_light_sleep_start(void) */ #if SOC_PMU_SUPPORTED int sleep_time_sw_adjustment = LIGHT_SLEEP_TIME_OVERHEAD_US + sleep_time_overhead_in + s_config.sleep_time_overhead_out; - int sleep_time_hw_adjustment = pmu_sleep_calculate_hw_wait_time(sleep_flags, s_config.rtc_clk_cal_period, s_config.fast_clk_cal_period); + int sleep_time_hw_adjustment = pmu_sleep_calculate_hw_wait_time(sleep_flags, rtc_clk_slow_src_get(), s_config.rtc_clk_cal_period, s_config.fast_clk_cal_period); s_config.sleep_time_adjustment = sleep_time_sw_adjustment + sleep_time_hw_adjustment; #if SOC_PM_MMU_TABLE_RETENTION_WHEN_TOP_PD int sleep_time_sw_mmu_table_restore = (sleep_flags & PMU_SLEEP_PD_TOP) ? SLEEP_MMU_TABLE_RETENTION_OVERHEAD_US : 0; diff --git a/components/soc/esp32c5/include/soc/Kconfig.soc_caps.in b/components/soc/esp32c5/include/soc/Kconfig.soc_caps.in index 680fa3f138..c46cc77b28 100644 --- a/components/soc/esp32c5/include/soc/Kconfig.soc_caps.in +++ b/components/soc/esp32c5/include/soc/Kconfig.soc_caps.in @@ -1547,6 +1547,10 @@ config SOC_PM_PAU_REGDMA_UPDATE_CACHE_BEFORE_WAIT_COMPARE bool default y +config SOC_PM_PMU_MIN_SLP_SLOW_CLK_CYCLE_FIXED + bool + default y + config SOC_PM_RETENTION_MODULE_NUM int default 32 diff --git a/components/soc/esp32c5/include/soc/soc_caps.h b/components/soc/esp32c5/include/soc/soc_caps.h index 077b6cdc4a..92b074a257 100644 --- a/components/soc/esp32c5/include/soc/soc_caps.h +++ b/components/soc/esp32c5/include/soc/soc_caps.h @@ -618,6 +618,7 @@ #define SOC_PM_PAU_REGDMA_LINK_IDX_WIFIMAC (4) // The range of values for the link index is [0, SOC_PM_PAU_LINK_NUM) #define SOC_PM_PAU_REGDMA_UPDATE_CACHE_BEFORE_WAIT_COMPARE (1) +#define SOC_PM_PMU_MIN_SLP_SLOW_CLK_CYCLE_FIXED (1) #define SOC_PM_RETENTION_MODULE_NUM (32) diff --git a/components/soc/esp32c6/include/soc/Kconfig.soc_caps.in b/components/soc/esp32c6/include/soc/Kconfig.soc_caps.in index 0e0bf78497..7f03bd86c6 100644 --- a/components/soc/esp32c6/include/soc/Kconfig.soc_caps.in +++ b/components/soc/esp32c6/include/soc/Kconfig.soc_caps.in @@ -1491,6 +1491,10 @@ config SOC_PM_PAU_REGDMA_UPDATE_CACHE_BEFORE_WAIT_COMPARE bool default y +config SOC_PM_PMU_MIN_SLP_SLOW_CLK_CYCLE_FIXED + bool + default y + config SOC_PM_RETENTION_MODULE_NUM int default 32 diff --git a/components/soc/esp32c6/include/soc/soc_caps.h b/components/soc/esp32c6/include/soc/soc_caps.h index 2c87311382..ada0b9eb1f 100644 --- a/components/soc/esp32c6/include/soc/soc_caps.h +++ b/components/soc/esp32c6/include/soc/soc_caps.h @@ -580,6 +580,7 @@ #define SOC_PM_PAU_REGDMA_LINK_WIFIMAC (1) #define SOC_PM_PAU_REGDMA_UPDATE_CACHE_BEFORE_WAIT_COMPARE (1) +#define SOC_PM_PMU_MIN_SLP_SLOW_CLK_CYCLE_FIXED (1) #define SOC_PM_RETENTION_MODULE_NUM (32) diff --git a/components/soc/esp32c61/include/soc/Kconfig.soc_caps.in b/components/soc/esp32c61/include/soc/Kconfig.soc_caps.in index 064a33934d..9548e4ea73 100644 --- a/components/soc/esp32c61/include/soc/Kconfig.soc_caps.in +++ b/components/soc/esp32c61/include/soc/Kconfig.soc_caps.in @@ -1155,6 +1155,10 @@ config SOC_PM_PAU_REGDMA_UPDATE_CACHE_BEFORE_WAIT_COMPARE bool default y +config SOC_PM_PMU_MIN_SLP_SLOW_CLK_CYCLE_FIXED + bool + default y + config SOC_PM_RETENTION_MODULE_NUM int default 32 diff --git a/components/soc/esp32c61/include/soc/soc_caps.h b/components/soc/esp32c61/include/soc/soc_caps.h index 2ccc6def12..2d2b8947b8 100644 --- a/components/soc/esp32c61/include/soc/soc_caps.h +++ b/components/soc/esp32c61/include/soc/soc_caps.h @@ -474,6 +474,7 @@ #define SOC_PM_PAU_REGDMA_LINK_WIFIMAC (1) #define SOC_PM_PAU_REGDMA_UPDATE_CACHE_BEFORE_WAIT_COMPARE (1) +#define SOC_PM_PMU_MIN_SLP_SLOW_CLK_CYCLE_FIXED (1) #define SOC_PM_RETENTION_MODULE_NUM (32)