Merge branch 'bugfix/btdm_controller_deinit_v3.1' into 'release/v3.1'
bt : fix bug that bluetooth controller init/disable/enable/disable may cause exception(backport v3.1) See merge request idf/esp-idf!2865
This commit is contained in:
commit
c983bc4d12
2 changed files with 20 additions and 21 deletions
|
@ -98,6 +98,7 @@ static void hci_hal_env_init(
|
||||||
static void hci_hal_env_deinit(void)
|
static void hci_hal_env_deinit(void)
|
||||||
{
|
{
|
||||||
fixed_queue_free(hci_hal_env.rx_q, hci_hal_env.allocator->free);
|
fixed_queue_free(hci_hal_env.rx_q, hci_hal_env.allocator->free);
|
||||||
|
hci_hal_env.rx_q = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool hal_open(const hci_hal_callbacks_t *upper_callbacks)
|
static bool hal_open(const hci_hal_callbacks_t *upper_callbacks)
|
||||||
|
@ -317,6 +318,10 @@ static int host_recv_pkt_cb(uint8_t *data, uint16_t len)
|
||||||
BT_HDR *pkt;
|
BT_HDR *pkt;
|
||||||
size_t pkt_size;
|
size_t pkt_size;
|
||||||
|
|
||||||
|
if (hci_hal_env.rx_q == NULL) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
pkt_size = BT_HDR_SIZE + len;
|
pkt_size = BT_HDR_SIZE + len;
|
||||||
pkt = (BT_HDR *)hci_hal_env.allocator->alloc(pkt_size);
|
pkt = (BT_HDR *)hci_hal_env.allocator->alloc(pkt_size);
|
||||||
if (!pkt) {
|
if (!pkt) {
|
||||||
|
|
|
@ -61,9 +61,9 @@
|
||||||
/* not for user call, so don't put to include file */
|
/* not for user call, so don't put to include file */
|
||||||
extern void btdm_osi_funcs_register(void *osi_funcs);
|
extern void btdm_osi_funcs_register(void *osi_funcs);
|
||||||
extern int btdm_controller_init(uint32_t config_mask, esp_bt_controller_config_t *config_opts);
|
extern int btdm_controller_init(uint32_t config_mask, esp_bt_controller_config_t *config_opts);
|
||||||
extern int btdm_controller_deinit(void);
|
extern void btdm_controller_deinit(void);
|
||||||
extern int btdm_controller_enable(esp_bt_mode_t mode);
|
extern int btdm_controller_enable(esp_bt_mode_t mode);
|
||||||
extern int btdm_controller_disable(esp_bt_mode_t mode);
|
extern void btdm_controller_disable(void);
|
||||||
extern uint8_t btdm_controller_get_mode(void);
|
extern uint8_t btdm_controller_get_mode(void);
|
||||||
extern const char *btdm_controller_get_compile_version(void);
|
extern const char *btdm_controller_get_compile_version(void);
|
||||||
extern void btdm_rf_bb_init(void);
|
extern void btdm_rf_bb_init(void);
|
||||||
|
@ -880,9 +880,7 @@ esp_err_t esp_bt_controller_deinit(void)
|
||||||
return ESP_ERR_INVALID_STATE;
|
return ESP_ERR_INVALID_STATE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (btdm_controller_deinit() != 0) {
|
btdm_controller_deinit();
|
||||||
return ESP_ERR_NO_MEM;
|
|
||||||
}
|
|
||||||
|
|
||||||
periph_module_disable(PERIPH_BT_MODULE);
|
periph_module_disable(PERIPH_BT_MODULE);
|
||||||
|
|
||||||
|
@ -956,6 +954,9 @@ esp_err_t esp_bt_controller_enable(esp_bt_mode_t mode)
|
||||||
esp_modem_sleep_deregister(MODEM_BLE_MODULE);
|
esp_modem_sleep_deregister(MODEM_BLE_MODULE);
|
||||||
}
|
}
|
||||||
esp_phy_rf_deinit(PHY_BT_MODULE);
|
esp_phy_rf_deinit(PHY_BT_MODULE);
|
||||||
|
#ifdef CONFIG_PM_ENABLE
|
||||||
|
esp_pm_lock_release(s_pm_lock);
|
||||||
|
#endif
|
||||||
return ESP_ERR_INVALID_STATE;
|
return ESP_ERR_INVALID_STATE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -966,8 +967,6 @@ esp_err_t esp_bt_controller_enable(esp_bt_mode_t mode)
|
||||||
|
|
||||||
esp_err_t esp_bt_controller_disable(void)
|
esp_err_t esp_bt_controller_disable(void)
|
||||||
{
|
{
|
||||||
int ret;
|
|
||||||
|
|
||||||
if (btdm_controller_status != ESP_BT_CONTROLLER_STATUS_ENABLED) {
|
if (btdm_controller_status != ESP_BT_CONTROLLER_STATUS_ENABLED) {
|
||||||
return ESP_ERR_INVALID_STATE;
|
return ESP_ERR_INVALID_STATE;
|
||||||
}
|
}
|
||||||
|
@ -983,12 +982,8 @@ esp_err_t esp_bt_controller_disable(void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = btdm_controller_disable(btdm_controller_get_mode());
|
btdm_controller_disable();
|
||||||
if (ret < 0) {
|
|
||||||
return ESP_ERR_INVALID_STATE;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ret == ESP_BT_MODE_IDLE) {
|
|
||||||
if (btdm_controller_get_sleep_mode() == BTDM_MODEM_SLEEP_MODE_NONE
|
if (btdm_controller_get_sleep_mode() == BTDM_MODEM_SLEEP_MODE_NONE
|
||||||
|| btdm_controller_get_sleep_mode() == BTDM_MODEM_SLEEP_MODE_ORIG) {
|
|| btdm_controller_get_sleep_mode() == BTDM_MODEM_SLEEP_MODE_ORIG) {
|
||||||
esp_modem_sleep_deregister(MODEM_BLE_MODULE);
|
esp_modem_sleep_deregister(MODEM_BLE_MODULE);
|
||||||
|
@ -998,7 +993,6 @@ esp_err_t esp_bt_controller_disable(void)
|
||||||
}
|
}
|
||||||
esp_phy_rf_deinit(PHY_BT_MODULE);
|
esp_phy_rf_deinit(PHY_BT_MODULE);
|
||||||
btdm_controller_status = ESP_BT_CONTROLLER_STATUS_INITED;
|
btdm_controller_status = ESP_BT_CONTROLLER_STATUS_INITED;
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef CONFIG_PM_ENABLE
|
#ifdef CONFIG_PM_ENABLE
|
||||||
esp_pm_lock_release(s_pm_lock);
|
esp_pm_lock_release(s_pm_lock);
|
||||||
|
|
Loading…
Reference in a new issue