App_Thread是如何运行的?

2019-03-26 07:49发布

下面是BLE Wireless UART例子程序ApplMain.c中main_task最后调用的函数。其中处理了两类事件:gAppEvtMsgFromHostStack_c(the host to app message)和 gAppEvtAppCallback_c( the callback message ),这两个事件有什么不同,都是由哪里发起的,为什么gAppEvtMsgFromHostStack_c处理是用App_HandleHostMessageInput(pMsgIn);这个函数完成什么功能?

  1. void App_Thread (uint32_t param)
  2. {
  3.     osaEventFlags_t event;
  4.    
  5.     while(1)
  6.     {
  7.         OSA_EventWait(mAppEvent, osaEventFlagsAll_c, FALSE, osaWaitForever_c , &event);
  8.         
  9.         /* Dequeue the host to app message */
  10.         if (event & gAppEvtMsgFromHostStack_c)
  11.         {
  12.             /* Pointer for storing the messages from host. */
  13.             appMsgFromHost_t *pMsgIn = NULL;  
  14.             
  15.             /* Check for existing messages in queue */
  16.             while(MSG_Pending(&mHostAppInputQueue))
  17.             {
  18.                 pMsgIn = MSG_DeQueue(&mHostAppInputQueue);
  19.             
  20.                 if (pMsgIn)
  21.                 {
  22.                     /* Process it */
  23.                     App_HandleHostMessageInput(pMsgIn);
  24.                     
  25.                     /* Messages must always be freed. */
  26.                     MSG_Free(pMsgIn);
  27.                     pMsgIn = NULL;
  28.                 }
  29.             }
  30.         }
  31.         
  32.         /* Dequeue the callback message */
  33.         if (event & gAppEvtAppCallback_c)
  34.         {
  35.             /* Pointer for storing the callback messages. */
  36.             appMsgCallback_t *pMsgIn = NULL;  
  37.             
  38.             /* Check for existing messages in queue */
  39.             while(MSG_Pending(&mAppCbInputQueue))
  40.             {
  41.                 pMsgIn = MSG_DeQueue(&mAppCbInputQueue);
  42.             
  43.                 if (pMsgIn)
  44.                 {
  45.                     /* Execute callback handler */
  46.                     if (pMsgIn->handler)
  47.                     {
  48.                         pMsgIn->handler (pMsgIn->param);
  49.                     }
  50.                     
  51.                     /* Messages must always be freed. */
  52.                     MSG_Free(pMsgIn);
  53.                     pMsgIn = NULL;
  54.                 }
  55.             }
  56.         }
  57.         /* For BareMetal break the while(1) after 1 run */
  58.         if( gUseRtos_c == 0 )
  59.         {
  60.             break;
  61.         }
  62.     }
  63. }
复制代码


gAppEvtAppCallback_c事件用pMsgIn->handler (pMsgIn->param)处理的,怎么感觉什么也没有做呀?到哪里可以看到所有的应用回调函数呀?
  
  1.      /* Dequeue the callback message */
  2.         if (event & gAppEvtAppCallback_c)
  3.         {
  4.             /* Pointer for storing the callback messages. */
  5.             appMsgCallback_t *pMsgIn = NULL;  
  6.             
  7.             /* Check for existing messages in queue */
  8.             while(MSG_Pending(&mAppCbInputQueue))
  9.             {
  10.                 pMsgIn = MSG_DeQueue(&mAppCbInputQueue);
  11.             
  12.                 if (pMsgIn)
  13.                 {
  14.                     /* Execute callback handler */
  15.                     if (pMsgIn->handler)
  16.                     {
  17.                         pMsgIn->handler (pMsgIn->param);
  18.                     }
  19.                     
  20.                     /* Messages must always be freed. */
  21.                     MSG_Free(pMsgIn);
  22.                     pMsgIn = NULL;
  23.                 }
  24.             }
  25.         }
复制代码 此帖出自小平头技术问答
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
5条回答
bjemt
2019-03-26 13:13
osaEventFlags_t event;中定义的事件类型只是一个32位的无符号整数,怎么知道事件中每一位的含义?
如果要在App_Thread程序中处理定时器(TPM和PIT),AD,DMA的事件应该如何修改这个函数?

一周热门 更多>