bt : fix bug that bluetooth controller init/disable/enable/disable may cause exception

1. when one task do deinit/init/disable/enable, especially different cpu
core, it may cause controller crash in ISR handler
2. fix while BLE is scanning, bluetooth controller is disabled cause BLE
scan is not abort.
This commit is contained in:
Tian Hao 2018-07-17 15:46:56 +08:00
parent 97603b1d59
commit a9c1820385
3 changed files with 12 additions and 16 deletions

View File

@ -92,6 +92,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)
@ -260,6 +261,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) {

View File

@ -57,9 +57,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);
@ -748,9 +748,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);
@ -806,21 +804,14 @@ 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;
} }
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) { esp_phy_rf_deinit();
esp_phy_rf_deinit(); 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);

@ -1 +1 @@
Subproject commit 12ca65ce02d292a6223cd8f658fb5c38638b2dd5 Subproject commit 96e7e06e0bd602953b0a80531eaa4a7dc6cb935a