下面是BLE Wireless UART例子程序ApplMain.c中main_task最后调用的函数。其中处理了两类事件:gAppEvtMsgFromHostStack_c(the host to app message)和 gAppEvtAppCallback_c( the callback message ),这两个事件有什么不同,都是由哪里发起的,为什么gAppEvtMsgFromHostStack_c处理是用App_HandleHostMessageInput(pMsgIn);这个函数完成什么功能?
- void App_Thread (uint32_t param)
- {
- osaEventFlags_t event;
-
- while(1)
- {
- OSA_EventWait(mAppEvent, osaEventFlagsAll_c, FALSE, osaWaitForever_c , &event);
-
- /* Dequeue the host to app message */
- if (event & gAppEvtMsgFromHostStack_c)
- {
- /* Pointer for storing the messages from host. */
- appMsgFromHost_t *pMsgIn = NULL;
-
- /* Check for existing messages in queue */
- while(MSG_Pending(&mHostAppInputQueue))
- {
- pMsgIn = MSG_DeQueue(&mHostAppInputQueue);
-
- if (pMsgIn)
- {
- /* Process it */
- App_HandleHostMessageInput(pMsgIn);
-
- /* Messages must always be freed. */
- MSG_Free(pMsgIn);
- pMsgIn = NULL;
- }
- }
- }
-
- /* Dequeue the callback message */
- if (event & gAppEvtAppCallback_c)
- {
- /* Pointer for storing the callback messages. */
- appMsgCallback_t *pMsgIn = NULL;
-
- /* Check for existing messages in queue */
- while(MSG_Pending(&mAppCbInputQueue))
- {
- pMsgIn = MSG_DeQueue(&mAppCbInputQueue);
-
- if (pMsgIn)
- {
- /* Execute callback handler */
- if (pMsgIn->handler)
- {
- pMsgIn->handler (pMsgIn->param);
- }
-
- /* Messages must always be freed. */
- MSG_Free(pMsgIn);
- pMsgIn = NULL;
- }
- }
- }
- /* For BareMetal break the while(1) after 1 run */
- if( gUseRtos_c == 0 )
- {
- break;
- }
- }
- }
复制代码
gAppEvtAppCallback_c事件用pMsgIn->handler (pMsgIn->param)处理的,怎么感觉什么也没有做呀?到哪里可以看到所有的应用回调函数呀?
- /* Dequeue the callback message */
- if (event & gAppEvtAppCallback_c)
- {
- /* Pointer for storing the callback messages. */
- appMsgCallback_t *pMsgIn = NULL;
-
- /* Check for existing messages in queue */
- while(MSG_Pending(&mAppCbInputQueue))
- {
- pMsgIn = MSG_DeQueue(&mAppCbInputQueue);
-
- if (pMsgIn)
- {
- /* Execute callback handler */
- if (pMsgIn->handler)
- {
- pMsgIn->handler (pMsgIn->param);
- }
-
- /* Messages must always be freed. */
- MSG_Free(pMsgIn);
- pMsgIn = NULL;
- }
- }
- }
复制代码
此帖出自
小平头技术问答
一周热门 更多>