ZigBee协议栈初始化网络启动流程图

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

ZigBee协议栈初始化网络启动流程

ZigBee的基本流程:由协调器的组网(创建PAN ID),终端设备和路由设备发现网络以及加入网络。

基本流程:main()->osal_init_system()->osalInitTasks()->ZDApp_Init(),进协议栈初始化函数ZDApp_Init()。

1.1 进入程序入口main()。

ZMain.c中

C++ Code

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 );

// Initialize the MAC

ZMacInit();

// Determine the extended address

zmain_ext_addr();

// 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();

#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()

1.2 给任务添加ID

sapi.c中

C++ Code

void osalInitTasks( void ) //为各自进程添加ID 用于任务的查找

{

uint8 taskID = 0;

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

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

macTaskInit( taskID++ );

nwk_init( taskID++ );

Hal_Init( taskID++ );//硬件抽象层初始化

#if defined( MT_TASK )

MT_TaskInit( taskID++ );

#endif

APS_Init( taskID++ );

ZDApp_Init( taskID++ );//判断如果协调器节点建立网络、如果终端节点加入网络

SAPI_Init( taskID );

}

1.3 初始化ZigBee协议栈网络

ZDApp.c

C++ Code

void ZDApp_Init( uint8 task_id )

{

// Save the task ID

// Initialize the ZDO global device short address storage

ZDAppNwkAddr.addrMode = Addr16Bit;

ZDAppNwkAddr.addr.shortAddr = INVALID_NODE_ADDR;

(void)NLME_GetExtAddr(); // Load the saveExtAddr pointer.

// Check for manual "Hold Auto Start"

//检测到有手工设置HAL_KEY_SW_1则会设置devState = DEV_HOLD,从而避开网络初始化

ZDAppCheckForHoldKey();

// Initialize ZDO items and setup the device - type of device to create.

ZDO_Init(); //通过判断预编译来开启一些函数功能

// Register the endpoint description with the AF

// This task doesn't have a Simple description, but we still need

// to register the endpoint.

afRegister( (endPointDesc_t *)&ZDApp_epDesc );

#if defined( ZDO_USERDESC_RESPONSE )

ZDApp_InitUserDesc();

#endif // ZDO_USERDESC_RESPONSE

// Start the device?

if ( devState != DEV_HOLD )

{

ZDOInitDevice( 0 );

}

else

{

// Blink LED to indicate HOLD_START

HalLedBlink ( HAL_LED_4, 0, 50, 500 );

}

相关文档
最新文档