您的位置:首页 > 其它

CC254X 如何添加用户进程

2014-08-11 17:29 197 查看
1.添加用户进程文件:user.c user.h

#include "user.h"
#include "SerialApp.h"
//#include "hmc5883l.h"

#define START_DEVICE_EVT          0x0001
#define SECOND_DEVICE_EVT         0x0002
#define boardROLE_DEVICE_EVT      0x0008

static uint8 uesrTaskId;
void user_init( uint8 task_id )
{
  //acquire_device_id();
  uesrTaskId = task_id;  
  RegisterForuser( uesrTaskId );
  osal_set_event( uesrTaskId, START_DEVICE_EVT );  
}

uint16 user_ProcessEvent( uint8 task_id, uint16 events )
{
  VOID task_id; 
  //static uint8 new_adv_enabled_status;
  
  if ( events & START_DEVICE_EVT )
  {
    SerialPrintf("user application\r\n");
    osal_start_timerEx(uesrTaskId ,START_DEVICE_EVT,2000);//20S
    return ( events ^ START_DEVICE_EVT );
  }  

  if ( events & SECOND_DEVICE_EVT )
  {
    HalUARTWrite(0,"message transmit\r\n",19);
    //user_transmit();
    //message_transmit();
    return ( events ^ SECOND_DEVICE_EVT );
  }  
  
  if ( events & boardROLE_DEVICE_EVT )
  {
    //HalUARTWrite(0,"boardcast\r\n",11);
    /*
    if(boardROLE == 0)
    {
      new_adv_enabled_status = TRUE;
      GAPRole_SetParameter( GAPROLE_ADVERT_ENABLED, sizeof( uint8 ), &new_adv_enabled_status ); 
    }
    else if(boardROLE == 1)
    {
      new_adv_enabled_status = FALSE;
      GAPRole_TerminateConnection();
      GAPRole_SetParameter( GAPROLE_ADVERT_ENABLED, sizeof( uint8 ), &new_adv_enabled_status );      
    } 
    */
    return ( events ^ boardROLE_DEVICE_EVT );
  }
  return 0;
}


#include "bcomdef.h"
#include "OSAL.h"
#include "OSAL_PwrMgr.h"
#include "OnBoard.h"
#include "hal_adc.h"
#include "hal_led.h"
#include "hal_key.h"
#include "hal_lcd.h"
#include "hal_uart.h"
#include "gatt.h"
#include "hci.h"
#include "gapgattserver.h"
#include "gattservapp.h"

#include "simpleGATTprofile.h"
#if defined( CC2540_MINIDK )
#include "simplekeys.h"
#endif
#if defined ( PLUS_BROADCASTER )
#include "peripheralBroadcaster.h"
#else
#include "peripheral.h"
#endif
#include "gapbondmgr.h"

//#include "hmc5883l.h"
//#include "id.h"
#include  <math.h>

extern void user_init( uint8 task_id );
extern uint16 user_ProcessEvent( uint8 task_id, uint16 events );





2.在Onboard.c 添加代码:

static uint8 registereduserTaskID = NO_TASK_ID;

//user

uint8 RegisterForuser( uint8 task_id )

{

// Allow only the first task

if ( registereduserTaskID == NO_TASK_ID )

{

registereduserTaskID = task_id;

return ( true );

}

else

return ( false );

}

3.在Onboard.h 添加代码:

extern uint8 RegisterForuser( uint8 task_id );

4.注册 在OSAL_simpleBLECentral.c:

添加

#include "user.h"

const pTaskEventHandlerFn tasksArr[] =

{

LL_ProcessEvent,

Hal_ProcessEvent,

HCI_ProcessEvent,

#if defined ( OSAL_CBTIMER_NUM_TASKS )

OSAL_CBTIMER_PROCESS_EVENT( osal_CbTimerProcessEvent ),

#endif

L2CAP_ProcessEvent,

GAP_ProcessEvent,

GATT_ProcessEvent,

SM_ProcessEvent,

GAPCentralRole_ProcessEvent,

GAPBondMgr_ProcessEvent,

GATTServApp_ProcessEvent,

user_ProcessEvent,

SimpleBLECentral_ProcessEvent

};

void osalInitTasks( void )

{

user_init( taskID++ );

}

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: