From bfa79648cdbd2fe658d09faa4f405837e71b2d16 Mon Sep 17 00:00:00 2001 From: gengyuchao Date: Thu, 20 Aug 2020 21:49:15 +0800 Subject: [PATCH] Fix HCI timeout 0x40F by handling the pairing busy status. --- .../bt/bluedroid/osi/include/osi/thread.h | 2 +- components/bt/bt.c | 86 +++++++++++++++++++ components/bt/lib | 2 +- 3 files changed, 88 insertions(+), 2 deletions(-) diff --git a/components/bt/bluedroid/osi/include/osi/thread.h b/components/bt/bluedroid/osi/include/osi/thread.h index 9b4e4ab22b..7fbc6dcb84 100644 --- a/components/bt/bluedroid/osi/include/osi/thread.h +++ b/components/bt/bluedroid/osi/include/osi/thread.h @@ -66,7 +66,7 @@ typedef enum { #define HCI_HOST_QUEUE_LEN 190//40 #define HCI_H4_TASK_PINNED_TO_CORE (TASK_PINNED_TO_CORE) -#define HCI_H4_TASK_STACK_SIZE (2048 + BT_TASK_EXTRA_STACK_SIZE) +#define HCI_H4_TASK_STACK_SIZE (2560 + BT_TASK_EXTRA_STACK_SIZE) #define HCI_H4_TASK_PRIO (configMAX_PRIORITIES - 4) #define HCI_H4_TASK_NAME "hciH4T" #define HCI_H4_QUEUE_LEN 1 diff --git a/components/bt/bt.c b/components/bt/bt.c index 77c520f917..1c89447567 100644 --- a/components/bt/bt.c +++ b/components/bt/bt.c @@ -1513,4 +1513,90 @@ void bt_abort_with_coredump_log(uint16_t error) r_assert_with_log(error,intenable,*((uint32_t*)BT_INT_STA_REG),*((uint32_t*)BLE_INT_STA_REG),(uint32_t)(esp_timer_get_time()/1000)); } + +typedef void (*esp_func_t)(void* arg); +int IRAM_ATTR Designated_execution_core1_wrapper(esp_func_t func, void* param) +{ + esp_err_t err = ESP_OK; + + if (xPortGetCoreID() == CONFIG_BTDM_CONTROLLER_PINNED_TO_CORE) { + ESP_LOGD("BTDM","Exec core right %d.\n",CONFIG_BTDM_CONTROLLER_PINNED_TO_CORE); + } else { + ESP_LOGD("BTDM","Exec core err, will run in core %d.\n",CONFIG_BTDM_CONTROLLER_PINNED_TO_CORE); + ESP_ERROR_CHECK(esp_ipc_call(CONFIG_BTDM_CONTROLLER_PINNED_TO_CORE, func, (void *)param)); + err = ESP_FAIL; + } + return err; +} + +#define BTDM_TIMER_MAX 4 +esp_timer_handle_t btdm_oneshot_timer[BTDM_TIMER_MAX]={NULL}; +esp_timer_create_args_t oneshot_timer_args[BTDM_TIMER_MAX]; + +void btdm_debug_error_add(int error); +esp_err_t simple_timer_start(int timer_id,esp_timer_cb_t timer_callback,int timeout); +esp_err_t simple_timer_clear(int timer_id); + +esp_err_t simple_timer_start(int timer_id,esp_timer_cb_t timer_callback,int timeout) +{ + esp_err_t ret = ESP_OK; + if(timer_id>BTDM_TIMER_MAX-1) + { + ESP_LOGD("simple_timer","BTDM Timer id err %d.\n",timer_id); + return ESP_ERR_INVALID_ARG; + } + if(timer_callback == NULL) + { + ESP_LOGD("simple_timer","BTDM Timer timer_callback err %p.\n",timer_callback); + return ESP_ERR_INVALID_ARG; + } + ESP_LOGD("simple_timer","%s:%d\n",__func__,timer_id); + + if(btdm_oneshot_timer[timer_id] != NULL) + { + ESP_LOGD("simple_timer","BTDM Timer %d has been set.\n",timer_id); + esp_timer_stop(btdm_oneshot_timer[timer_id]); + ret = esp_timer_start_once(btdm_oneshot_timer[timer_id], timeout); + } + else + { + oneshot_timer_args[timer_id].callback = timer_callback; + oneshot_timer_args[timer_id].name = "one-shot"; + ret = esp_timer_create(&oneshot_timer_args[timer_id], &btdm_oneshot_timer[timer_id]); + if(ret == ESP_OK) { + ret = esp_timer_start_once(btdm_oneshot_timer[timer_id], timeout); + } + } + if(ret != ESP_OK){ + ESP_LOGE("simple_timer","BTDM Timer %d ret %d .\n",timer_id,ret); + btdm_debug_error_add(15); + } + return ret; +} + +esp_err_t simple_timer_clear(int timer_id) +{ + ESP_LOGD("simple_timer","%s:%d core_id:%d\n",__func__,timer_id,xPortGetCoreID()); + + if(timer_id>BTDM_TIMER_MAX-1) + { + ESP_LOGD("simple_timer","BTDM Timer id err %d.\n",timer_id); + return ESP_ERR_INVALID_ARG; + } + if(btdm_oneshot_timer[timer_id]==NULL) + { + ESP_LOGD("simple_timer","BTDM Timer not init %d.\n",timer_id); + return ESP_ERR_INVALID_STATE; + } + if(esp_timer_stop(btdm_oneshot_timer[timer_id])==ESP_ERR_INVALID_STATE) + { + ESP_LOGD("simple_timer","BTDM Timer not start %d.\n",timer_id); + return ESP_ERR_INVALID_STATE; + } + esp_timer_delete(btdm_oneshot_timer[timer_id]); + btdm_oneshot_timer[timer_id] = NULL; + return ESP_OK; +} + + #endif /* CONFIG_BT_ENABLED */ diff --git a/components/bt/lib b/components/bt/lib index decab32977..e5219ee315 160000 --- a/components/bt/lib +++ b/components/bt/lib @@ -1 +1 @@ -Subproject commit decab32977f45077c6e52317fc168ac415fde22a +Subproject commit e5219ee315ed35392b71eb213d58ff7cdf5b2c17