make bluetooth and wifi use the same low power clock

This commit is contained in:
xiongweichao 2021-10-20 19:32:21 +08:00
parent cf9309c8a2
commit 8f0c559c03
4 changed files with 79 additions and 2 deletions

View File

@ -394,6 +394,8 @@ static DRAM_ATTR uint8_t btdm_lpcycle_us_frac = 0;
static DRAM_ATTR QueueHandle_t s_wakeup_req_sem = NULL;
// wakeup timer
static DRAM_ATTR esp_timer_handle_t s_btdm_slp_tmr;
// set low power clock source callback
static esp_set_lpclk_source_callback_t s_set_lpclk_source_cb = NULL;
#ifdef CONFIG_PM_ENABLE
static DRAM_ATTR esp_pm_lock_handle_t s_pm_lock;
@ -924,6 +926,11 @@ static void IRAM_ATTR btdm_mac_bb_power_up_cb(void)
}
#endif
void esp_wifi_set_lpclk_register_callback(esp_set_lpclk_source_callback_t callback)
{
s_set_lpclk_source_cb = callback;
}
esp_err_t esp_bt_controller_init(esp_bt_controller_config_t *cfg)
{
esp_err_t err = ESP_FAIL;
@ -1106,6 +1113,10 @@ esp_err_t esp_bt_controller_init(esp_bt_controller_config_t *cfg)
goto error;
}
if (s_set_lpclk_source_cb) {
s_set_lpclk_source_cb();
}
#ifdef CONFIG_PM_ENABLE
if (s_lp_cntl.no_light_sleep) {
if ((err = esp_pm_lock_create(ESP_PM_NO_LIGHT_SLEEP, 0, "btLS", &s_light_sleep_pm_lock)) != ESP_OK) {
@ -1191,7 +1202,15 @@ error:
s_lp_cntl.main_xtal_pu = 0;
}
#endif
btdm_lpclk_select_src(BTDM_LPCLK_SEL_RTC_SLOW);
btdm_lpclk_set_div(0);
if (s_set_lpclk_source_cb) {
s_set_lpclk_source_cb();
}
}
btdm_lpcycle_us = 0;
s_set_lpclk_source_cb = NULL;
} while (0);
#if CONFIG_MAC_BB_PD
@ -1261,7 +1280,15 @@ esp_err_t esp_bt_controller_deinit(void)
s_lp_cntl.main_xtal_pu = 0;
}
#endif
btdm_lpclk_select_src(BTDM_LPCLK_SEL_RTC_SLOW);
btdm_lpclk_set_div(0);
if (s_set_lpclk_source_cb) {
s_set_lpclk_source_cb();
}
}
btdm_lpcycle_us = 0;
s_set_lpclk_source_cb = NULL;
} while (0);
#if CONFIG_MAC_BB_PD
@ -1284,7 +1311,6 @@ esp_err_t esp_bt_controller_deinit(void)
osi_funcs_p = NULL;
btdm_controller_status = ESP_BT_CONTROLLER_STATUS_IDLE;
btdm_lpcycle_us = 0;
return ESP_OK;
}

View File

@ -397,6 +397,8 @@ static DRAM_ATTR uint8_t btdm_lpcycle_us_frac = 0;
static DRAM_ATTR QueueHandle_t s_wakeup_req_sem = NULL;
// wakeup timer
static DRAM_ATTR esp_timer_handle_t s_btdm_slp_tmr;
// set low power clock source callback
static esp_set_lpclk_source_callback_t s_set_lpclk_source_cb = NULL;
#ifdef CONFIG_PM_ENABLE
static DRAM_ATTR esp_pm_lock_handle_t s_pm_lock;
@ -955,6 +957,11 @@ static void IRAM_ATTR btdm_mac_bb_power_up_cb(void)
}
#endif
void esp_wifi_set_lpclk_register_callback(esp_set_lpclk_source_callback_t callback)
{
s_set_lpclk_source_cb = callback;
}
esp_err_t esp_bt_controller_init(esp_bt_controller_config_t *cfg)
{
esp_err_t err = ESP_FAIL;
@ -1137,6 +1144,10 @@ esp_err_t esp_bt_controller_init(esp_bt_controller_config_t *cfg)
goto error;
}
if (s_set_lpclk_source_cb) {
s_set_lpclk_source_cb();
}
#ifdef CONFIG_PM_ENABLE
if (s_lp_cntl.no_light_sleep) {
if ((err = esp_pm_lock_create(ESP_PM_NO_LIGHT_SLEEP, 0, "btLS", &s_light_sleep_pm_lock)) != ESP_OK) {
@ -1213,6 +1224,7 @@ error:
semphr_delete_wrapper(s_wakeup_req_sem);
s_wakeup_req_sem = NULL;
}
}
if (s_lp_cntl.lpclk_sel == BTDM_LPCLK_SEL_XTAL) {
#ifdef CONFIG_BT_CTRL_MAIN_XTAL_PU_DURING_LIGHT_SLEEP
@ -1221,7 +1233,15 @@ error:
s_lp_cntl.main_xtal_pu = 0;
}
#endif
btdm_lpclk_select_src(BTDM_LPCLK_SEL_RTC_SLOW);
btdm_lpclk_set_div(0);
if (s_set_lpclk_source_cb) {
s_set_lpclk_source_cb();
}
}
btdm_lpcycle_us = 0;
s_set_lpclk_source_cb = NULL;
} while (0);
#if CONFIG_MAC_BB_PD
@ -1292,7 +1312,15 @@ esp_err_t esp_bt_controller_deinit(void)
s_lp_cntl.main_xtal_pu = 0;
}
#endif
btdm_lpclk_select_src(BTDM_LPCLK_SEL_RTC_SLOW);
btdm_lpclk_set_div(0);
if (s_set_lpclk_source_cb) {
s_set_lpclk_source_cb();
}
}
btdm_lpcycle_us = 0;
s_set_lpclk_source_cb = NULL;
} while (0);
#if CONFIG_MAC_BB_PD
@ -1310,7 +1338,6 @@ esp_err_t esp_bt_controller_deinit(void)
osi_funcs_p = NULL;
btdm_controller_status = ESP_BT_CONTROLLER_STATUS_IDLE;
btdm_lpcycle_us = 0;
return ESP_OK;
}

View File

@ -92,6 +92,11 @@ enum {
*/
typedef void (* esp_bt_hci_tl_callback_t) (void *arg, uint8_t status);
/**
* @brief callback function for Wi-Fi low power clock operations
*/
typedef void (* esp_set_lpclk_source_callback_t)(void);
#ifdef CONFIG_BT_ENABLED
#define BT_CTRL_BLE_MAX_ACT_LIMIT 10 //Maximum BLE activity limitation
@ -535,6 +540,13 @@ void esp_wifi_bt_power_domain_on(void);
*/
void esp_wifi_bt_power_domain_off(void);
/**
* @brief Register application callback function to Wi-Fi low power clock module.
*
* @param callback : Wi-Fi set low power clock callback function
*/
void esp_wifi_set_lpclk_register_callback(esp_set_lpclk_source_callback_t callback);
#ifdef __cplusplus
}
#endif

View File

@ -92,6 +92,11 @@ enum {
*/
typedef void (* esp_bt_hci_tl_callback_t) (void *arg, uint8_t status);
/**
* @brief callback function for Wi-Fi low power clock operations
*/
typedef void (* esp_set_lpclk_source_callback_t)(void);
#ifdef CONFIG_BT_ENABLED
#define BT_CTRL_BLE_MAX_ACT_LIMIT 10 //Maximum BLE activity limitation
@ -534,6 +539,13 @@ void esp_wifi_bt_power_domain_on(void);
*/
void esp_wifi_bt_power_domain_off(void);
/**
* @brief Register application callback function to Wi-Fi low power clock module.
*
* @param callback : Wi-Fi set low power clock callback function
*/
void esp_wifi_set_lpclk_register_callback(esp_set_lpclk_source_callback_t callback);
#ifdef __cplusplus
}
#endif