From 307381ef1ed1b434c956a9a98ca25ba6b415d7c7 Mon Sep 17 00:00:00 2001 From: Chris Manton Date: Thu, 4 Sep 2014 19:48:49 -0700 Subject: [PATCH] Remove btu_task and replace with bt_workqueue reactor --- bta/sys/bta_sys_main.c | 11 ++- main/bte_main.c | 115 ++++------------------- stack/btu/btu_init.c | 144 ++++++++++++++++++++++++---- stack/btu/btu_task.c | 247 +++++++++++++++++++++---------------------------- stack/include/btu.h | 10 +- 5 files changed, 266 insertions(+), 261 deletions(-) diff --git a/bta/sys/bta_sys_main.c b/bta/sys/bta_sys_main.c index c5eeae1df..939d25ed0 100644 --- a/bta/sys/bta_sys_main.c +++ b/bta/sys/bta_sys_main.c @@ -24,6 +24,7 @@ #include #define LOG_TAG "bta_sys_main" #include +#include #include "alarm.h" #include "btm_api.h" @@ -36,7 +37,8 @@ #include "hash_functions.h" #include "hash_map.h" #include "ptim.h" -#include +#include "osi.h" +#include "thread.h" #if( defined BTA_AR_INCLUDED ) && (BTA_AR_INCLUDED == TRUE) #include "bta_ar_api.h" #endif @@ -51,6 +53,7 @@ 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; +extern thread_t *bt_workqueue_thread; /* trace level */ /* TODO Bluedroid - Hard-coded trace levels - Needs to be configurable */ @@ -59,6 +62,7 @@ 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, UNUSED_ATTR void *context); static const tBTA_SYS_REG bta_sys_hw_reg = { @@ -180,6 +184,11 @@ BTA_API void bta_sys_init(void) hash_function_pointer, NULL, (data_free_fn)alarm_free); btu_bta_alarm_queue = fixed_queue_new(SIZE_MAX); + fixed_queue_register_dequeue(btu_bta_alarm_queue, + thread_get_reactor(bt_workqueue_thread), + btu_bta_alarm_ready, + NULL); + bta_sys_cb.task_id = GKI_get_taskid(); appl_trace_level = APPL_INITIAL_TRACE_LEVEL; diff --git a/main/bte_main.c b/main/bte_main.c index de53464d9..e9edb9e75 100755 --- a/main/bte_main.c +++ b/main/bte_main.c @@ -43,6 +43,7 @@ #include "btsnoop.h" #include "bt_utils.h" #include "fixed_queue.h" +#include "future.h" #include "gki.h" #include "hash_functions.h" #include "hash_map.h" @@ -76,30 +77,6 @@ BOOLEAN hci_logging_config = FALSE; /* configured from bluetooth framework */ BOOLEAN hci_save_log = FALSE; /* save a copy of the log before starting again */ char hci_logfile[256] = HCI_LOGGING_FILENAME; -// Communication queue between btu_task and bta. -fixed_queue_t *btu_bta_msg_queue; - -// Communication queue between btu_task and hci. -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 = 17; - -// 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 = 17; - -// 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 = 17; - /******************************************************************************* ** Static variables *******************************************************************************/ @@ -109,15 +86,9 @@ static const hci_callbacks_t hci_callbacks; // Lock to serialize shutdown requests from upper layer. static pthread_mutex_t shutdown_lock; -// These are temporary so we can run the new HCI code -// with the old upper stack. -static fixed_queue_t *upbound_data; -static thread_t *dispatch_thread; - /******************************************************************************* ** Static functions *******************************************************************************/ -static void dump_upbound_data_to_btu(fixed_queue_t *queue, void *context); /******************************************************************************* ** Externs @@ -129,6 +100,8 @@ void bte_load_conf(const char *p_path); extern void bte_load_ble_conf(const char *p_path); bt_bdaddr_t btif_local_bd_addr; +fixed_queue_t *btu_hci_msg_queue; + /****************************************************************************** ** ** Function bte_main_boot_entry @@ -149,17 +122,13 @@ void bte_main_boot_entry(void) btsnoop = btsnoop_get_interface(); - upbound_data = fixed_queue_new(SIZE_MAX); - dispatch_thread = thread_new("hci_dispatch"); - - fixed_queue_register_dequeue( - upbound_data, - thread_get_reactor(dispatch_thread), - dump_upbound_data_to_btu, - NULL - ); + btu_hci_msg_queue = fixed_queue_new(SIZE_MAX); + if (btu_hci_msg_queue == NULL) { + ALOGE("%s unable to allocate hci message queue.", __func__); + return; + } - data_dispatcher_register_default(hci->upward_dispatcher, upbound_data); + data_dispatcher_register_default(hci->upward_dispatcher, btu_hci_msg_queue); bte_load_conf(BTE_STACK_CONF_FILE); #if (defined(BLE_INCLUDED) && (BLE_INCLUDED == TRUE)) @@ -186,12 +155,10 @@ void bte_main_boot_entry(void) ******************************************************************************/ void bte_main_shutdown() { - thread_free(dispatch_thread); data_dispatcher_register_default(hci_layer_get_interface()->upward_dispatcher, NULL); - fixed_queue_free(upbound_data, NULL); + fixed_queue_free(btu_hci_msg_queue, NULL); - dispatch_thread = NULL; - upbound_data = NULL; + btu_hci_msg_queue = NULL; pthread_mutex_destroy(&shutdown_lock); GKI_shutdown(); @@ -211,25 +178,7 @@ void bte_main_enable() { APPL_TRACE_DEBUG("%s", __FUNCTION__); - btu_bta_msg_queue = fixed_queue_new(SIZE_MAX); - btu_hci_msg_queue = fixed_queue_new(SIZE_MAX); - - btu_general_alarm_hash_map = hash_map_new(BTU_GENERAL_ALARM_HASH_MAP_SIZE, - hash_function_pointer, NULL, (data_free_fn)alarm_free); - pthread_mutex_init(&btu_general_alarm_lock, NULL); - btu_general_alarm_queue = fixed_queue_new(SIZE_MAX); - - btu_oneshot_alarm_hash_map = hash_map_new(BTU_ONESHOT_ALARM_HASH_MAP_SIZE, - hash_function_pointer, NULL, (data_free_fn)alarm_free); - pthread_mutex_init(&btu_oneshot_alarm_lock, NULL); - btu_oneshot_alarm_queue = fixed_queue_new(SIZE_MAX); - - btu_l2cap_alarm_hash_map = hash_map_new(BTU_L2CAP_ALARM_HASH_MAP_SIZE, - hash_function_pointer, NULL, (data_free_fn)alarm_free); - pthread_mutex_init(&btu_l2cap_alarm_lock, NULL); - btu_l2cap_alarm_queue = fixed_queue_new(SIZE_MAX); - - BTU_StartUp(); +// BTU_StartUp(); btsnoop->set_is_running(hci_logging_enabled || hci_logging_config); assert(hci->start_up_async(btif_local_bd_addr.address, &hci_callbacks)); @@ -260,21 +209,6 @@ void bte_main_disable(void) } BTU_ShutDown(); - - fixed_queue_free(btu_bta_msg_queue, NULL); - fixed_queue_free(btu_hci_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); } /****************************************************************************** @@ -459,21 +393,13 @@ static void hci_startup_cb(bool success) APPL_TRACE_EVENT("HC preload_cb %d [1:SUCCESS 0:FAIL]", success); if (success) { - /* notify BTU task that libbt-hci is ready */ - GKI_send_event(BTU_TASK, BT_EVT_PRELOAD_CMPL); + BTU_StartUp(); } else { - /* Notify BTIF_TASK that the init procedure had failed*/ - GKI_send_event(BTIF_TASK, BT_EVT_HARDWARE_INIT_FAIL); + ALOGE("%s hci startup failed", __func__); + // TODO(cmanton) Initiate shutdown sequence. } } -static void dump_upbound_data_to_btu(fixed_queue_t *queue, UNUSED_ATTR void *context) { - fixed_queue_enqueue(btu_hci_msg_queue, fixed_queue_dequeue(queue)); - // Signal the target thread work is ready. - GKI_send_event(BTU_TASK, (UINT16)EVENT_MASK(BTU_HCI_RCV_MBOX)); - -} - /****************************************************************************** ** ** Function tx_result @@ -491,21 +417,14 @@ static void dump_upbound_data_to_btu(fixed_queue_t *queue, UNUSED_ATTR void *con ** boundary. The 'p_buf' is not intended to be used here ** but might point to data portion in data-path buffer. ** -** Returns bt_hc_status_t +** Returns void ** ******************************************************************************/ -static void tx_result(void *p_buf, bool all_fragments_sent) -{ +static void tx_result(void *p_buf, bool all_fragments_sent) { if (!all_fragments_sent) - { fixed_queue_enqueue(btu_hci_msg_queue, p_buf); - // Signal the target thread work is ready. - GKI_send_event(BTU_TASK, (UINT16)EVENT_MASK(BTU_HCI_RCV_MBOX)); - } else - { GKI_freebuf(p_buf); - } } /***************************************************************************** diff --git a/stack/btu/btu_init.c b/stack/btu/btu_init.c index 4e5c4fa88..423cc880a 100644 --- a/stack/btu/btu_init.c +++ b/stack/btu/btu_init.c @@ -16,22 +16,23 @@ * ******************************************************************************/ -/****************************************************************************** - * - * This module contains the routines that load and shutdown the core stack - * components. - * - ******************************************************************************/ +#include #include "bt_target.h" +#define LOG_TAG "bt_task" +#include +#include #include #include "dyn_mem.h" +#include "alarm.h" #include "fixed_queue.h" +#include "hash_functions.h" #include "hash_map.h" #include "btu.h" #include "btm_int.h" #include "sdpint.h" +#include "thread.h" #include "l2c_int.h" #if (BLE_INCLUDED == TRUE) @@ -42,17 +43,45 @@ #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 = 17; + +// 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 = 17; + +// 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 = 17; + +thread_t *bt_workqueue_thread; +static const char *BT_WORKQUEUE_NAME = "bt_workqueue"; + extern void PLATFORM_DisableHciTransport(UINT8 bDisable); /***************************************************************************** ** V A R I A B L E S * ******************************************************************************/ +// TODO(cmanton) Move this out of this file const BD_ADDR BT_BD_ANY = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff}; -/***************************************************************************** -** F U N C T I O N S * -******************************************************************************/ +void btu_task_start_up(void *context); +void btu_task_shut_down(void *context); + /***************************************************************************** ** ** Function btu_init_core @@ -126,17 +155,98 @@ void BTU_StartUp(void) btu_cb.hci_cmd_cb[i].cmd_window = 1; } - GKI_create_task(btu_task, BTU_TASK, "BTU"); + 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)alarm_free); + if (btu_general_alarm_hash_map == NULL) + goto error_exit; + + if (pthread_mutex_init(&btu_general_alarm_lock, NULL)) + goto error_exit; + + 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)alarm_free); + if (btu_oneshot_alarm_hash_map == NULL) + goto error_exit; + + if (pthread_mutex_init(&btu_oneshot_alarm_lock, NULL)) + goto error_exit; + + 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)alarm_free); + if (btu_l2cap_alarm_hash_map == NULL) + goto error_exit; + + if (pthread_mutex_init(&btu_l2cap_alarm_lock, NULL)) + goto error_exit; + + btu_l2cap_alarm_queue = fixed_queue_new(SIZE_MAX); + if (btu_l2cap_alarm_queue == NULL) + goto error_exit; + + bt_workqueue_thread = thread_new(BT_WORKQUEUE_NAME); + if (bt_workqueue_thread == NULL) + goto error_exit; + + // Continue startup on bt workqueue thread. + thread_post(bt_workqueue_thread, btu_task_start_up, NULL); + return; + + error_exit:; + ALOGE("%s Unable to allocate resources for bt_workqueue", __func__); + BTU_ShutDown(); } void BTU_ShutDown(void) { - GKI_destroy_task(BTU_TASK); for (int i = 0; i < BTU_MAX_LOCAL_CTRLS; ++i) { while (!GKI_queue_is_empty(&btu_cb.hci_cmd_cb[i].cmd_xmit_q)) GKI_freebuf(GKI_dequeue(&btu_cb.hci_cmd_cb[i].cmd_xmit_q)); while (!GKI_queue_is_empty(&btu_cb.hci_cmd_cb[i].cmd_cmpl_q)) GKI_freebuf(GKI_dequeue(&btu_cb.hci_cmd_cb[i].cmd_cmpl_q)); } + + fixed_queue_unregister_dequeue(btu_l2cap_alarm_queue); + fixed_queue_unregister_dequeue(btu_general_alarm_queue); + + 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); + + 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; } /***************************************************************************** @@ -180,11 +290,9 @@ UINT16 BTU_BleAclPktSize(void) ** Returns void ** *******************************************************************************/ -void btu_uipc_rx_cback(BT_HDR *p_msg) -{ - 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); - // Signal the target thread work is ready. - GKI_send_event(BTU_TASK, (UINT16)EVENT_MASK(BTU_HCI_RCV_MBOX)); +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/stack/btu/btu_task.c b/stack/btu/btu_task.c index 3daa167b0..79ea534e7 100644 --- a/stack/btu/btu_task.c +++ b/stack/btu/btu_task.c @@ -16,25 +16,13 @@ * ******************************************************************************/ -/****************************************************************************** - * - * This file contains the main Bluetooth Upper Layer processing loop. - * The Broadcom implementations of L2CAP RFCOMM, SDP and the BTIf run as one - * GKI task. This btu_task switches between them. - * - * Note that there will always be an L2CAP, but there may or may not be an - * RFCOMM or SDP. Whether these layers are present or not is determined by - * compile switches. - * - ******************************************************************************/ +#define LOG_TAG "btu_task" #include - -#define LOG_TAG "btu_task" #include #include -#include #include +#include #include "alarm.h" #include "bt_target.h" @@ -46,6 +34,7 @@ #include "btm_int.h" #include "btu.h" #include "fixed_queue.h" +#include "future.h" #include "gki.h" #include "hash_map.h" #include "hcimsgs.h" @@ -54,7 +43,9 @@ #include "bt_utils.h" #include +#include "osi.h" #include "sdpint.h" +#include "thread.h" #if ( defined(RFCOMM_INCLUDED) && RFCOMM_INCLUDED == TRUE ) #include "port_api.h" @@ -170,11 +161,69 @@ 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; + /* Define a function prototype to allow a generic timeout handler */ typedef void (tUSER_TIMEOUT_FUNC) (TIMER_LIST_ENT *p_tle); static void btu_l2cap_alarm_process(TIMER_LIST_ENT *p_tle); static void btu_general_alarm_process(TIMER_LIST_ENT *p_tle); +static void btu_bta_alarm_process(TIMER_LIST_ENT *p_tle); +static void btu_hci_msg_process(BT_HDR *p_msg); + +void btu_hci_msg_ready(fixed_queue_t *queue, UNUSED_ATTR void *context) { + BT_HDR *p_msg = (BT_HDR *)fixed_queue_dequeue(queue); + btu_hci_msg_process(p_msg); +} + +void btu_general_alarm_ready(fixed_queue_t *queue, UNUSED_ATTR void *context) { + TIMER_LIST_ENT *p_tle = (TIMER_LIST_ENT *)fixed_queue_dequeue(queue); + btu_general_alarm_process(p_tle); +} + +void btu_oneshot_alarm_ready(fixed_queue_t *queue, UNUSED_ATTR void *context) { + TIMER_LIST_ENT *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 + BTM_TRACE_WARNING("Received unexpected oneshot timer event:0x%x\n", + p_tle->event); + break; + } +} + +void btu_l2cap_alarm_ready(fixed_queue_t *queue, UNUSED_ATTR void *context) { + TIMER_LIST_ENT *p_tle = (TIMER_LIST_ENT *)fixed_queue_dequeue(queue); + btu_l2cap_alarm_process(p_tle); +} + +void btu_bta_msg_ready(fixed_queue_t *queue, UNUSED_ATTR void *context) { + BT_HDR *p_msg = (BT_HDR *)fixed_queue_dequeue(queue); + bta_sys_event(p_msg); +} + +void btu_bta_alarm_ready(fixed_queue_t *queue, UNUSED_ATTR void *context) { + TIMER_LIST_ENT *p_tle = (TIMER_LIST_ENT *)fixed_queue_dequeue(queue); + btu_bta_alarm_process(p_tle); +} static void btu_hci_msg_process(BT_HDR *p_msg) { /* Determine the input message type. */ @@ -354,146 +403,66 @@ static void btu_bta_alarm_process(TIMER_LIST_ENT *p_tle) { } } -/******************************************************************************* -** -** Function btu_task -** -** Description This is the main task of the Bluetooth Upper Layers unit. -** It sits in a loop waiting for messages, and dispatches them -** to the appropiate handlers. -** -** Returns should never return -** -*******************************************************************************/ -BTU_API void btu_task (void) -{ - UINT16 event; - BT_HDR *p_msg; - TIMER_LIST_ENT *p_tle; - UINT8 i; - UINT16 mask; - BOOLEAN handled; - - /* wait an event that HCISU is ready */ - BT_TRACE(TRACE_LAYER_BTU, TRACE_TYPE_API, - "btu_task pending for preload complete event"); - - for (;;) - { - event = GKI_wait (0xFFFF, 0); - if (event & EVENT_MASK(GKI_SHUTDOWN_EVT)) - { - /* indicates BT ENABLE abort */ - BT_TRACE(TRACE_LAYER_BTU, TRACE_TYPE_WARNING, - "btu_task start abort!"); - return; - } - else if (event & BT_EVT_PRELOAD_CMPL) - { - break; - } - else - { - BT_TRACE(TRACE_LAYER_BTU, TRACE_TYPE_WARNING, - "btu_task ignore evt %04x while pending for preload complete", - event); - } - } +void btu_task_start_up(UNUSED_ATTR void *context) { + BT_TRACE(TRACE_LAYER_BTU, TRACE_TYPE_API, + "btu_task pending for preload complete event"); + + ALOGI("Bluetooth chip preload is complete"); - BT_TRACE(TRACE_LAYER_BTU, TRACE_TYPE_API, - "btu_task received preload complete event"); + BT_TRACE(TRACE_LAYER_BTU, TRACE_TYPE_API, + "btu_task received preload complete event"); - /* Initialize the mandatory core stack control blocks - (BTU, BTM, L2CAP, and SDP) - */ - btu_init_core(); + /* Initialize the mandatory core stack control blocks + (BTU, BTM, L2CAP, and SDP) + */ + btu_init_core(); - /* Initialize any optional stack components */ - BTE_InitStack(); + /* Initialize any optional stack components */ + BTE_InitStack(); - bta_sys_init(); + bta_sys_init(); - /* Initialise platform trace levels at this point as BTE_InitStack() and bta_sys_init() - * reset the control blocks and preset the trace level with XXX_INITIAL_TRACE_LEVEL - */ + /* Initialise platform trace levels at this point as BTE_InitStack() and bta_sys_init() + * reset the control blocks and preset the trace level with XXX_INITIAL_TRACE_LEVEL + */ #if ( BT_USE_TRACES==TRUE ) - BTE_InitTraceLevels(); + BTE_InitTraceLevels(); #endif - // Inform the bt jni thread initialization is ok. - btif_transfer_context(btif_init_ok, 0, NULL, 0, NULL); - - raise_priority_a2dp(TASK_HIGH_BTU); + // Inform the bt jni thread initialization is ok. + btif_transfer_context(btif_init_ok, 0, NULL, 0, NULL); - /* Wait for, and process, events */ - for (;;) { - event = GKI_wait (0xFFFF, 0); - - // HCI message queue. - while (!fixed_queue_is_empty(btu_hci_msg_queue)) { - p_msg = (BT_HDR *)fixed_queue_dequeue(btu_hci_msg_queue); - btu_hci_msg_process(p_msg); - } + fixed_queue_register_dequeue(btu_bta_msg_queue, + thread_get_reactor(bt_workqueue_thread), + btu_bta_msg_ready, + NULL); - // General alarm queue. - while (!fixed_queue_is_empty(btu_general_alarm_queue)) { - p_tle = (TIMER_LIST_ENT *)fixed_queue_dequeue(btu_general_alarm_queue); - btu_general_alarm_process(p_tle); - } + fixed_queue_register_dequeue(btu_hci_msg_queue, + thread_get_reactor(bt_workqueue_thread), + btu_hci_msg_ready, + NULL); -#if defined(QUICK_TIMER_TICKS_PER_SEC) && (QUICK_TIMER_TICKS_PER_SEC > 0) - // L2CAP alarm queue. - while (!fixed_queue_is_empty(btu_l2cap_alarm_queue)) { - p_tle = (TIMER_LIST_ENT *)fixed_queue_dequeue(btu_l2cap_alarm_queue); - btu_l2cap_alarm_process(p_tle); - } -#endif // QUICK_TIMER + fixed_queue_register_dequeue(btu_general_alarm_queue, + thread_get_reactor(bt_workqueue_thread), + btu_general_alarm_ready, + NULL); - // BTA message queue. - while (!fixed_queue_is_empty(btu_bta_msg_queue)) { - p_msg = (BT_HDR *)fixed_queue_dequeue(btu_bta_msg_queue); - bta_sys_event(p_msg); - } + fixed_queue_register_dequeue(btu_oneshot_alarm_queue, + thread_get_reactor(bt_workqueue_thread), + btu_oneshot_alarm_ready, + NULL); - // BTA timer queue. - while (!fixed_queue_is_empty(btu_bta_alarm_queue)) { - p_tle = (TIMER_LIST_ENT *)fixed_queue_dequeue(btu_bta_alarm_queue); - btu_bta_alarm_process(p_tle); - } + fixed_queue_register_dequeue(btu_l2cap_alarm_queue, + thread_get_reactor(bt_workqueue_thread), + btu_l2cap_alarm_ready, + NULL); +} - while (!fixed_queue_is_empty(btu_oneshot_alarm_queue)) { - p_tle = (TIMER_LIST_ENT *)fixed_queue_dequeue(btu_oneshot_alarm_queue); - switch (p_tle->event) { -#if (defined(BLE_INCLUDED) && BLE_INCLUDED == TRUE) - case BTU_TTYPE_BLE_RANDOM_ADDR: - btm_ble_timeout(p_tle); - break; +void btu_task_shut_down(UNUSED_ATTR void *context) { +#if (defined(BTU_BTA_INCLUDED) && BTU_BTA_INCLUDED == TRUE) + bta_sys_free(); #endif - - case BTU_TTYPE_USER_FUNC: - { - tUSER_TIMEOUT_FUNC *p_uf = (tUSER_TIMEOUT_FUNC *)p_tle->param; - (*p_uf)(p_tle); - } - break; - - default: - // FAIL - BTM_TRACE_WARNING("Received unexpected oneshot timer event:0x%x\n", - p_tle->event); - break; - } - } - - if (event & EVENT_MASK(APPL_EVT_7)) - break; - } - - bta_sys_free(); - - btu_free_core(); - - return; + btu_free_core(); } /******************************************************************************* diff --git a/stack/include/btu.h b/stack/include/btu.h index 0cc1c5d33..45674876b 100644 --- a/stack/include/btu.h +++ b/stack/include/btu.h @@ -278,11 +278,11 @@ BTU_API extern const BD_ADDR BT_BD_ANY; /* Functions provided by btu_task.c ************************************ */ -BTU_API extern void btu_task (void); -BTU_API extern void btu_start_timer (TIMER_LIST_ENT *p_tle, UINT16 type, UINT32 timeout); -BTU_API extern void btu_stop_timer (TIMER_LIST_ENT *p_tle); -BTU_API extern void btu_start_timer_oneshot(TIMER_LIST_ENT *p_tle, UINT16 type, UINT32 timeout); -BTU_API extern void btu_stop_timer_oneshot(TIMER_LIST_ENT *p_tle); +extern void btu_start_timer (TIMER_LIST_ENT *p_tle, UINT16 type, UINT32 timeout); +extern void btu_stop_timer (TIMER_LIST_ENT *p_tle); +extern void btu_start_timer_oneshot(TIMER_LIST_ENT *p_tle, UINT16 type, UINT32 timeout); +extern void btu_stop_timer_oneshot(TIMER_LIST_ENT *p_tle); +extern UINT32 btu_remaining_time (TIMER_LIST_ENT *p_tle); BTU_API extern UINT32 btu_remaining_time (TIMER_LIST_ENT *p_tle); BTU_API extern void btu_uipc_rx_cback(BT_HDR *p_msg); -- 2.11.0