Skip to content

Commit

Permalink
Merge branch 'backport/esp_phy_init_refactor_c3_bt_fix' into 'release…
Browse files Browse the repository at this point in the history
…/v5.1'

Backport: esp phy init refactor c3 bt fix

See merge request espressif/esp-idf!26262
  • Loading branch information
jack0c committed Sep 28, 2023
2 parents 0122d6c + 4c60d48 commit f3ac648
Show file tree
Hide file tree
Showing 35 changed files with 300 additions and 80 deletions.
18 changes: 9 additions & 9 deletions components/bt/controller/esp32/bt.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand Down Expand Up @@ -937,15 +937,15 @@ static void btdm_sleep_enter_phase1_wrapper(uint32_t lpcycles)
static void btdm_sleep_enter_phase2_wrapper(void)
{
if (btdm_controller_get_sleep_mode() == BTDM_MODEM_SLEEP_MODE_ORIG) {
esp_phy_disable();
esp_phy_disable(PHY_MODEM_BT);
#ifdef CONFIG_PM_ENABLE
if (s_pm_lock_acquired) {
esp_pm_lock_release(s_pm_lock);
s_pm_lock_acquired = false;
}
#endif
} else if (btdm_controller_get_sleep_mode() == BTDM_MODEM_SLEEP_MODE_EVED) {
esp_phy_disable();
esp_phy_disable(PHY_MODEM_BT);
// pause bluetooth baseband
periph_module_disable(PERIPH_BT_BASEBAND_MODULE);
}
Expand All @@ -961,15 +961,15 @@ static void btdm_sleep_exit_phase3_wrapper(void)
#endif

if (btdm_controller_get_sleep_mode() == BTDM_MODEM_SLEEP_MODE_ORIG) {
esp_phy_enable();
esp_phy_enable(PHY_MODEM_BT);
btdm_check_and_init_bb();
#ifdef CONFIG_PM_ENABLE
esp_timer_stop(s_btdm_slp_tmr);
#endif
} else if (btdm_controller_get_sleep_mode() == BTDM_MODEM_SLEEP_MODE_EVED) {
// resume bluetooth baseband
periph_module_enable(PERIPH_BT_BASEBAND_MODULE);
esp_phy_enable();
esp_phy_enable(PHY_MODEM_BT);
}
}

Expand Down Expand Up @@ -1641,7 +1641,7 @@ static void bt_shutdown(void)
#else
bt_controller_shutdown(NULL);
#endif
esp_phy_disable();
esp_phy_disable(PHY_MODEM_BT);

return;
}
Expand All @@ -1667,7 +1667,7 @@ esp_err_t esp_bt_controller_enable(esp_bt_mode_t mode)
esp_pm_lock_acquire(s_pm_lock);
#endif

esp_phy_enable();
esp_phy_enable(PHY_MODEM_BT);

#if CONFIG_SW_COEXIST_ENABLE
coex_enable();
Expand All @@ -1685,7 +1685,7 @@ esp_err_t esp_bt_controller_enable(esp_bt_mode_t mode)
#if CONFIG_SW_COEXIST_ENABLE
coex_disable();
#endif
esp_phy_disable();
esp_phy_disable(PHY_MODEM_BT);
#ifdef CONFIG_PM_ENABLE
if (!s_btdm_allow_light_sleep) {
esp_pm_lock_release(s_light_sleep_pm_lock);
Expand Down Expand Up @@ -1725,7 +1725,7 @@ esp_err_t esp_bt_controller_disable(void)
coex_disable();
#endif

esp_phy_disable();
esp_phy_disable(PHY_MODEM_BT);
btdm_controller_status = ESP_BT_CONTROLLER_STATUS_INITED;
esp_unregister_shutdown_handler(bt_shutdown);

Expand Down
12 changes: 6 additions & 6 deletions components/bt/controller/esp32c2/bt.c
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ struct ext_funcs_t ext_funcs_ro = {
._ecc_gen_key_pair = esp_ecc_gen_key_pair,
._ecc_gen_dh_key = esp_ecc_gen_dh_key,
._esp_reset_rpa_moudle = esp_reset_rpa_moudle,
._esp_bt_track_pll_cap = bt_track_pll_cap,
._esp_bt_track_pll_cap = NULL,
.magic = EXT_FUNC_MAGIC_VALUE,
};

Expand Down Expand Up @@ -465,7 +465,7 @@ IRAM_ATTR void controller_sleep_cb(uint32_t enable_tick, void *arg)
r_ble_rtc_wake_up_state_clr();
esp_pm_lock_release(s_pm_lock);
#endif // CONFIG_PM_ENABLE
esp_phy_disable();
esp_phy_disable(PHY_MODEM_BT);
s_ble_active = false;
}

Expand All @@ -474,7 +474,7 @@ IRAM_ATTR void controller_wakeup_cb(void *arg)
if (s_ble_active) {
return;
}
esp_phy_enable();
esp_phy_enable(PHY_MODEM_BT);
// need to check if need to call pm lock here
#ifdef CONFIG_PM_ENABLE
esp_pm_lock_acquire(s_pm_lock);
Expand Down Expand Up @@ -750,7 +750,7 @@ esp_err_t esp_bt_controller_enable(esp_bt_mode_t mode)
esp_pm_lock_acquire(s_pm_lock);
#endif // CONFIG_PM_ENABLE
// init phy
esp_phy_enable();
esp_phy_enable(PHY_MODEM_BT);
s_ble_active = true;
}
// init bb
Expand All @@ -772,7 +772,7 @@ esp_err_t esp_bt_controller_enable(esp_bt_mode_t mode)
coex_disable();
#endif
if (s_ble_active) {
esp_phy_disable();
esp_phy_disable(PHY_MODEM_BT);
#if CONFIG_PM_ENABLE
esp_pm_lock_release(s_pm_lock);
#endif // CONFIG_PM_ENABLE
Expand All @@ -792,7 +792,7 @@ esp_err_t esp_bt_controller_disable(void)
}

if (s_ble_active) {
esp_phy_disable();
esp_phy_disable(PHY_MODEM_BT);
#if CONFIG_PM_ENABLE
esp_pm_lock_release(s_pm_lock);
#endif // CONFIG_PM_ENABLE
Expand Down
14 changes: 9 additions & 5 deletions components/bt/controller/esp32c3/bt.c
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ extern bool btdm_deep_sleep_mem_init(void);
extern void btdm_deep_sleep_mem_deinit(void);
extern void btdm_ble_power_down_dma_copy(bool copy);
extern uint8_t btdm_sleep_clock_sync(void);
extern void sdk_config_extend_set_pll_track(bool enable);

#if CONFIG_MAC_BB_PD
extern void esp_mac_bb_power_down(void);
Expand Down Expand Up @@ -747,7 +748,7 @@ static void btdm_sleep_enter_phase2_wrapper(void)
{
if (btdm_controller_get_sleep_mode() == ESP_BT_SLEEP_MODE_1) {
if (s_lp_stat.phy_enabled) {
esp_phy_disable();
esp_phy_disable(PHY_MODEM_BT);
s_lp_stat.phy_enabled = 0;
} else {
assert(0);
Expand Down Expand Up @@ -776,7 +777,7 @@ static void btdm_sleep_exit_phase3_wrapper(void)

if (btdm_controller_get_sleep_mode() == ESP_BT_SLEEP_MODE_1) {
if (s_lp_stat.phy_enabled == 0) {
esp_phy_enable();
esp_phy_enable(PHY_MODEM_BT);
s_lp_stat.phy_enabled = 1;
}
}
Expand Down Expand Up @@ -1442,7 +1443,7 @@ esp_err_t esp_bt_controller_enable(esp_bt_mode_t mode)
/* Enable PHY when enabling controller to reduce power dissipation after controller init
* Notice the init order: esp_phy_enable() -> bt_bb_v2_init_cmplx() -> coex_pti_v2()
*/
esp_phy_enable();
esp_phy_enable(PHY_MODEM_BT);
s_lp_stat.phy_enabled = 1;

#if CONFIG_SW_COEXIST_ENABLE
Expand All @@ -1464,6 +1465,9 @@ esp_err_t esp_bt_controller_enable(esp_bt_mode_t mode)
}
} while (0);

// Disable pll track by default in BLE controller on ESP32-C3 and ESP32-S3
sdk_config_extend_set_pll_track(false);

if (btdm_controller_enable(mode) != 0) {
ret = ESP_ERR_INVALID_STATE;
goto error;
Expand Down Expand Up @@ -1494,7 +1498,7 @@ esp_err_t esp_bt_controller_enable(esp_bt_mode_t mode)
coex_disable();
#endif
if (s_lp_stat.phy_enabled) {
esp_phy_disable();
esp_phy_disable(PHY_MODEM_BT);
s_lp_stat.phy_enabled = 0;
}
return ret;
Expand All @@ -1516,7 +1520,7 @@ esp_err_t esp_bt_controller_disable(void)
coex_disable();
#endif
if (s_lp_stat.phy_enabled) {
esp_phy_disable();
esp_phy_disable(PHY_MODEM_BT);
s_lp_stat.phy_enabled = 0;
}

Expand Down
10 changes: 5 additions & 5 deletions components/bt/controller/esp32c6/bt.c
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ IRAM_ATTR void controller_sleep_cb(uint32_t enable_tick, void *arg)
sleep_retention_do_extra_retention(true);
#endif // SOC_PM_RETENTION_HAS_CLOCK_BUG
#endif /* CONFIG_FREERTOS_USE_TICKLESS_IDLE */
esp_phy_disable();
esp_phy_disable(PHY_MODEM_BT);
#ifdef CONFIG_PM_ENABLE
esp_pm_lock_release(s_pm_lock);
#endif // CONFIG_PM_ENABLE
Expand All @@ -506,7 +506,7 @@ IRAM_ATTR void controller_wakeup_cb(void *arg)
sleep_retention_do_extra_retention(false);
#endif /* CONFIG_FREERTOS_USE_TICKLESS_IDLE && SOC_PM_RETENTION_HAS_CLOCK_BUG */
#endif //CONFIG_PM_ENABLE
esp_phy_enable();
esp_phy_enable(PHY_MODEM_BT);
s_ble_active = true;
}

Expand Down Expand Up @@ -889,7 +889,7 @@ esp_err_t esp_bt_controller_enable(esp_bt_mode_t mode)
#if CONFIG_PM_ENABLE
esp_pm_lock_acquire(s_pm_lock);
#endif // CONFIG_PM_ENABLE
esp_phy_enable();
esp_phy_enable(PHY_MODEM_BT);
esp_btbb_enable();
s_ble_active = true;
}
Expand All @@ -910,7 +910,7 @@ esp_err_t esp_bt_controller_enable(esp_bt_mode_t mode)
#endif
if (s_ble_active) {
esp_btbb_disable();
esp_phy_disable();
esp_phy_disable(PHY_MODEM_BT);
#if CONFIG_PM_ENABLE
esp_pm_lock_release(s_pm_lock);
#endif // CONFIG_PM_ENABLE
Expand All @@ -933,7 +933,7 @@ esp_err_t esp_bt_controller_disable(void)
#endif
if (s_ble_active) {
esp_btbb_disable();
esp_phy_disable();
esp_phy_disable(PHY_MODEM_BT);
#if CONFIG_PM_ENABLE
esp_pm_lock_release(s_pm_lock);
#endif // CONFIG_PM_ENABLE
Expand Down
10 changes: 5 additions & 5 deletions components/bt/controller/esp32h2/bt.c
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ IRAM_ATTR void controller_sleep_cb(uint32_t enable_tick, void *arg)
#if CONFIG_FREERTOS_USE_TICKLESS_IDLE
r_ble_rtc_wake_up_state_clr();
#endif /* CONFIG_FREERTOS_USE_TICKLESS_IDLE */
esp_phy_disable();
esp_phy_disable(PHY_MODEM_BT);
#ifdef CONFIG_PM_ENABLE
esp_pm_lock_release(s_pm_lock);
#endif // CONFIG_PM_ENABLE
Expand All @@ -489,7 +489,7 @@ IRAM_ATTR void controller_wakeup_cb(void *arg)
esp_pm_lock_acquire(s_pm_lock);
r_ble_rtc_wake_up_state_clr();
#endif //CONFIG_PM_ENABLE
esp_phy_enable();
esp_phy_enable(PHY_MODEM_BT);
s_ble_active = true;
}

Expand Down Expand Up @@ -867,7 +867,7 @@ esp_err_t esp_bt_controller_enable(esp_bt_mode_t mode)
#if CONFIG_PM_ENABLE
esp_pm_lock_acquire(s_pm_lock);
#endif // CONFIG_PM_ENABLE
esp_phy_enable();
esp_phy_enable(PHY_MODEM_BT);
s_ble_active = true;
}
esp_btbb_enable();
Expand All @@ -888,7 +888,7 @@ esp_err_t esp_bt_controller_enable(esp_bt_mode_t mode)
#endif
esp_btbb_disable();
if (s_ble_active) {
esp_phy_disable();
esp_phy_disable(PHY_MODEM_BT);
#if CONFIG_PM_ENABLE
esp_pm_lock_release(s_pm_lock);
#endif // CONFIG_PM_ENABLE
Expand All @@ -911,7 +911,7 @@ esp_err_t esp_bt_controller_disable(void)
#endif
esp_btbb_disable();
if (s_ble_active) {
esp_phy_disable();
esp_phy_disable(PHY_MODEM_BT);
#if CONFIG_PM_ENABLE
esp_pm_lock_release(s_pm_lock);
#endif // CONFIG_PM_ENABLE
Expand Down
28 changes: 20 additions & 8 deletions components/esp_phy/include/esp_phy_init.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@ typedef struct {
uint8_t params[128]; /*!< opaque PHY initialization parameters */
} esp_phy_init_data_t;

/**
* @brief PHY enable or disable modem
*/
typedef enum {
PHY_MODEM_WIFI = 1, /*!< PHY modem WIFI */
PHY_MODEM_BT = 2, /*!< PHY modem BT */
PHY_MODEM_IEEE802154 = 4, /*!< PHY modem IEEE802154 */
} esp_phy_modem_t;

/**
* @brief Opaque PHY calibration data
*/
Expand Down Expand Up @@ -144,8 +153,9 @@ esp_err_t esp_phy_erase_cal_data_in_nvs(void);
* Now PHY and RF enabling job is done automatically when start WiFi or BT. Users should not
* call this API in their application.
*
* @param modem the modem to call the phy enable.
*/
void esp_phy_enable(void);
void esp_phy_enable(esp_phy_modem_t modem);

/**
* @brief Disable PHY and RF module
Expand All @@ -154,8 +164,9 @@ void esp_phy_enable(void);
* Now PHY and RF disabling job is done automatically when stop WiFi or BT. Users should not
* call this API in their application.
*
* @param modem the modem to call the phy disable.
*/
void esp_phy_disable(void);
void esp_phy_disable(esp_phy_modem_t modem);

/**
* @brief Enable BTBB module
Expand Down Expand Up @@ -259,16 +270,17 @@ esp_err_t esp_phy_apply_phy_init_data(uint8_t *init_data);
char * get_phy_version_str(void);

/**
* @brief Enable phy track pll
*
* @brief Set PHY init parameters
* @param param is 1 means combo module
*/
void phy_track_pll_init(void);
void phy_init_param_set(uint8_t param);

/**
* @brief Disable phy track pll
*
* @brief Wi-Fi RX enable
* @param enable True for enable wifi receiving mode as default, false for closing wifi receiving mode as default.
*/
void phy_track_pll_deinit(void);
void phy_wifi_enable_set(uint8_t enable);

#ifdef __cplusplus
}
#endif
30 changes: 29 additions & 1 deletion components/esp_phy/include/esp_private/phy.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand Down Expand Up @@ -140,6 +140,34 @@ void phy_eco_version_sel(uint8_t chip_ver);
void phy_improve_rx_special(bool enable);
#endif

/**
* @brief Enable phy track pll
*
*/
void phy_track_pll_init(void);

/**
* @brief Disable phy track pll
*
*/
void phy_track_pll_deinit(void);

/**
* @brief Set the flag recorded which modem has already enabled phy
*
*/
void phy_set_modem_flag(esp_phy_modem_t modem);

/**
* @brief Clear the flag to record which modem calls phy disenable
*/
void phy_clr_modem_flag(esp_phy_modem_t modem);

/**
* @brief Get the flag recorded which modem has already enabled phy
*
*/
esp_phy_modem_t phy_get_modem_flag(void);
#ifdef __cplusplus
}
#endif
Loading

0 comments on commit f3ac648

Please sign in to comment.