1.main函数
main()位于Zmain.c
关注osal_init_system()和osal_start_system()两个函数
/*********************************************************************
* @fn main
* @brief First function called after startup.
* @return don't care
*/
int main( void )
{
// Turn off interrupts
osal_int_disable( INTS_ALL );
// Initialization for board related stuff such as LEDs
HAL_BOARD_INIT(); //初始化系统时钟
// Make sure supply voltage is high enough to run
zmain_vdd_check();
// Initialize board I/O
InitBoard( OB_COLD );
// Initialze HAL drivers
HalDriverInit();
// Initialize NV System
osal_nv_init( NULL ); //初始化flash寄存器
// Initialize the MAC
ZMacInit();
// Determine the extended address
zmain_ext_addr(); //确定64位IEEE地址
// Initialize basic NV items
zgInit(); //初始非易失变量
#ifndef NONWK
// Since the AF isn't a task, call it's initialization routine
afInit();
#endif
// Initialize the operating system
osal_init_system();
// Allow interrupts
osal_int_enable( INTS_ALL ); //使能全部中断
// Final board initialization
InitBoard( OB_READY ); //最终板载初始化
// Display information about this device
zmain_dev_info(); //显示设备信息
/* Display the device info on the LCD */
#ifdef LCD_SUPPORTED
zmain_lcd_init(); //初始化LED
#endif
#ifdef WDT_IN_PM1
/* If WDT is used, this is a good place to enable it. */
WatchDogEnable( WDTIMX );
#endif
osal_start_system(); // No Return from here
return 0; // Shouldn't get here.
} // main()
2.操作系统初始化函数
osal_init_system()位于OSAL.c
关注osalInitTask()任务初始化函数
/*********************************************************************
* @fn osal_init_system
*
* @brief
*
* This function initializes the "task" system by creating the
* tasks defined in the task table (OSAL_Tasks.h).
*
* @param void
*
* @return SUCCESS
*/
uint8 osal_init_system( void )
{
// Initialize the Memory Allocation System
osal_mem_init();
// Initialize the message queue
osal_qHead = NULL;
// Initialize the timers
osalTimerInit();
// Initialize the Power Management System
osal_pwrmgr_init();
// Initialize the system tasks.
osalInitTasks(); //初始化系统任务
// Setup efficient search for the first free block of heap.
osal_mem_kick();
return ( SUCCESS );
}
2.1任务初始化函数
osalInitTask()位于OSAL_GenericApp.c
关注Hal_Init()、ZDApp_Init()、zclGenericApp_Init()
/*********************************************************************
* @fn osalInitTasks
*
* @brief This function invokes the initialization function for each task.
*
* @param void
*
* @return none
*/
void osalInitTasks( void )
{
uint8 taskID = 0; //分配内存,返回指向缓冲区的指针 任务号
tasksEvents = (uint16 *)osal_mem_alloc( sizeof( uint16 ) * tasksCnt); //设置所分配的内存单元值为0
osal_memset( tasksEvents, 0, (sizeof( uint16 ) * tasksCnt)); //任务优先级由高到底依次排序,高优先级对应的taskID值反而小
macTaskInit( taskID++ ); //不管 taskID=0
nwk_init( taskID++ ); //不管 taskID=1
#if !defined (DISABLE_GREENPOWER_B