日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

蓝牙协议栈消息的关联

發布時間:2023/12/20 编程问答 25 豆豆
生活随笔 收集整理的這篇文章主要介紹了 蓝牙协议栈消息的关联 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

版權聲明:本文為博主原創文章,未經博主允許不得轉載。
https://blog.csdn.net/huangweiqing80/article/details/82707399
bluetooth.c:enable

static int enable(bool start_restricted) {LOG_INFO(LOG_TAG, "%s: start restricted = %d", __func__, start_restricted);restricted_mode = start_restricted;if (!interface_ready())return BT_STATUS_NOT_READY;stack_manager_get_interface()->start_up_stack_async();return BT_STATUS_SUCCESS; }

調用協議棧函數:stack_manager_get_interface()->start_up_stack_async();
system/bt/btif/src/stack_manager.c

static void start_up_stack_async(void) {thread_post(management_thread, event_start_up_stack, NULL); }
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函數里面主要做的就是
1.初始化各個消息隊列;如 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函數會被得到調用
system/bt/stack/btu/btu_task.c

void btu_task_start_up(UNUSED_ATTR void *context) {BT_TRACE(TRACE_LAYER_BTU, TRACE_TYPE_API,"btu_task pending for preload complete event");LOG_INFO("Bluetooth chip preload is complete");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 any optional stack components */BTE_InitStack();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*/ #if ( BT_USE_TRACES==TRUE )module_init(get_module(BTE_LOGMSG_MODULE)); #endif// Inform the bt jni thread initialization is ok.btif_transfer_context(btif_init_ok, 0, NULL, 0, NULL);fixed_queue_register_dequeue(btu_bta_msg_queue,thread_get_reactor(bt_workqueue_thread),btu_bta_msg_ready,NULL);fixed_queue_register_dequeue(btu_hci_msg_queue,thread_get_reactor(bt_workqueue_thread),btu_hci_msg_ready,NULL);fixed_queue_register_dequeue(btu_general_alarm_queue,thread_get_reactor(bt_workqueue_thread),btu_general_alarm_ready,NULL);fixed_queue_register_dequeue(btu_oneshot_alarm_queue,thread_get_reactor(bt_workqueue_thread),btu_oneshot_alarm_ready,NULL);fixed_queue_register_dequeue(btu_l2cap_alarm_queue,thread_get_reactor(bt_workqueue_thread),btu_l2cap_alarm_ready,NULL); }

通過fixed_queue_register_dequeue方法來關聯消息隊列和讀取線程。如
fixed_queue_register_dequeue(btu_bta_msg_queue,
thread_get_reactor(bt_workqueue_thread),
btu_bta_msg_ready,
NULL);
這樣當有消息加入到btu_bta_msg_queue隊列,即有消息發送到btu_bta_msg_queue隊列;btu_bta_msg_ready就會被調用,btu_bta_msg_ready函數就是消息的處理方法
其他隊列也類似,我們可以看到在btu task啟動的時候,會關聯相應的隊列,如btu_bta_msg_queue、btu_hci_msg_queue、btu_general_alarm_queue、btu_oneshot_alarm_queue、btu_l2cap_alarm_queue

總結

以上是生活随笔為你收集整理的蓝牙协议栈消息的关联的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。