CC2530芯片中的操作系统抽象层(OSAL)是一个多任务操作系统,在开发时首先需要将任务静态添加至系统进行编译,当任务执行后会产生对应的事件,当系统初始化时,需要初始化新添加的任务:
void osalInitTasks( void )
{
uint8 taskID = 0;//这里可以看出系统最多有256个任务
tasksEvents = (uint16 *)osal_mem_alloc( sizeof( uint16 ) * tasksCnt);//每项任务对应事件数组中的每一项
osal_memset( tasksEvents, 0, (sizeof( uint16 ) * tasksCnt));
//初始化系统默认任务
………..
GenericApp_Init( taskID );//这里就初始化新添加的任务
}
添加任务处理函数:
// The order in this table must be identical to the task initialization calls below in osalInitTask.
typedef unsigned short (*pTaskEventHandlerFn)( unsigned char task_id, unsigned short event );
const pTaskEventHandlerFn tasksArr[] = {
macEventLoop,
nwk_event_loop,
Hal_ProcessEvent,
#if defined( MT_TASK )
MT_ProcessEvent,
#endif
APS_event_loop,
#if defined ( ZIGBEE_FRAGMENTATION )
APSF_ProcessEvent,
#endif
ZDApp_event_loop,
#if defi