TI osal蓝牙协议栈回调分析

来源:互联网 发布:勤思考研怎么样知乎 编辑:程序博客网 时间:2024/06/01 10:11

SYD8801是一款低功耗高性能蓝牙低功耗SOC,集成了高性能2.4GHz射频收发机、32位ARM Cortex-M0处理器、128kB Flash存储器、以及丰富的数字接口。SYD8801片上集成了Balun无需阻抗匹配网络、高效率DCDC降压转换器,适合用于可穿戴、物联网设备等。具体可咨询:http://www.syd-tek.com/

TI osal蓝牙协议栈回调分析

《BLE高级实践17 一主三从(12.08更新)》

 

搜索"Advertising"可以看到peripheralStateNotificationCB函数中有提及:

HalLcdWriteString("Advertising",  HAL_LCD_LINE_3);

 

--------》

包含进simpleBLEPeripheral_PeripheralCBs数组:

// GAP Role Callbacks

static gapRolesCBs_t simpleBLEPeripheral_PeripheralCBs =

{

 peripheralStateNotificationCB,  //Profile State Change Callbacks

 NULL                            //When a valid RSSI is read from controller (not used by application)

};

 

-------》

SimpleBLEPeripheral_ProcessEvent函数中进行了注册:

// Start the Device

VOID GAPRole_StartDevice(&simpleBLEPeripheral_PeripheralCBs );

 

-------》

保存pGapRoles_AppCGs变量:

// Clear all of the Application callbacks

   if ( pAppCallbacks )

    {

     pGapRoles_AppCGs = pAppCallbacks;

}

 

有两个地方调用了pGapRoles_AppCGs->pfnStateChange,先说GAPRole_ProcessEvent函数中的:

————》

  if ( events & START_ADVERTISING_EVT )

  {

        …………………………………………………….       

        // Notify the application with the newstate change

        if ( pGapRoles_AppCGs &&pGapRoles_AppCGs->pfnStateChange )

        {

          pGapRoles_AppCGs->pfnStateChange(gapRole_state );

        }

        ………………………………………………………

  }

 

----------》

// Theorder in this table must be identical to the task initialization calls below inosalInitTask.

constpTaskEventHandlerFn tasksArr[] =

{

  LL_ProcessEvent,                                                 // task 0

  Hal_ProcessEvent,                                                 // task 1

  HCI_ProcessEvent,                                                // task 2

#ifdefined ( OSAL_CBTIMER_NUM_TASKS )

  OSAL_CBTIMER_PROCESS_EVENT(osal_CbTimerProcessEvent ),           //task 3

#endif

  L2CAP_ProcessEvent,                                              // task 4

  GAP_ProcessEvent,                                                // task 5

  GATT_ProcessEvent,                                               // task 6

  SM_ProcessEvent,                                                  // task 7

  GAPRole_ProcessEvent,                                             //task 8

  GAPBondMgr_ProcessEvent,                                          //task 9

  GATTServApp_ProcessEvent,                                         // task 10

  SimpleBLEPeripheral_ProcessEvent                                  // task 11

};

 

最后来到tasksArr数组,这是osal回调事件的数组,看看osal事件初始化:

voidosalInitTasks( void )

{

  uint8 taskID = 0;

 

  tasksEvents = (uint16 *)osal_mem_alloc(sizeof( uint16 ) * tasksCnt);

  osal_memset( tasksEvents, 0, (sizeof( uint16) * tasksCnt));

 

  /* LL Task */

  LL_Init( taskID++ );

 

  /* Hal Task */

  Hal_Init( taskID++ );

 

  /* HCI Task */

  HCI_Init( taskID++ );

 

#ifdefined ( OSAL_CBTIMER_NUM_TASKS )

  /* Callback Timer Tasks */

  osal_CbTimerInit( taskID );

  taskID += OSAL_CBTIMER_NUM_TASKS;

#endif

 

  /* L2CAP Task */

  L2CAP_Init( taskID++ );

 

  /* GAP Task */

  GAP_Init( taskID++ );

 

  /* GATT Task */

  GATT_Init( taskID++ );

 

  /* SM Task */

  SM_Init( taskID++ );

 

  /* Profiles */

  GAPRole_Init( taskID++ );

  GAPBondMgr_Init( taskID++ );

 

  GATTServApp_Init( taskID++ );

 

  /* Application */

  SimpleBLEPeripheral_Init( taskID );

}

 

这里存在着一一对应的关系,事件的排序按照蓝牙协议栈从低往上排。

 

下来看gapRole_ProcessGAPMsg函数中的pGapRoles_AppCGs->pfnStateChange:

---------》

staticvoid gapRole_ProcessGAPMsg( gapEventHdr_t *pMsg )

{

………………………………………………..

  if ( notify == TRUE )

  {

    // Notify the application with the newstate change

    if ( pGapRoles_AppCGs &&pGapRoles_AppCGs->pfnStateChange )

    {

      pGapRoles_AppCGs->pfnStateChange(gapRole_state );

    }

  }

}

//这里还处理了蓝牙其他回调事件,比如:GAP_ADV_DATA_UPDATE_DONE_EVENT

 

——————》

staticvoid gapRole_ProcessOSALMsg( osal_event_hdr_t *pMsg )

{

  switch ( pMsg->event )

  {

    ……………………………………………………

    case GAP_MSG_EVENT:

      gapRole_ProcessGAPMsg( (gapEventHdr_t *)pMsg);

      break;

 

----------------》

uint16GAPRole_ProcessEvent( uint8 task_id, uint16 events )

{

  VOID task_id; // OSAL required parameter thatisn't used in this function

 

  if ( events & SYS_EVENT_MSG )

  {

    uint8 *pMsg;

 

    if ( (pMsg = osal_msg_receive(gapRole_TaskID )) != NULL )

    {

      gapRole_ProcessOSALMsg( (osal_event_hdr_t*)pMsg );

 

      // Release the OSAL message

      VOID osal_msg_deallocate( pMsg );

    }

 

    // return unprocessed events

    return (events ^ SYS_EVENT_MSG);

  }

//这里回到了GAPRole_ProcessEvent函数,蓝牙回调事件基本在GAPRole_ProcessEvent函数中进行的



这里上传本博客使用到的代码:

http://download.csdn.net/detail/chengdong1314/9820872

0 0
原创粉丝点击