From 930c304a57b618d9710264cb87560542b53734fc Mon Sep 17 00:00:00 2001 From: baohongde Date: Wed, 10 Oct 2018 16:10:20 +0800 Subject: [PATCH] components/bt: Combine two hci task into one --- components/bt/bluedroid/hci/hci_hal_h4.c | 18 +++++------------- components/bt/bluedroid/hci/hci_layer.c | 6 +++--- .../bt/bluedroid/hci/include/hci/hci_hal.h | 2 +- 3 files changed, 9 insertions(+), 17 deletions(-) diff --git a/components/bt/bluedroid/hci/hci_hal_h4.c b/components/bt/bluedroid/hci/hci_hal_h4.c index b31deda79c..5985e32ae2 100644 --- a/components/bt/bluedroid/hci/hci_hal_h4.c +++ b/components/bt/bluedroid/hci/hci_hal_h4.c @@ -27,12 +27,6 @@ #include "esp_bt.h" #include "stack/hcimsgs.h" -#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_PRIO (BT_TASK_MAX_PRIORITIES - 4) -#define HCI_H4_TASK_NAME "hciH4T" - - #if (C2H_FLOW_CONTROL_INCLUDED == TRUE) #include "l2c_int.h" #endif ///C2H_FLOW_CONTROL_INCLUDED == TRUE @@ -105,9 +99,11 @@ static void hci_hal_env_deinit(void) 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, void *task_thread) { assert(upper_callbacks != NULL); + assert(task_thread != NULL); + callbacks = upper_callbacks; #if (BLE_ADV_REPORT_FLOW_CONTROL == TRUE) hci_hal_env_init(HCI_HAL_SERIAL_BUFFER_SIZE, BLE_ADV_REPORT_FLOW_CONTROL_NUM + L2CAP_HOST_FC_ACL_BUFS + QUEUE_SIZE_MAX); // adv flow control num + ACL flow control num + hci cmd numeber @@ -115,10 +111,7 @@ static bool hal_open(const hci_hal_callbacks_t *upper_callbacks) hci_hal_env_init(HCI_HAL_SERIAL_BUFFER_SIZE, QUEUE_SIZE_MAX); #endif - hci_h4_thread = osi_thread_create(HCI_H4_TASK_NAME, HCI_H4_TASK_STACK_SIZE, HCI_H4_TASK_PRIO, HCI_H4_TASK_PINNED_TO_CORE, 1); - if (hci_h4_thread == NULL) { - return false; - } + hci_h4_thread = (osi_thread_t *)task_thread; //register vhci host cb if (esp_vhci_host_register_callback(&vhci_host_cb) != ESP_OK) { @@ -132,7 +125,6 @@ static void hal_close() { hci_hal_env_deinit(); - osi_thread_free(hci_h4_thread); hci_h4_thread = NULL; } @@ -180,7 +172,7 @@ static void hci_hal_h4_rx_handler(void *arg) bool hci_hal_h4_task_post(osi_thread_blocking_t blocking) { - return osi_thread_post(hci_h4_thread, hci_hal_h4_rx_handler, NULL, 0, blocking); + return osi_thread_post(hci_h4_thread, hci_hal_h4_rx_handler, NULL, 1, blocking); } #if (C2H_FLOW_CONTROL_INCLUDED == TRUE) diff --git a/components/bt/bluedroid/hci/hci_layer.c b/components/bt/bluedroid/hci/hci_layer.c index 00c6f19e7c..e426528d45 100644 --- a/components/bt/bluedroid/hci/hci_layer.c +++ b/components/bt/bluedroid/hci/hci_layer.c @@ -37,7 +37,7 @@ #define HCI_HOST_TASK_PINNED_TO_CORE (TASK_PINNED_TO_CORE) #define HCI_HOST_TASK_STACK_SIZE (2048 + BT_TASK_EXTRA_STACK_SIZE) #define HCI_HOST_TASK_PRIO (BT_TASK_MAX_PRIORITIES - 3) -#define HCI_HOST_TASK_NAME "hciHostT" +#define HCI_HOST_TASK_NAME "hciT" typedef struct { uint16_t opcode; @@ -105,13 +105,13 @@ int hci_start_up(void) goto error; } - hci_host_thread = osi_thread_create(HCI_HOST_TASK_NAME, HCI_HOST_TASK_STACK_SIZE, HCI_HOST_TASK_PRIO, HCI_HOST_TASK_PINNED_TO_CORE, 1); + hci_host_thread = osi_thread_create(HCI_HOST_TASK_NAME, HCI_HOST_TASK_STACK_SIZE, HCI_HOST_TASK_PRIO, HCI_HOST_TASK_PINNED_TO_CORE, 2); if (hci_host_thread == NULL) { return -2; } packet_fragmenter->init(&packet_fragmenter_callbacks); - hal->open(&hal_callbacks); + hal->open(&hal_callbacks, hci_host_thread); hci_host_startup_flag = true; return 0; diff --git a/components/bt/bluedroid/hci/include/hci/hci_hal.h b/components/bt/bluedroid/hci/include/hci/hci_hal.h index 2928f29ad3..daf3dfb81a 100644 --- a/components/bt/bluedroid/hci/include/hci/hci_hal.h +++ b/components/bt/bluedroid/hci/include/hci/hci_hal.h @@ -51,7 +51,7 @@ typedef struct hci_hal_t { //bool (*init)(const hci_hal_callbacks_t *upper_callbacks); // Connect to the underlying hardware, and let data start flowing. - bool (*open)(const hci_hal_callbacks_t *upper_callbacks); + bool (*open)(const hci_hal_callbacks_t *upper_callbacks, void *task_thread); // Disconnect from the underlying hardware, and close the HAL. // "Daisy, Daisy..." void (*close)(void);