From d2872cbf2ec72091676985791902382ff8862e5b Mon Sep 17 00:00:00 2001 From: Tian Hao Date: Mon, 23 Jan 2017 16:11:27 +0800 Subject: [PATCH] component/bt : remove fixed queue from btu --- .../bt/bluedroid/bta/sys/bta_sys_main.c | 18 +- components/bt/bluedroid/hci/hci_hal_h4.c | 9 +- components/bt/bluedroid/hci/hci_layer.c | 32 +-- .../bt/bluedroid/hci/include/hci_layer.h | 3 - components/bt/bluedroid/main/bte_main.c | 66 ------- components/bt/bluedroid/osi/include/thread.h | 37 +++- components/bt/bluedroid/stack/btu/btu_hcif.c | 9 +- components/bt/bluedroid/stack/btu/btu_init.c | 73 +------ components/bt/bluedroid/stack/btu/btu_task.c | 187 +++++------------- 9 files changed, 104 insertions(+), 330 deletions(-) diff --git a/components/bt/bluedroid/bta/sys/bta_sys_main.c b/components/bt/bluedroid/bta/sys/bta_sys_main.c index c1d1c0018a..b023ef4635 100644 --- a/components/bt/bluedroid/bta/sys/bta_sys_main.c +++ b/components/bt/bluedroid/bta/sys/bta_sys_main.c @@ -51,7 +51,6 @@ tBTA_SYS_CB bta_sys_cb; #endif -fixed_queue_t *btu_bta_alarm_queue; static hash_map_t *bta_alarm_hash_map; static const size_t BTA_ALARM_HASH_MAP_SIZE = 17; static pthread_mutex_t bta_alarm_lock; @@ -62,8 +61,6 @@ static pthread_mutex_t bta_alarm_lock; UINT8 appl_trace_level = BT_TRACE_LEVEL_WARNING; //APPL_INITIAL_TRACE_LEVEL; UINT8 btif_trace_level = BT_TRACE_LEVEL_WARNING; -// Communication queue between btu_task and bta. -extern fixed_queue_t *btu_bta_msg_queue; void btu_bta_alarm_ready(fixed_queue_t *queue); static const tBTA_SYS_REG bta_sys_hw_reg = { @@ -175,10 +172,6 @@ void bta_sys_init(void) bta_alarm_hash_map = hash_map_new(BTA_ALARM_HASH_MAP_SIZE, hash_function_pointer, NULL, (data_free_fn)osi_alarm_free, NULL); - btu_bta_alarm_queue = fixed_queue_new(SIZE_MAX); - - fixed_queue_register_dequeue(btu_bta_alarm_queue, - btu_bta_alarm_ready); appl_trace_level = APPL_INITIAL_TRACE_LEVEL; @@ -196,7 +189,6 @@ void bta_sys_init(void) void bta_sys_free(void) { - fixed_queue_free(btu_bta_alarm_queue, NULL); hash_map_free(bta_alarm_hash_map); pthread_mutex_destroy(&bta_alarm_lock); } @@ -575,10 +567,8 @@ void bta_sys_sendmsg(void *p_msg) // there is a procedure in progress that can schedule a task via this // message queue. This causes |btu_bta_msg_queue| to get cleaned up before // it gets used here; hence we check for NULL before using it. - if (btu_bta_msg_queue) { - fixed_queue_enqueue(btu_bta_msg_queue, p_msg); - //ke_event_set(KE_EVENT_BTU_TASK_THREAD); - btu_task_post(SIG_BTU_WORK, TASK_POST_BLOCKING); + if (btu_task_post(SIG_BTU_BTA_MSG, p_msg, TASK_POST_BLOCKING) != TASK_POST_SUCCESS) { + GKI_freebuf(p_msg); } } @@ -597,9 +587,7 @@ void bta_alarm_cb(void *data) assert(data != NULL); TIMER_LIST_ENT *p_tle = (TIMER_LIST_ENT *)data; - fixed_queue_enqueue(btu_bta_alarm_queue, p_tle); - - btu_task_post(SIG_BTU_WORK, TASK_POST_BLOCKING); + btu_task_post(SIG_BTU_BTA_ALARM, p_tle, TASK_POST_BLOCKING); } void bta_sys_start_timer(TIMER_LIST_ENT *p_tle, UINT16 type, INT32 timeout_ms) diff --git a/components/bt/bluedroid/hci/hci_hal_h4.c b/components/bt/bluedroid/hci/hci_hal_h4.c index 30e225e951..0cc5db676f 100644 --- a/components/bt/bluedroid/hci/hci_hal_h4.c +++ b/components/bt/bluedroid/hci/hci_hal_h4.c @@ -163,23 +163,26 @@ static void hci_hal_h4_rx_handler(void *arg) for (;;) { if (pdTRUE == xQueueReceive(xHciH4Queue, &e, (portTickType)portMAX_DELAY)) { - if (e.sig == 0xff) { + if (e.sig == SIG_HCI_HAL_RECV_PACKET) { fixed_queue_process(hci_hal_env.rx_q); } } } } -void hci_hal_h4_task_post(task_post_t timeout) +task_post_status_t hci_hal_h4_task_post(task_post_t timeout) { BtTaskEvt_t evt; - evt.sig = 0xff; + evt.sig = SIG_HCI_HAL_RECV_PACKET; evt.par = 0; if (xQueueSend(xHciH4Queue, &evt, timeout) != pdTRUE) { LOG_ERROR("xHciH4Queue failed\n"); + return TASK_POST_SUCCESS; } + + return TASK_POST_FAIL; } static void hci_hal_h4_hdl_rx_packet(BT_HDR *packet) diff --git a/components/bt/bluedroid/hci/hci_layer.c b/components/bt/bluedroid/hci/hci_layer.c index 4273074217..aa93184e2b 100644 --- a/components/bt/bluedroid/hci/hci_layer.c +++ b/components/bt/bluedroid/hci/hci_layer.c @@ -54,9 +54,6 @@ typedef struct { fixed_queue_t *command_queue; fixed_queue_t *packet_queue; - // The hand-off point for data going to a higher layer, set by the higher layer - fixed_queue_t *upwards_data_queue; - command_waiting_response_t cmd_waiting_q; /* @@ -135,20 +132,23 @@ void hci_shut_down(void) } -void hci_host_task_post(task_post_t timeout) +task_post_status_t hci_host_task_post(task_post_t timeout) { BtTaskEvt_t evt; if (hci_host_startup_flag == false) { - return; + return TASK_POST_FAIL; } - evt.sig = 0xff; + evt.sig = SIG_HCI_HOST_SEND_AVAILABLE; evt.par = 0; if (xQueueSend(xHciHostQueue, &evt, timeout) != pdTRUE) { LOG_ERROR("xHciHostQueue failed\n"); + return TASK_POST_FAIL; } + + return TASK_POST_SUCCESS; } static int hci_layer_init_env(void) @@ -227,7 +227,7 @@ static void hci_host_thread_handler(void *arg) for (;;) { if (pdTRUE == xQueueReceive(xHciHostQueue, &e, (portTickType)portMAX_DELAY)) { - if (e.sig == 0xff) { + if (e.sig == SIG_HCI_HOST_SEND_AVAILABLE) { if (esp_vhci_host_check_send_available()) { /*Now Target only allowed one packet per TX*/ BT_HDR *pkt = packet_fragmenter->fragment_current_packet(); @@ -247,11 +247,6 @@ static void hci_host_thread_handler(void *arg) } } -static void set_data_queue(fixed_queue_t *queue) -{ - hci_host_env.upwards_data_queue = queue; -} - static void transmit_command( BT_HDR *command, command_complete_cb complete_callback, @@ -311,7 +306,7 @@ static void transmit_downward(uint16_t type, void *data) } else { fixed_queue_enqueue(hci_host_env.packet_queue, data); } - //ke_event_set(KE_EVENT_HCI_HOST_THREAD); + hci_host_task_post(TASK_POST_BLOCKING); } @@ -495,7 +490,6 @@ intercepted: !fixed_queue_is_empty(hci_host_env.command_queue)) { hci_host_task_post(TASK_POST_BLOCKING); } - //ke_event_set(KE_EVENT_HCI_HOST_THREAD); if (wait_entry) { // If it has a callback, it's responsible for freeing the packet @@ -521,13 +515,8 @@ intercepted: static void dispatch_reassembled(BT_HDR *packet) { // Events should already have been dispatched before this point - - if (hci_host_env.upwards_data_queue) { - fixed_queue_enqueue(hci_host_env.upwards_data_queue, packet); - btu_task_post(SIG_BTU_WORK, TASK_POST_BLOCKING); - //Tell Up-layer received packet. - } else { - LOG_DEBUG("%s had no queue to place upwards data packet in. Dropping it on the floor.", __func__); + //Tell Up-layer received packet. + if (btu_task_post(SIG_BTU_HCI_MSG, packet, TASK_POST_BLOCKING) != TASK_POST_SUCCESS) { buffer_allocator->free(packet); } } @@ -576,7 +565,6 @@ static waiting_command_t *get_waiting_command(command_opcode_t opcode) static void init_layer_interface() { if (!interface_created) { - interface.set_data_queue = set_data_queue; interface.transmit_command = transmit_command; interface.transmit_command_futured = transmit_command_futured; interface.transmit_downward = transmit_downward; diff --git a/components/bt/bluedroid/hci/include/hci_layer.h b/components/bt/bluedroid/hci/include/hci_layer.h index caea29f28d..76f93638ad 100644 --- a/components/bt/bluedroid/hci/include/hci_layer.h +++ b/components/bt/bluedroid/hci/include/hci_layer.h @@ -77,9 +77,6 @@ typedef struct hci_t { // Do the postload sequence (call after the rest of the BT stack initializes). void (*do_postload)(void); - // Set the queue to receive ACL data in - void (*set_data_queue)(fixed_queue_t *queue); - // Send a command through the HCI layer void (*transmit_command)( BT_HDR *command, diff --git a/components/bt/bluedroid/main/bte_main.c b/components/bt/bluedroid/main/bte_main.c index 2705bff9b3..8e77072e92 100644 --- a/components/bt/bluedroid/main/bte_main.c +++ b/components/bt/bluedroid/main/bte_main.c @@ -32,56 +32,16 @@ #include "bt_trace.h" #include "osi.h" #include "alarm.h" -#include "fixed_queue.h" #include "hash_map.h" #include "hash_functions.h" #include "controller.h" #include "hci_layer.h" #include "bta_api.h" -//#include "bluedroid_test.h" -/* -#define LOG_TAG "bt_main" - -#include -#include -#include -#include -#include -#include -#include - -#include "osi/include/alarm.h" -#include "bta_api.h" -#include "bt_hci_bdroid.h" -#include "bte.h" -#include "btif_common.h" -#include "btu.h" -#include "btsnoop.h" -#include "bt_utils.h" -#include "btcore/include/counter.h" -#include "btcore/include/module.h" -#include "osi/include/fixed_queue.h" -#include "osi/include/future.h" -#include "gki.h" -#include "osi/include/hash_functions.h" -#include "osi/include/hash_map.h" -#include "hci_layer.h" -#include "osi/include/osi.h" -#include "osi/include/log.h" -#include "stack_config.h" -#include "osi/include/thread.h" -*/ /******************************************************************************* ** Constants & Macros *******************************************************************************/ -/* Run-time configuration file for BLE*/ -/* -#ifndef BTE_BLE_STACK_CONF_FILE -#define BTE_BLE_STACK_CONF_FILE "/etc/bluetooth/ble_stack.conf" -#endif -*/ /****************************************************************************** ** Variables ******************************************************************************/ @@ -100,8 +60,6 @@ static void bte_main_enable(void); /******************************************************************************* ** Externs *******************************************************************************/ -//extern void bte_load_ble_conf(const char *p_path); -fixed_queue_t *btu_hci_msg_queue; bluedroid_init_done_cb_t bluedroid_init_done_cb; @@ -128,18 +86,8 @@ int bte_main_boot_entry(bluedroid_init_done_cb_t cb) return -2; } - btu_hci_msg_queue = fixed_queue_new(SIZE_MAX); - if (btu_hci_msg_queue == NULL) { - LOG_ERROR("%s unable to allocate hci message queue.\n", __func__); - return -3; - } - bluedroid_init_done_cb = cb; - //Caution: No event dispatcher defined now in hci layer - //data_dispatcher_register_default(hci->event_dispatcher, btu_hci_msg_queue); - hci->set_data_queue(btu_hci_msg_queue); - //Enbale HCI bte_main_enable(); @@ -157,20 +105,6 @@ int bte_main_boot_entry(bluedroid_init_done_cb_t cb) ******************************************************************************/ void bte_main_shutdown(void) { - //data_dispatcher_register_default(hci_layer_get_interface()->event_dispatcher, NULL); - hci->set_data_queue(NULL); - fixed_queue_unregister_dequeue(btu_hci_msg_queue); - fixed_queue_free(btu_hci_msg_queue, NULL); - - btu_hci_msg_queue = NULL; - - /* - module_clean_up(get_module(STACK_CONFIG_MODULE)); - - module_clean_up(get_module(COUNTER_MODULE)); - module_clean_up(get_module(GKI_MODULE)); - */ - #if (BLE_INCLUDED == TRUE) BTA_VendorCleanup(); #endif diff --git a/components/bt/bluedroid/osi/include/thread.h b/components/bt/bluedroid/osi/include/thread.h index 4d2b435962..5f023c657f 100644 --- a/components/bt/bluedroid/osi/include/thread.h +++ b/components/bt/bluedroid/osi/include/thread.h @@ -35,12 +35,27 @@ typedef struct bt_task_evt BtTaskEvt_t; typedef bt_status_t (* BtTaskCb_t)(void *arg); -enum { - SIG_PRF_START_UP = 0xfc, - SIG_PRF_WORK = 0xfd, - SIG_BTU_START_UP = 0xfe, - SIG_BTU_WORK = 0xff, -}; +typedef enum { + SIG_HCI_HAL_RECV_PACKET = 0, + SIG_HCI_HAL_NUM, +} SIG_HCI_HAL_t; + + +typedef enum { + SIG_HCI_HOST_SEND_AVAILABLE = 0, + SIG_HCI_HOST_NUM, +} SIG_HCI_HOST_t; + +typedef enum { + SIG_BTU_START_UP = 0, + SIG_BTU_HCI_MSG, + SIG_BTU_BTA_MSG, + SIG_BTU_BTA_ALARM, + SIG_BTU_GENERAL_ALARM, + SIG_BTU_ONESHOT_ALARM, + SIG_BTU_L2CAP_ALARM, + SIG_BTU_NUM, +} SIG_BTU_t; #define HCI_HOST_TASK_STACK_SIZE (2048 + BT_TASK_EXTRA_STACK_SIZE) #define HCI_HOST_TASK_PRIO (configMAX_PRIORITIES - 3) @@ -67,9 +82,13 @@ enum { #define TASK_POST_BLOCKING (portMAX_DELAY) typedef uint32_t task_post_t; /* Timeout of task post return, unit TICK */ -void btu_task_post(uint32_t sig, task_post_t timeout); -void hci_host_task_post(task_post_t timeout); -void hci_hal_h4_task_post(task_post_t timeout); +typedef enum { + TASK_POST_SUCCESS = 0, + TASK_POST_FAIL, +} task_post_status_t; +task_post_status_t btu_task_post(uint32_t sig, void *param, task_post_t timeout); +task_post_status_t hci_host_task_post(task_post_t timeout); +task_post_status_t hci_hal_h4_task_post(task_post_t timeout); #endif /* __THREAD_H__ */ diff --git a/components/bt/bluedroid/stack/btu/btu_hcif.c b/components/bt/bluedroid/stack/btu/btu_hcif.c index 7d00f0b76f..f3a6dd5c8e 100644 --- a/components/bt/bluedroid/stack/btu/btu_hcif.c +++ b/components/bt/bluedroid/stack/btu/btu_hcif.c @@ -47,7 +47,6 @@ // TODO(zachoverflow): remove this horrible hack #include "btu.h" -extern fixed_queue_t *btu_hci_msg_queue; extern void btm_process_cancel_complete(UINT8 status, UINT8 mode); extern void btm_ble_test_command_complete(UINT8 *p); @@ -1009,9 +1008,7 @@ static void btu_hcif_command_complete_evt(BT_HDR *response, void *context) event->event = BTU_POST_TO_TASK_NO_GOOD_HORRIBLE_HACK; - fixed_queue_enqueue(btu_hci_msg_queue, event); - // ke_event_set(KE_EVENT_BTU_TASK_THREAD); - btu_task_post(SIG_BTU_WORK, TASK_POST_BLOCKING); + btu_task_post(SIG_BTU_HCI_MSG, event, TASK_POST_BLOCKING); } @@ -1209,9 +1206,7 @@ static void btu_hcif_command_status_evt(uint8_t status, BT_HDR *command, void *c event->event = BTU_POST_TO_TASK_NO_GOOD_HORRIBLE_HACK; - fixed_queue_enqueue(btu_hci_msg_queue, event); - //ke_event_set(KE_EVENT_BTU_TASK_THREAD); - btu_task_post(SIG_BTU_WORK, TASK_POST_BLOCKING); + btu_task_post(SIG_BTU_HCI_MSG, event, TASK_POST_BLOCKING); } /******************************************************************************* diff --git a/components/bt/bluedroid/stack/btu/btu_init.c b/components/bt/bluedroid/stack/btu/btu_init.c index df387bceb3..5ebb6edfc2 100644 --- a/components/bt/bluedroid/stack/btu/btu_init.c +++ b/components/bt/bluedroid/stack/btu/btu_init.c @@ -22,7 +22,6 @@ #include "bt_trace.h" #include "controller.h" #include "alarm.h" -#include "fixed_queue.h" #include "hash_map.h" #include "hash_functions.h" #include "thread.h" @@ -44,28 +43,14 @@ #endif #endif -// extern fixed_queue_t *btif_msg_queue; - -// Communication queue from bta thread to bt_workqueue. -fixed_queue_t *btu_bta_msg_queue; - -// Communication queue from hci thread to bt_workqueue. -extern fixed_queue_t *btu_hci_msg_queue; - -// General timer queue. -fixed_queue_t *btu_general_alarm_queue; hash_map_t *btu_general_alarm_hash_map; pthread_mutex_t btu_general_alarm_lock; static const size_t BTU_GENERAL_ALARM_HASH_MAP_SIZE = 34; -// Oneshot timer queue. -fixed_queue_t *btu_oneshot_alarm_queue; hash_map_t *btu_oneshot_alarm_hash_map; pthread_mutex_t btu_oneshot_alarm_lock; static const size_t BTU_ONESHOT_ALARM_HASH_MAP_SIZE = 34; -// l2cap timer queue. -fixed_queue_t *btu_l2cap_alarm_queue; hash_map_t *btu_l2cap_alarm_hash_map; pthread_mutex_t btu_l2cap_alarm_lock; static const size_t BTU_L2CAP_ALARM_HASH_MAP_SIZE = 34; @@ -156,11 +141,6 @@ void BTU_StartUp(void) memset (&btu_cb, 0, sizeof (tBTU_CB)); btu_cb.trace_level = HCI_INITIAL_TRACE_LEVEL; - btu_bta_msg_queue = fixed_queue_new(SIZE_MAX); - if (btu_bta_msg_queue == NULL) { - goto error_exit; - } - btu_general_alarm_hash_map = hash_map_new(BTU_GENERAL_ALARM_HASH_MAP_SIZE, hash_function_pointer, NULL, (data_free_fn)osi_alarm_free, NULL); if (btu_general_alarm_hash_map == NULL) { @@ -169,11 +149,6 @@ void BTU_StartUp(void) pthread_mutex_init(&btu_general_alarm_lock, NULL); - btu_general_alarm_queue = fixed_queue_new(SIZE_MAX); - if (btu_general_alarm_queue == NULL) { - goto error_exit; - } - btu_oneshot_alarm_hash_map = hash_map_new(BTU_ONESHOT_ALARM_HASH_MAP_SIZE, hash_function_pointer, NULL, (data_free_fn)osi_alarm_free, NULL); if (btu_oneshot_alarm_hash_map == NULL) { @@ -182,11 +157,6 @@ void BTU_StartUp(void) pthread_mutex_init(&btu_oneshot_alarm_lock, NULL); - btu_oneshot_alarm_queue = fixed_queue_new(SIZE_MAX); - if (btu_oneshot_alarm_queue == NULL) { - goto error_exit; - } - btu_l2cap_alarm_hash_map = hash_map_new(BTU_L2CAP_ALARM_HASH_MAP_SIZE, hash_function_pointer, NULL, (data_free_fn)osi_alarm_free, NULL); if (btu_l2cap_alarm_hash_map == NULL) { @@ -195,18 +165,11 @@ void BTU_StartUp(void) pthread_mutex_init(&btu_l2cap_alarm_lock, NULL); - btu_l2cap_alarm_queue = fixed_queue_new(SIZE_MAX); - if (btu_l2cap_alarm_queue == NULL) { - goto error_exit; - } - xBtuQueue = xQueueCreate(BTU_QUEUE_NUM, sizeof(BtTaskEvt_t)); xTaskCreatePinnedToCore(btu_task_thread_handler, BTU_TASK_NAME, BTU_TASK_STACK_SIZE, NULL, BTU_TASK_PRIO, &xBtuTaskHandle, 0); - btu_task_post(SIG_BTU_START_UP, TASK_POST_BLOCKING); - /* - // Continue startup on bt workqueue thread. - thread_post(bt_workqueue_thread, btu_task_start_up, NULL); - */ + + btu_task_post(SIG_BTU_START_UP, NULL, TASK_POST_BLOCKING); + return; error_exit:; @@ -218,36 +181,24 @@ void BTU_ShutDown(void) { btu_task_shut_down(); - fixed_queue_free(btu_bta_msg_queue, NULL); - hash_map_free(btu_general_alarm_hash_map); pthread_mutex_destroy(&btu_general_alarm_lock); - fixed_queue_free(btu_general_alarm_queue, NULL); hash_map_free(btu_oneshot_alarm_hash_map); pthread_mutex_destroy(&btu_oneshot_alarm_lock); - fixed_queue_free(btu_oneshot_alarm_queue, NULL); hash_map_free(btu_l2cap_alarm_hash_map); pthread_mutex_destroy(&btu_l2cap_alarm_lock); - fixed_queue_free(btu_l2cap_alarm_queue, NULL); - //thread_free(bt_workqueue_thread); vTaskDelete(xBtuTaskHandle); vQueueDelete(xBtuQueue); - btu_bta_msg_queue = NULL; - btu_general_alarm_hash_map = NULL; - btu_general_alarm_queue = NULL; btu_oneshot_alarm_hash_map = NULL; - btu_oneshot_alarm_queue = NULL; btu_l2cap_alarm_hash_map = NULL; - btu_l2cap_alarm_queue = NULL; -// bt_workqueue_thread = NULL; xBtuTaskHandle = NULL; xBtuQueue = 0; } @@ -269,21 +220,3 @@ UINT16 BTU_BleAclPktSize(void) return 0; #endif } -/******************************************************************************* -** -** Function btu_uipc_rx_cback -** -** Description -** -** -** Returns void -** -*******************************************************************************/ -/* -void btu_uipc_rx_cback(BT_HDR *p_msg) { - assert(p_msg != NULL); - BT_TRACE(TRACE_LAYER_BTM, TRACE_TYPE_DEBUG, "btu_uipc_rx_cback event 0x%x," - " len %d, offset %d", p_msg->event, p_msg->len, p_msg->offset); - fixed_queue_enqueue(btu_hci_msg_queue, p_msg); -} -*/ diff --git a/components/bt/bluedroid/stack/btu/btu_task.c b/components/bt/bluedroid/stack/btu/btu_task.c index 5d7b1ec60b..0f0b3ec9bd 100644 --- a/components/bt/bluedroid/stack/btu/btu_task.c +++ b/components/bt/bluedroid/stack/btu/btu_task.c @@ -27,7 +27,6 @@ #include "btm_api.h" #include "btm_int.h" #include "btu.h" -#include "fixed_queue.h" #include "gki.h" #include "hash_map.h" #include "hcimsgs.h" @@ -94,34 +93,17 @@ extern void BTE_InitStack(void); tBTU_CB btu_cb; #endif -// Communication queue between btu_task and bta. -extern fixed_queue_t *btu_bta_msg_queue; - -// alarm queue between btu_task and bta -extern fixed_queue_t *btu_bta_alarm_queue; - -// Communication queue between btu_task and hci. -extern fixed_queue_t *btu_hci_msg_queue; - -// General timer queue. -extern fixed_queue_t *btu_general_alarm_queue; extern hash_map_t *btu_general_alarm_hash_map; extern pthread_mutex_t btu_general_alarm_lock; // Oneshot timer queue. -extern fixed_queue_t *btu_oneshot_alarm_queue; extern hash_map_t *btu_oneshot_alarm_hash_map; extern pthread_mutex_t btu_oneshot_alarm_lock; // l2cap timer queue. -extern fixed_queue_t *btu_l2cap_alarm_queue; extern hash_map_t *btu_l2cap_alarm_hash_map; extern pthread_mutex_t btu_l2cap_alarm_lock; -extern fixed_queue_t *event_queue; -//extern fixed_queue_t *btif_msg_queue; - -//extern thread_t *bt_workqueue_thread; extern xTaskHandle xBtuTaskHandle; extern xQueueHandle xBtuQueue; extern bluedroid_init_done_cb_t bluedroid_init_done_cb; @@ -137,87 +119,6 @@ static void btu_hci_msg_process(BT_HDR *p_msg); static void btu_bta_alarm_process(TIMER_LIST_ENT *p_tle); #endif -void btu_hci_msg_ready(fixed_queue_t *queue) -{ - BT_HDR *p_msg; - - while (!fixed_queue_is_empty(queue)) { - p_msg = (BT_HDR *)fixed_queue_dequeue(queue); - btu_hci_msg_process(p_msg); - } -} - -void btu_general_alarm_ready(fixed_queue_t *queue) -{ - TIMER_LIST_ENT *p_tle; - - while (!fixed_queue_is_empty(queue)) { - p_tle = (TIMER_LIST_ENT *)fixed_queue_dequeue(queue); - btu_general_alarm_process(p_tle); - } -} - -void btu_oneshot_alarm_ready(fixed_queue_t *queue) -{ - TIMER_LIST_ENT *p_tle; - - while (!fixed_queue_is_empty(queue)) { - p_tle = (TIMER_LIST_ENT *)fixed_queue_dequeue(queue); - btu_general_alarm_process(p_tle); - - switch (p_tle->event) { -#if (defined(BLE_INCLUDED) && BLE_INCLUDED == TRUE) - case BTU_TTYPE_BLE_RANDOM_ADDR: - btm_ble_timeout(p_tle); - break; -#endif - case BTU_TTYPE_USER_FUNC: { - tUSER_TIMEOUT_FUNC *p_uf = (tUSER_TIMEOUT_FUNC *)p_tle->param; - (*p_uf)(p_tle); - } - break; - - default: - // FAIL - LOG_ERROR("Received unexpected oneshot timer event:0x%x\n", - p_tle->event); - break; - } - } -} - -void btu_l2cap_alarm_ready(fixed_queue_t *queue) -{ - TIMER_LIST_ENT *p_tle; - - while (!fixed_queue_is_empty(queue)) { - p_tle = (TIMER_LIST_ENT *)fixed_queue_dequeue(queue); - btu_l2cap_alarm_process(p_tle); - } -} - -#if (defined(BTA_INCLUDED) && BTA_INCLUDED == TRUE) -void btu_bta_msg_ready(fixed_queue_t *queue) -{ - BT_HDR *p_msg; - - while (!fixed_queue_is_empty(queue)) { - p_msg = (BT_HDR *)fixed_queue_dequeue(queue); - bta_sys_event(p_msg); - } -} - -void btu_bta_alarm_ready(fixed_queue_t *queue) -{ - TIMER_LIST_ENT *p_tle; - - while (!fixed_queue_is_empty(queue)) { - p_tle = (TIMER_LIST_ENT *)fixed_queue_dequeue(queue); - btu_bta_alarm_process(p_tle); - } -} -#endif - static void btu_hci_msg_process(BT_HDR *p_msg) { /* Determine the input message type. */ @@ -317,47 +218,74 @@ void btu_task_thread_handler(void *arg) for (;;) { if (pdTRUE == xQueueReceive(xBtuQueue, &e, (portTickType)portMAX_DELAY)) { - if (e.sig == SIG_BTU_WORK) { - fixed_queue_process(btu_hci_msg_queue); -#if (defined(BTA_INCLUDED) && BTA_INCLUDED == TRUE) - fixed_queue_process(btu_bta_msg_queue); - fixed_queue_process(btu_bta_alarm_queue); -#endif - fixed_queue_process(btu_general_alarm_queue); - fixed_queue_process(btu_oneshot_alarm_queue); - fixed_queue_process(btu_l2cap_alarm_queue); - } else if (e.sig == SIG_BTU_START_UP) { + switch (e.sig) { + case SIG_BTU_START_UP: btu_task_start_up(); + break; + case SIG_BTU_HCI_MSG: + btu_hci_msg_process((BT_HDR *)e.par); + break; +#if (defined(BTA_INCLUDED) && BTA_INCLUDED == TRUE) + case SIG_BTU_BTA_MSG: + bta_sys_event((BT_HDR *)e.par); + break; + case SIG_BTU_BTA_ALARM: + btu_bta_alarm_process((TIMER_LIST_ENT *)e.par); + break; +#endif + case SIG_BTU_GENERAL_ALARM: + btu_general_alarm_process((TIMER_LIST_ENT *)e.par); + break; + case SIG_BTU_ONESHOT_ALARM: { + TIMER_LIST_ENT *p_tle = (TIMER_LIST_ENT *)e.par; + btu_general_alarm_process(p_tle); + + switch (p_tle->event) { +#if (defined(BLE_INCLUDED) && BLE_INCLUDED == TRUE) + case BTU_TTYPE_BLE_RANDOM_ADDR: + btm_ble_timeout(p_tle); + break; +#endif + case BTU_TTYPE_USER_FUNC: { + tUSER_TIMEOUT_FUNC *p_uf = (tUSER_TIMEOUT_FUNC *)p_tle->param; + (*p_uf)(p_tle); + break; + } + default: + // FAIL + LOG_ERROR("Received unexpected oneshot timer event:0x%x\n", p_tle->event); + break; + } + break; + } + case SIG_BTU_L2CAP_ALARM: + btu_l2cap_alarm_process((TIMER_LIST_ENT *)e.par); + break; + default: + break; } } } } -void btu_task_post(uint32_t sig, task_post_t timeout) +task_post_status_t btu_task_post(uint32_t sig, void *param, task_post_t timeout) { BtTaskEvt_t evt; evt.sig = sig; - evt.par = 0; + evt.par = param; if (xQueueSend(xBtuQueue, &evt, timeout) != pdTRUE) { LOG_ERROR("xBtuQueue failed\n"); + return TASK_POST_FAIL; } + + return TASK_POST_SUCCESS; } void btu_task_start_up(void) { - -#if (defined(BTA_INCLUDED) && BTA_INCLUDED == TRUE) - fixed_queue_register_dequeue(btu_bta_msg_queue, btu_bta_msg_ready); -#endif - - fixed_queue_register_dequeue(btu_hci_msg_queue, btu_hci_msg_ready); - fixed_queue_register_dequeue(btu_general_alarm_queue, btu_general_alarm_ready); - fixed_queue_register_dequeue(btu_oneshot_alarm_queue, btu_oneshot_alarm_ready); - fixed_queue_register_dequeue(btu_l2cap_alarm_queue, btu_l2cap_alarm_ready); - /* Initialize the mandatory core stack control blocks (BTU, BTM, L2CAP, and SDP) */ @@ -381,12 +309,7 @@ void btu_task_start_up(void) void btu_task_shut_down(void) { - fixed_queue_unregister_dequeue(btu_general_alarm_queue); - fixed_queue_unregister_dequeue(btu_oneshot_alarm_queue); - fixed_queue_unregister_dequeue(btu_l2cap_alarm_queue); - #if (defined(BTA_INCLUDED) && BTA_INCLUDED == TRUE) - fixed_queue_unregister_dequeue(btu_bta_msg_queue); bta_sys_free(); #endif @@ -515,9 +438,7 @@ void btu_general_alarm_cb(void *data) assert(data != NULL); TIMER_LIST_ENT *p_tle = (TIMER_LIST_ENT *)data; - fixed_queue_enqueue(btu_general_alarm_queue, p_tle); - //ke_event_set(KE_EVENT_BTU_TASK_THREAD); - btu_task_post(SIG_BTU_WORK, TASK_POST_BLOCKING); + btu_task_post(SIG_BTU_GENERAL_ALARM, p_tle, TASK_POST_BLOCKING); } void btu_start_timer(TIMER_LIST_ENT *p_tle, UINT16 type, UINT32 timeout_sec) @@ -606,9 +527,7 @@ static void btu_l2cap_alarm_cb(void *data) assert(data != NULL); TIMER_LIST_ENT *p_tle = (TIMER_LIST_ENT *)data; - fixed_queue_enqueue(btu_l2cap_alarm_queue, p_tle); - //ke_event_set(KE_EVENT_BTU_TASK_THREAD); - btu_task_post(SIG_BTU_WORK, TASK_POST_BLOCKING); + btu_task_post(SIG_BTU_L2CAP_ALARM, p_tle, TASK_POST_BLOCKING); } void btu_start_quick_timer(TIMER_LIST_ENT *p_tle, UINT16 type, UINT32 timeout_ticks) @@ -674,9 +593,7 @@ void btu_oneshot_alarm_cb(void *data) btu_stop_timer_oneshot(p_tle); - fixed_queue_enqueue(btu_oneshot_alarm_queue, p_tle); - //ke_event_set(KE_EVENT_BTU_TASK_THREAD); - btu_task_post(SIG_BTU_WORK, TASK_POST_BLOCKING); + btu_task_post(SIG_BTU_ONESHOT_ALARM, p_tle, TASK_POST_BLOCKING); } /* -- 2.40.0