ZigBee源码程序及解释.doc





《ZigBee源码程序及解释.doc》由会员分享,可在线阅读,更多相关《ZigBee源码程序及解释.doc(174页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、Four short words sum up what has lifted most successful individuals above the crowd: a little bit more.-author-dateZigBee源码程序及解释ZigBee源码程序及解释协议栈无线透传编程原理:第一个功能:协调器的组网,终端设备和路由设备发现网络以及加入网络/第一步:Z-Stack由 main()函数开始执行,main()函数共做了 2 件事:一是系统初始化,另外一件是开始执行轮转查询式操作系统int main( void ) ./ Initialize the operating
2、systemosal_init_system(); /第二步,操作系统初始化.osal_start_system(); /初始化完系统任务事件后,正式开始执行操作系统. /第二步,进入 osal_init_system()函数,执行操作系统初始化uint8 osal_init_system( void ) /初始化操作系统,其中最重要的是,初始化操作系统的任务/ Initialize the Memory Allocation Systemosal_mem_init();/ Initialize the message queueosal_qHead = NULL;/ Initialize t
3、he timersosalTimerInit();/ Initialize the Power Management Systemosal_pwrmgr_init();/ Initialize the system tasks.osalInitTasks(); /第三步,执行操作系统任务初始化函数/ Setup efficient search for the first free block of heap.osal_mem_kick();return ( SUCCESS );/第三步,进入osalInitTasks()函数,执行操作系统任务初始化void osalInitTasks( vo
4、id ) /第三步,初始化操作系统任务uint8 taskID = 0;tasksEvents = (uint16 *)osal_mem_alloc( sizeof( uint16 ) * tasksCnt);osal_memset( tasksEvents, 0, (sizeof( uint16 ) * tasksCnt);/任务优先级由高向低依次排列,高优先级对应 taskID 的值反而小macTaskInit( taskID+ ); /不需要用户考虑nwk_init( taskID+ ); /不需要用户考虑Hal_Init( taskID+ ); /硬件抽象层初始化,需要我们考虑#if
5、defined( MT_TASK ) MT_TaskInit( taskID+ );#endifAPS_Init( taskID+ ); /不需要用户考虑#if defined ( ZIGBEE_FRAGMENTATION )APSF_Init( taskID+ );#endifZDApp_Init( taskID+ ); /第四步,ZDApp层,初始化,执行ZDApp_init函数后,如果是协调器将建立网络,如果是终端设备将加入网络。#if defined ( ZIGBEE_FREQ_AGILITY ) | defined ( ZIGBEE_PANID_CONFLICT )ZDNwkMgr_
6、Init( taskID+ );#endifSerialApp_Init( taskID );/应用层SerialApp层初始化,需要用户考虑 在此处设置了一个按键触发事件, /当有按键按下的时候,产生一个系统消息 /第四步,进入ZDApp_init()函数,执行ZDApp层初始化/The first stepvoid ZDApp_Init( uint8 task_id ) /The first step,ZDApp层初始化。/ Save the task IDZDAppTaskID = task_id;/ Initialize the ZDO global device short addr
7、ess storageZDAppNwkAddr.addrMode = Addr16Bit;ZDAppNwkAddr.addr.shortAddr = INVALID_NODE_ADDR;(void)NLME_GetExtAddr();/ Load the saveExtAddr pointer./ Check for manual Hold Auto StartZDAppCheckForHoldKey();/ Initialize ZDO items and setup the device - type of device to create.ZDO_Init();/ Register th
8、e endpoint description with the AF/ This task doesnt 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_HOL
9、D ) /devState 初值为DEV_INIT , 所以在初始化ZDA层时,就执行该条件语句 ZDOInitDevice( 0 ); /The second step, 接着转到ZDOInitDevice()函数,执行The third step;else / Blink LED to indicate HOLD_START HalLedBlink ( HAL_LED_4, 0, 50, 500 );ZDApp_RegisterCBs(); /* ZDApp_Init() */The third step,执行ZDOInitDevice()函数,执行设备初始化uint8 ZDOInitDe
10、vice( uint16 startDelay )/The third step, ZDO层初始化设备, ./ Trigger the network startZDApp_NetworkInit( extendedDelay ); /网络初始化,跳到相应的函数里头,执行The fourth step ./The fouth step,执行 ZDApp_NetWorkInit()函数void ZDApp_NetworkInit( uint16 delay ) /The fourth step,网络初始化if ( delay ) / Wait awhile before starting the
11、 device osal_start_timerEx( ZDAppTaskID, ZDO_NETWORK_INIT, delay ); /发送ZDO_NETWORK_INIT(网络初始化)消息到 ZDApp层,转到 /ZDApp层,执行The fifth step, ZDApp_event_loop() 函数 else osal_set_event( ZDAppTaskID, ZDO_NETWORK_INIT );/The fifth step,转到ZDApp_event_loop()函数UINT16 ZDApp_event_loop( uint8 task_id, UINT16 events
12、 )if ( events & ZDO_NETWORK_INIT ) /The fivth step,网络初始化事件处理 / Initialize apps and start the network devState = DEV_INIT; /设备逻辑类型,启动模式,信标时间,超帧长度,接着转到The sixth step,去启动设备,接着执行The sixth step,转到ZDO_StartDevice() ZDO_StartDevice( (uint8)ZDO_Config_Node_Descriptor.LogicalType, devStartMode, DEFAULT_BEACO
13、N_ORDER, DEFAULT_SUPERFRAME_ORDER ); / Return unprocessed events return (events ZDO_NETWORK_INIT);/The sixth step,执行ZDO_StartDevice()函数,启动设备void ZDO_StartDevice( byte logicalType, devStartModes_t startMode, byte beaconOrder, byte superframeOrder ) /The sixth step.if ( ZG_BUILD_COORDINATOR_TYPE & log
14、icalType = NODETYPE_COORDINATOR ) /当设备作为协调器时,执行这个条件语句。 if ( startMode = MODE_HARD ) devState = DEV_COORD_STARTING; /向网络层发送网络形成请求。当网络层执行 NLME_NetworkFormationRequest()建立网络后,将给予 ZDO层反馈信息。 / 接着转到The seventh step,去执行ZDApp层的ZDO_NetworkFormationConfirmCB()函数 ret = NLME_NetworkFormationRequest( zgConfigPAN
15、ID, zgApsUseExtendedPANID, zgDefaultChannelList, zgDefaultStartingScanDuration, beaconOrder, superframeOrder, false ); if ( ZG_BUILD_JOINING_TYPE & (logicalType = NODETYPE_ROUTER | logicalType = NODETYPE_DEVICE) ) /当为终端设备或路由时 if ( (startMode = MODE_JOIN) | (startMode = MODE_REJOIN) ) devState = DEV_
16、NWK_DISC; / zgDefaultChannelList与协调器形成网络的通道号匹配。 网络发现请求。 / 继而转到ZDO_NetworkDiscoveryConfirmCB()函数 ret = NLME_NetworkDiscoveryRequest( zgDefaultChannelList, zgDefaultStartingScanDuration ); ./The seventh step,分两种情况,1.协调器 2.路由器或终端设备1)协调器void ZDO_NetworkFormationConfirmCB( ZStatus_t Status ) /The seventh
17、 step,给予ZDO层网络形成反馈信息(协调器)osal_set_event( ZDAppTaskID, ZDO_NETWORK_START ); /发送网络启动事件 到 ZDApp层,接着转到ZDApp_event_loop()函数 .UINT16 ZDApp_event_loop( uint8 task_id, UINT16 events ).if ( events & ZDO_NETWORK_START )/ 网络启动事件 ZDApp_NetworkStartEvt(); /网络启动事件,接着跳转到The ninth step, 执行ZDApp_NetworkStartEvt()函数.
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- ZigBee 源码 程序 解释

限制150内