@@ -51,7 +51,7 @@ void pmu_sleep_disable_regdma_backup(void)
5151 }
5252}
5353
54- uint32_t pmu_sleep_calculate_hw_wait_time (uint32_t sleep_flags , uint32_t slowclk_period , uint32_t fastclk_period )
54+ 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 )
5555{
5656 const pmu_sleep_machine_constant_t * mc = (pmu_sleep_machine_constant_t * )PMU_instance ()-> mc ;
5757
@@ -98,8 +98,20 @@ uint32_t pmu_sleep_calculate_hw_wait_time(uint32_t sleep_flags, uint32_t slowclk
9898 * | wake-up delay |
9999 */
100100#if SOC_PM_SUPPORT_PMU_MODEM_STATE && CONFIG_ESP_WIFI_ENHANCED_LIGHT_SLEEP
101+ int min_slp_time_adjustment_us = 0 ;
102+ #if SOC_PM_PMU_MIN_SLP_SLOW_CLK_CYCLE_FIXED
103+ if (slowclk_src == SOC_RTC_SLOW_CLK_SRC_RC_SLOW ) {
104+ const uint32_t slowclk_period_fixed = rtc_clk_freq_to_period (SOC_CLK_RC_SLOW_FREQ_APPROX );
105+ const int min_slp_cycle_fixed = rtc_time_us_to_slowclk (mc -> hp .min_slp_time_us , slowclk_period_fixed );
106+ const int min_slp_cycle_calib = rtc_time_us_to_slowclk (mc -> hp .min_slp_time_us , slowclk_period );
107+ const int min_slp_cycle_diff = (min_slp_cycle_calib > min_slp_cycle_fixed ) ? \
108+ (min_slp_cycle_calib - min_slp_cycle_fixed ) : (min_slp_cycle_fixed - min_slp_cycle_calib );
109+ const int min_slp_time_diff = rtc_time_slowclk_to_us (min_slp_cycle_diff , slowclk_period_fixed );
110+ min_slp_time_adjustment_us = (min_slp_cycle_calib > min_slp_cycle_fixed ) ? min_slp_time_diff : - min_slp_time_diff ;
111+ }
112+ #endif
101113 const int rf_on_protect_time_us = mc -> hp .regdma_rf_on_work_time_us ;
102- const int total_hw_wait_time_us = lp_hw_wait_time_us + hp_hw_wait_time_us + mc -> hp .clock_domain_sync_time_us ;
114+ 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 ;
103115#else
104116 const int rf_on_protect_time_us = 0 ;
105117 const int total_hw_wait_time_us = lp_hw_wait_time_us + hp_hw_wait_time_us ;
@@ -114,26 +126,33 @@ static inline pmu_sleep_param_config_t * pmu_sleep_param_config_default(
114126 pmu_sleep_power_config_t * power , /* We'll use the runtime power parameter to determine some hardware parameters */
115127 const uint32_t sleep_flags ,
116128 const uint32_t adjustment ,
129+ soc_rtc_slow_clk_src_t slowclk_src ,
117130 const uint32_t slowclk_period ,
118131 const uint32_t fastclk_period
119132 )
120133{
121134 const pmu_sleep_machine_constant_t * mc = (pmu_sleep_machine_constant_t * )PMU_instance ()-> mc ;
122135
123- param -> hp_sys .min_slp_slow_clk_cycle = rtc_time_us_to_slowclk (mc -> hp .min_slp_time_us , slowclk_period );
136+ #if (SOC_PM_PMU_MIN_SLP_SLOW_CLK_CYCLE_FIXED && SOC_PM_SUPPORT_PMU_MODEM_STATE && CONFIG_ESP_WIFI_ENHANCED_LIGHT_SLEEP )
137+ 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 ;
138+ #else
139+ const uint32_t slowclk_period_fixed = slowclk_period ;
140+ #endif
141+
142+ param -> hp_sys .min_slp_slow_clk_cycle = rtc_time_us_to_slowclk (mc -> hp .min_slp_time_us , slowclk_period_fixed );
124143 param -> hp_sys .analog_wait_target_cycle = rtc_time_us_to_fastclk (mc -> hp .analog_wait_time_us , fastclk_period );
125144 param -> hp_sys .digital_power_supply_wait_cycle = rtc_time_us_to_fastclk (mc -> hp .power_supply_wait_time_us , fastclk_period );
126145 param -> hp_sys .digital_power_up_wait_cycle = rtc_time_us_to_fastclk (mc -> hp .power_up_wait_time_us , fastclk_period );
127146 param -> hp_sys .pll_stable_wait_cycle = rtc_time_us_to_fastclk (mc -> hp .pll_wait_stable_time_us , fastclk_period );
128147 param -> hp_sys .isolate_wait_cycle = rtc_time_us_to_fastclk (mc -> hp .isolate_wait_time_us , fastclk_period );
129148 param -> hp_sys .reset_wait_cycle = rtc_time_us_to_fastclk (mc -> hp .reset_wait_time_us , fastclk_period );
130149
131- const int hw_wait_time_us = pmu_sleep_calculate_hw_wait_time (sleep_flags , slowclk_period , fastclk_period );
150+ const int hw_wait_time_us = pmu_sleep_calculate_hw_wait_time (sleep_flags , slowclk_src , slowclk_period , fastclk_period );
132151 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 ;
133152 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 ;
134153 param -> hp_sys .modem_wakeup_wait_cycle = rtc_time_us_to_fastclk (modem_wakeup_wait_time_us , fastclk_period );
135154
136- param -> lp_sys .min_slp_slow_clk_cycle = rtc_time_us_to_slowclk (mc -> lp .min_slp_time_us , slowclk_period );
155+ param -> lp_sys .min_slp_slow_clk_cycle = rtc_time_us_to_slowclk (mc -> lp .min_slp_time_us , slowclk_period_fixed );
137156 param -> lp_sys .analog_wait_target_cycle = rtc_time_us_to_slowclk (mc -> lp .analog_wait_time_us , slowclk_period );
138157 param -> lp_sys .digital_power_supply_wait_cycle = rtc_time_us_to_fastclk (mc -> lp .power_supply_wait_time_us , fastclk_period );
139158 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(
153172 uint32_t sleep_flags ,
154173 uint32_t clk_flags ,
155174 uint32_t adjustment ,
175+ soc_rtc_slow_clk_src_t slowclk_src ,
156176 uint32_t slowclk_period ,
157177 uint32_t fastclk_period ,
158178 bool dslp
@@ -162,7 +182,7 @@ const pmu_sleep_config_t* pmu_sleep_config_default(
162182 config -> power = power_default ;
163183
164184 pmu_sleep_param_config_t param_default = PMU_SLEEP_PARAM_CONFIG_DEFAULT (sleep_flags );
165- config -> param = * pmu_sleep_param_config_default (& param_default , & power_default , sleep_flags , adjustment , slowclk_period , fastclk_period );
185+ config -> param = * pmu_sleep_param_config_default (& param_default , & power_default , sleep_flags , adjustment , slowclk_src , slowclk_period , fastclk_period );
166186
167187 if (dslp ) {
168188 config -> param .lp_sys .analog_wait_target_cycle = rtc_time_us_to_slowclk (PMU_LP_ANALOG_WAIT_TARGET_TIME_DSLP_US , slowclk_period );
0 commit comments