Skip to content

Commit b93ac47

Browse files
author
Jiang Jiang Jian
committed
Merge branch 'bugfix/fix_modem_state_rx_bcn_failed' into 'master'
fix(wifi):fix modem state rx bcn failed when tbtt update, support modem state for coexist Closes WIFI-6538, WIFIBUG-1052, WIFIBUG-128, WIFIBUG-1064, and WIFIBUG-1088 See merge request espressif/esp-idf!37238
2 parents ab36ffa + 29a470b commit b93ac47

File tree

56 files changed

+335
-36
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+335
-36
lines changed

components/esp_coex/include/private/esp_coexist_internal.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,15 @@ int coex_schm_flexible_period_set(uint8_t period);
396396
uint8_t coex_schm_flexible_period_get(void);
397397
#endif
398398

399+
/**
400+
* @brief Get coexistence scheme phase by phase index.
401+
*
402+
* @param phase_idx Coexistence phase index
403+
*
404+
* @return Coexistence scheme phase
405+
*/
406+
void * coex_schm_get_phase_by_idx(int phase_idx);
407+
399408
/**
400409
* @brief Check the MD5 values of the coexistence adapter header files in IDF and WiFi library
401410
*

components/esp_hw_support/include/esp_private/esp_pmu.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <stdlib.h>
1313

1414
#include "soc/soc_caps.h"
15+
#include "soc/clk_tree_defs.h"
1516

1617
#if SOC_PMU_SUPPORTED
1718
#include "hal/pmu_hal.h"
@@ -228,19 +229,21 @@ uint32_t pmu_sleep_calculate_hp_hw_wait_time(uint32_t sleep_flags, uint32_t slow
228229
* @brief Calculate the hardware time overhead during sleep to compensate for sleep time
229230
*
230231
* @param sleep_flags flags indicates the power domain that will be powered down and the sleep submode
232+
* @param slowclk_src slow clock source of pmu
231233
* @param slowclk_period re-calibrated slow clock period
232234
* @param fastclk_period re-calibrated fast clock period
233235
*
234236
* @return hardware time overhead in us
235237
*/
236-
uint32_t pmu_sleep_calculate_hw_wait_time(uint32_t sleep_flags, uint32_t slowclk_period, uint32_t fastclk_period);
238+
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);
237239

238240
/**
239241
* @brief Get default sleep configuration
240242
* @param config pmu_sleep_config instance
241243
* @param sleep_flags flags indicates the power domain that will be powered down and the sleep submode
242244
* @param clk_flags indicates the clock ICG cell that will be ungated
243245
* @param adjustment total software and hardware time overhead
246+
* @param slowclk_src slow clock source of pmu
244247
* @param slowclk_period re-calibrated slow clock period in microseconds,
245248
* Q13.19 fixed point format
246249
* @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
249252
250253
* @return hardware time overhead in us
251254
*/
252-
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);
255+
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);
253256

254257
/**
255258
* @brief Prepare the chip to enter sleep mode

components/esp_hw_support/port/esp32/include/soc/rtc.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,14 @@ bool rtc_dig_8m_enabled(void);
481481
*/
482482
uint32_t rtc_clk_freq_cal(uint32_t cal_val);
483483

484+
/**
485+
* @brief Calculate the slow clock period value by slow clock frequency
486+
*
487+
* @param freq_hz Frequency of the slow clock in Hz
488+
* @return Fixed point value of slow clock period in microseconds
489+
*/
490+
uint32_t rtc_clk_freq_to_period(uint32_t freq_hz);
491+
484492
/**
485493
* @brief sleep configuration for rtc_sleep_init function
486494
*/

components/esp_hw_support/port/esp32/rtc_time.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,8 @@ uint32_t rtc_clk_freq_cal(uint32_t cal_val)
191191
return 1000000ULL * (1 << RTC_CLK_CAL_FRACT) / cal_val;
192192
}
193193

194+
uint32_t rtc_clk_freq_to_period(uint32_t) __attribute__((alias("rtc_clk_freq_cal")));
195+
194196
/// @brief if the calibration is used, we need to enable the timer group0 first
195197
__attribute__((constructor))
196198
static void enable_timer_group0_for_calibration(void)

components/esp_hw_support/port/esp32c2/include/soc/rtc.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,14 @@ bool rtc_dig_8m_enabled(void);
508508
*/
509509
uint32_t rtc_clk_freq_cal(uint32_t cal_val);
510510

511+
/**
512+
* @brief Calculate the slow clock period value by slow clock frequency
513+
*
514+
* @param freq_hz Frequency of the slow clock in Hz
515+
* @return Fixed point value of slow clock period in microseconds
516+
*/
517+
uint32_t rtc_clk_freq_to_period(uint32_t freq_hz);
518+
511519
/**
512520
* @brief Power down flags for rtc_sleep_pd function
513521
*/

components/esp_hw_support/port/esp32c2/rtc_time.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,8 @@ uint32_t rtc_clk_freq_cal(uint32_t cal_val)
191191
return 1000000ULL * (1 << RTC_CLK_CAL_FRACT) / cal_val;
192192
}
193193

194+
uint32_t rtc_clk_freq_to_period(uint32_t) __attribute__((alias("rtc_clk_freq_cal")));
195+
194196
/// @brief if the calibration is used, we need to enable the timer group0 first
195197
__attribute__((constructor))
196198
static void enable_timer_group0_for_calibration(void)

components/esp_hw_support/port/esp32c3/include/soc/rtc.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,14 @@ bool rtc_dig_8m_enabled(void);
536536
*/
537537
uint32_t rtc_clk_freq_cal(uint32_t cal_val);
538538

539+
/**
540+
* @brief Calculate the slow clock period value by slow clock frequency
541+
*
542+
* @param freq_hz Frequency of the slow clock in Hz
543+
* @return Fixed point value of slow clock period in microseconds
544+
*/
545+
uint32_t rtc_clk_freq_to_period(uint32_t freq_hz);
546+
539547
/**
540548
* @brief Power down flags for rtc_sleep_pd function
541549
*/

components/esp_hw_support/port/esp32c3/rtc_time.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,8 @@ uint32_t rtc_clk_freq_cal(uint32_t cal_val)
194194
return 1000000ULL * (1 << RTC_CLK_CAL_FRACT) / cal_val;
195195
}
196196

197+
uint32_t rtc_clk_freq_to_period(uint32_t) __attribute__((alias("rtc_clk_freq_cal")));
198+
197199
/// @brief if the calibration is used, we need to enable the timer group0 first
198200
__attribute__((constructor))
199201
static void enable_timer_group0_for_calibration(void)

components/esp_hw_support/port/esp32c5/include/soc/rtc.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,14 @@ bool rtc_dig_8m_enabled(void);
416416
*/
417417
uint32_t rtc_clk_freq_cal(uint32_t cal_val);
418418

419+
/**
420+
* @brief Calculate the slow clock period value by slow clock frequency
421+
*
422+
* @param freq_hz Frequency of the slow clock in Hz
423+
* @return Fixed point value of slow clock period in microseconds
424+
*/
425+
uint32_t rtc_clk_freq_to_period(uint32_t freq_hz);
426+
419427
#ifdef __cplusplus
420428
}
421429
#endif

components/esp_hw_support/port/esp32c5/pmu_sleep.c

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)