蓝牙协议栈消息的关联
版權(quán)聲明:本文為博主原創(chuàng)文章,未經(jīng)博主允許不得轉(zhuǎn)載。
https://blog.csdn.net/huangweiqing80/article/details/82707399
bluetooth.c:enable
調(diào)用協(xié)議棧函數(shù):stack_manager_get_interface()->start_up_stack_async();
system/bt/btif/src/stack_manager.c
static void event_start_up_stack(UNUSED_ATTR void *context) {if (stack_is_running) {LOG_DEBUG("%s stack already brought up.", __func__);return;}ensure_stack_is_initialized();LOG_DEBUG("%s is bringing up the stack.", __func__);hack_future = future_new();// Include this for now to put btif config into a shutdown-able statemodule_start_up(get_module(BTIF_CONFIG_MODULE));bte_main_enable();if (future_await(hack_future) != FUTURE_SUCCESS) {stack_is_running = true; // So stack shutdown actually happensevent_shut_down_stack(NULL);return;}stack_is_running = true;LOG_DEBUG("%s finished", __func__);btif_thread_post(event_signal_stack_up, NULL); }
system/bt/main/bte_main.c
/****************************************************************************** ** ** Function bte_main_enable ** ** Description BTE MAIN API - Creates all the BTE tasks. Should be called ** part of the Bluetooth stack enable sequence ** ** Returns None ** ******************************************************************************/ void bte_main_enable() { APPL_TRACE_DEBUG("%s", __FUNCTION__); module_start_up(get_module(BTSNOOP_MODULE)); module_start_up(get_module(HCI_MODULE)); BTU_StartUp(); }system/bt/stack/btu/btu_init.c
/***************************************************************************** ** ** Function BTU_StartUp ** ** Description Initializes the BTU control block. ** ** NOTE: Must be called before creating any tasks ** (RPC, BTU, HCIT, APPL, etc.) ** ** Returns void ** ******************************************************************************/ 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)alarm_free, NULL);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, NULL);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, NULL);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:;LOG_ERROR("%s Unable to allocate resources for bt_workqueue", __func__);BTU_ShutDown(); }BTU_StartUp函數(shù)里面主要做的就是
1.初始化各個消息隊(duì)列;如 btu_bta_msg_queue = fixed_queue_new(SIZE_MAX);
2.啟動工作線程:thread_post(bt_workqueue_thread, btu_task_start_up, NULL);
參考Bluedroid中的線程介紹
所以btu_task_start_up函數(shù)會被得到調(diào)用
system/bt/stack/btu/btu_task.c
通過fixed_queue_register_dequeue方法來關(guān)聯(lián)消息隊(duì)列和讀取線程。如
fixed_queue_register_dequeue(btu_bta_msg_queue,
thread_get_reactor(bt_workqueue_thread),
btu_bta_msg_ready,
NULL);
這樣當(dāng)有消息加入到btu_bta_msg_queue隊(duì)列,即有消息發(fā)送到btu_bta_msg_queue隊(duì)列;btu_bta_msg_ready就會被調(diào)用,btu_bta_msg_ready函數(shù)就是消息的處理方法
其他隊(duì)列也類似,我們可以看到在btu task啟動的時候,會關(guān)聯(lián)相應(yīng)的隊(duì)列,如btu_bta_msg_queue、btu_hci_msg_queue、btu_general_alarm_queue、btu_oneshot_alarm_queue、btu_l2cap_alarm_queue
總結(jié)
以上是生活随笔為你收集整理的蓝牙协议栈消息的关联的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 管理驾驶舱(Management Coc
- 下一篇: 对称加密+非对称加密,实现数据安全传输