diff --git a/components/bt/bt.c b/components/bt/bt.c index 140877d33..a0539a19a 100644 --- a/components/bt/bt.c +++ b/components/bt/bt.c @@ -33,6 +33,7 @@ #include "bt.h" #include "esp_err.h" #include "esp_log.h" +#include "esp_pm.h" #if CONFIG_BT_ENABLED @@ -147,6 +148,10 @@ static esp_bt_controller_status_t btdm_controller_status = ESP_BT_CONTROLLER_STA static portMUX_TYPE global_int_mux = portMUX_INITIALIZER_UNLOCKED; +#ifdef CONFIG_PM_ENABLE +static esp_pm_lock_handle_t s_pm_lock; +#endif + static void IRAM_ATTR interrupt_disable(void) { portENTER_CRITICAL(&global_int_mux); @@ -442,6 +447,13 @@ esp_err_t esp_bt_controller_init(esp_bt_controller_config_t *cfg) return ESP_ERR_INVALID_ARG; } +#ifdef CONFIG_PM_ENABLE + esp_err_t err = esp_pm_lock_create(ESP_PM_APB_FREQ_MAX, 0, "bt", &s_pm_lock); + if (err != ESP_OK) { + return err; + } +#endif + btdm_osi_funcs_register(&osi_funcs); btdm_controller_mem_init(); @@ -450,6 +462,10 @@ esp_err_t esp_bt_controller_init(esp_bt_controller_config_t *cfg) ret = btdm_controller_init(btdm_cfg_mask, cfg); if (ret) { +#ifdef CONFIG_PM_ENABLE + esp_pm_lock_delete(s_pm_lock); + s_pm_lock = NULL; +#endif return ESP_ERR_NO_MEM; } @@ -468,6 +484,12 @@ esp_err_t esp_bt_controller_deinit(void) } btdm_controller_status = ESP_BT_CONTROLLER_STATUS_IDLE; + +#ifdef CONFIG_PM_ENABLE + esp_pm_lock_delete(s_pm_lock); + s_pm_lock = NULL; +#endif + return ESP_OK; } @@ -484,6 +506,10 @@ esp_err_t esp_bt_controller_enable(esp_bt_mode_t mode) return ESP_ERR_INVALID_ARG; } +#ifdef CONFIG_PM_ENABLE + esp_pm_lock_acquire(s_pm_lock); +#endif + esp_phy_load_cal_and_init(); if (btdm_bb_init_flag == false) { @@ -519,6 +545,10 @@ esp_err_t esp_bt_controller_disable(void) btdm_controller_status = ESP_BT_CONTROLLER_STATUS_INITED; } +#ifdef CONFIG_PM_ENABLE + esp_pm_lock_release(s_pm_lock); +#endif + return ESP_OK; }