![ZigBee協(xié)議棧初始化網(wǎng)絡(luò)啟動流程_第1頁](http://file4.renrendoc.com/view/bf42951b82d90858c9ee26451057f5ce/bf42951b82d90858c9ee26451057f5ce1.gif)
![ZigBee協(xié)議棧初始化網(wǎng)絡(luò)啟動流程_第2頁](http://file4.renrendoc.com/view/bf42951b82d90858c9ee26451057f5ce/bf42951b82d90858c9ee26451057f5ce2.gif)
![ZigBee協(xié)議棧初始化網(wǎng)絡(luò)啟動流程_第3頁](http://file4.renrendoc.com/view/bf42951b82d90858c9ee26451057f5ce/bf42951b82d90858c9ee26451057f5ce3.gif)
![ZigBee協(xié)議棧初始化網(wǎng)絡(luò)啟動流程_第4頁](http://file4.renrendoc.com/view/bf42951b82d90858c9ee26451057f5ce/bf42951b82d90858c9ee26451057f5ce4.gif)
版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)
文檔簡介
1、ZigBee協(xié)議棧初始化網(wǎng)絡(luò)啟動流程編制僅供參考審核批準(zhǔn)生效日期地址: 電話:傳真: 郵編:ZigBee協(xié)議棧初始化網(wǎng)絡(luò)啟動流程ZigBee的基本流程:由協(xié)調(diào)器的組網(wǎng)(創(chuàng)建PAN ID),終端設(shè)備和路由設(shè)備發(fā)現(xiàn)網(wǎng)絡(luò)以及加入網(wǎng)絡(luò)。基本流程:main()-osal_init_system()-osalInitTasks()-ZDApp_Init(),進(jìn)協(xié)議棧初始化函數(shù)ZDApp_Init()。1.1 進(jìn)入程序入口main()。ZMain.c中C+ Codeint main( void )/ Turn off interruptsosal_int_disable( INTS_ALL );/ Init
2、ialization for board related stuff such as LEDsHAL_BOARD_INIT();/ Make sure supply voltage is high enough to runzmain_vdd_check();/ Initialize board I/OInitBoard( OB_COLD );/ Initialze HAL driversHalDriverInit();/ Initialize NV Systemosal_nv_init( NULL );/ Initialize the MACZMacInit();/ Determine th
3、e extended addresszmain_ext_addr();/ Initialize basic NV itemszgInit();#ifndef NONWK/ Since the AF isnt a task, call its initialization routineafInit();#endif/ Initialize the operating systemosal_init_system();/ Allow interruptsosal_int_enable( INTS_ALL );/ Final board initializationInitBoard( OB_RE
4、ADY );/ Display information about this devicezmain_dev_info();/* Display the device info on the LCD */#ifdef LCD_SUPPORTEDzmain_lcd_init();#endif#ifdef WDT_IN_PM1/* If WDT is used, this is a good place to enable it. */WatchDogEnable( WDTIMX );#endifosal_start_system(); / No Return from herereturn 0;
5、 / Shouldnt get here. / main()1.2 給任務(wù)添加IDsapi.c中C+ Codevoid osalInitTasks( void ) /為各自進(jìn)程添加ID 用于任務(wù)的查找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( ta
6、skID+ );/硬件抽象層初始化#if defined( MT_TASK )MT_TaskInit( taskID+ );#endifAPS_Init( taskID+ );ZDApp_Init( taskID+ );/判斷如果協(xié)調(diào)器節(jié)點(diǎn)建立網(wǎng)絡(luò)、如果終端節(jié)點(diǎn)加入網(wǎng)絡(luò)SAPI_Init( taskID );1.3 初始化ZigBee協(xié)議棧網(wǎng)絡(luò)ZDApp.cC+ Codevoid ZDApp_Init( uint8 task_id )/ Save the task IDZDAppTaskID = task_id;/ Initialize the ZDO global device short
7、address storageZDAppNwkAddr.addrMode = Addr16Bit;ZDAppNwkAddr.addr.shortAddr = INVALID_NODE_ADDR;(void)NLME_GetExtAddr(); / Load the saveExtAddr pointer./ Check for manual Hold Auto Start/檢測到有手工設(shè)置HAL_KEY_SW_1則會設(shè)置devState = DEV_HOLD,從而避開網(wǎng)絡(luò)初始化ZDAppCheckForHoldKey();/ Initialize ZDO items and setup the
8、 device - type of device to create.ZDO_Init(); /通過判斷預(yù)編譯來開啟一些函數(shù)功能/ Register the 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_InitUserDes
9、c();#endif / ZDO_USERDESC_RESPONSE/ Start the device?if ( devState != DEV_HOLD )ZDOInitDevice( 0 );else/ Blink LED to indicate HOLD_STARTHalLedBlink ( HAL_LED_4, 0, 50, 500 );ZDApp_RegisterCBs(); /* ZDApp_Init() */如果設(shè)置devState為DEV_HOLD,則不會執(zhí)行ZDOInitDevice;反之,系統(tǒng)會調(diào)用此函數(shù)是設(shè)備組網(wǎng)或者入網(wǎng)??聪逻@個函數(shù)完成的功能是什么樣子的。ZDOIni
10、tDevice是設(shè)備在網(wǎng)絡(luò)中啟動。它會讀取NV中的ZCD_NV_STARTUP_OPTION選項決定是否恢復(fù)網(wǎng)絡(luò)狀態(tài)。如果應(yīng)用層強(qiáng)制進(jìn)行新的join操作,它應(yīng)該在調(diào)用這個函數(shù)之前設(shè)置ZCD_NV_STARTUP_OPTION中的ZCD_STARTOPT_DEFAULT_NETWORK_STATE位??梢哉{(diào)用zgWrieStartupOptions()函數(shù)完成這些設(shè)置。1.4 初始化設(shè)備(啟動網(wǎng)絡(luò)和設(shè)置網(wǎng)絡(luò)類型)ZDApp.cC+ Codeuint8 ZDOInitDevice( uint16 startDelay )uint8 networkStateNV = ZDO_INITDEV_NEW_
11、NETWORK_STATE;uint16 extendedDelay = 0;if ( devState = DEV_HOLD )/ Initialize the RAM items table, in case an NV item has been updated.zgInitItems( FALSE );ZDConfig_InitDescriptors();/devtag.071807.todo - fix this temporary solution_NIB.CapabilityInfo = ZDO_Config_Node_Descriptor.CapabilityFlags;dev
12、State = DEV_INIT; / Remove the Hold state/ 函數(shù)讀取NV項目ZCD_NV_LEAVE_CTRL的值,ZDApp_LeaveCtrl指向這個值/ Initialize leave control logicZDApp_LeaveCtrlInit();/ Check leave control reset settings/設(shè)備的斷開會造成DEV_HOLD狀態(tài)ZDApp_LeaveCtrlStartup( &devState, &startDelay );/ Leave may make the hold state come backif ( devSt
13、ate = DEV_HOLD )/設(shè)置啟動選項/ Set the NV startup option to force a new join.zgWriteStartupOptions( ZG_STARTUP_SET, ZCD_STARTOPT_DEFAULT_NETWORK_STATE );/通知應(yīng)用層觸發(fā)事件/ Notify the applicationsosal_set_event( ZDAppTaskID, ZDO_STATE_CHANGE_EVT );return ( ZDO_INITDEV_LEAVE_NOT_STARTED ); / Dont join - (one time)
14、.#if defined ( NV_RESTORE )/ Get Keypad directly to see if a reset nv is needed./ Hold down the SW_BYPASS_NV key (defined in OnBoard.h)/ while booting to skip past NV Restore.if ( HalKeyRead() = SW_BYPASS_NV )networkStateNV = ZDO_INITDEV_NEW_NETWORK_STATE;else/ 通過讀取ZCD_NV_STARTUP_OPTION選項決定是否進(jìn)行網(wǎng)絡(luò)恢復(fù)/
15、 Determine if NV should be restorednetworkStateNV = ZDApp_ReadNetworkRestoreState();if ( networkStateNV = ZDO_INITDEV_RESTORED_NETWORK_STATE )networkStateNV = ZDApp_RestoreNetworkState();else/ Wipe out the network state in NVNLME_InitNV();NLME_SetDefaultNV();#endifif ( networkStateNV = ZDO_INITDEV_N
16、EW_NETWORK_STATE )/如果是要啟動新的網(wǎng)絡(luò)ZDAppDetermineDeviceType();/根據(jù)選項設(shè)置設(shè)備的網(wǎng)絡(luò)類型,默認(rèn)路由類型/ Only delay if joining network - not restoring network stateextendedDelay = (uint16)(NWK_START_DELAY + startDelay)+ (osal_rand() & EXTENDED_JOINING_RANDOM_MASK);/ Initialize the security for type of deviceZDApp_SecInit( ne
17、tworkStateNV );/ 觸發(fā)啟動網(wǎng)絡(luò)/ Trigger the network startZDApp_NetworkInit( extendedDelay );/ set broadcast address mask to support broadcast filtering 用于處理合法的廣播地址NLME_SetBroadcastFilter( ZDO_Config_Node_Descriptor.CapabilityFlags );return ( networkStateNV );這個函數(shù)注意功能:初始化設(shè)備配置,ZDAppDetermineDeviceType()設(shè)置網(wǎng)絡(luò)類
18、型(協(xié)調(diào)、路由、終端),ZDApp_NetworkInit( extendedDelay )初始化網(wǎng)絡(luò)并開啟或加入網(wǎng)絡(luò)。1.5 定時開啟網(wǎng)絡(luò)ZDApp.c進(jìn)入ZDApp_NetworkInit()函數(shù),等待一段時間在執(zhí)行ZDO_NETWORK_INIT,跳入事件處理ZDApp層ZDAPP_EVENT_LOOP()函數(shù)開啟網(wǎng)絡(luò)。C+ Codevoid ZDApp_NetworkInit( uint16 delay )if ( delay )/ Wait awhile before starting the deviceosal_start_timerEx( ZDAppTaskID, ZDO_NE
19、TWORK_INIT, delay );/發(fā)送ZDO_NETWORK_INIT(網(wǎng)絡(luò)初始化)消息到 ZDApp層,轉(zhuǎn)到ZDApp層,ZDApp_event_loop()函數(shù)。elseosal_set_event( ZDAppTaskID, ZDO_NETWORK_INIT );1.6 啟動設(shè)備ZDApp.cZDApp_event_loop()函數(shù)是回調(diào)函數(shù),循環(huán)處理主事件。設(shè)備邏輯類型,啟動模式,信標(biāo)時間,超幀長度C+ CodeUINT16 ZDApp_event_loop( uint8 task_id, UINT16 events )uint8 *msg_ptr;if ( events &
20、SYS_EVENT_MSG )while ( (msg_ptr = osal_msg_receive( ZDAppTaskID ) )ZDApp_ProcessOSALMsg( (osal_event_hdr_t *)msg_ptr );/ Release the memoryosal_msg_deallocate( msg_ptr );/ Return unprocessed eventsreturn (events SYS_EVENT_MSG);if ( events & ZDO_NETWORK_INIT )/ Initialize apps and start the networkde
21、vState = DEV_INIT;/設(shè)備邏輯類型,啟動模式,信標(biāo)時間,超幀長度,接著轉(zhuǎn)到去啟動設(shè)備,轉(zhuǎn)到ZDO_StartDevice()ZDO_StartDevice( (uint8)ZDO_Config_Node_Descriptor.LogicalType, devStartMode,DEFAULT_BEACON_ORDER, DEFAULT_SUPERFRAME_ORDER );/ Return unprocessed eventsreturn (events ZDO_NETWORK_INIT);if ( ZSTACK_ROUTER_BUILD )if ( events & ZDO_
22、NETWORK_START )ZDApp_NetworkStartEvt();/ Return unprocessed eventsreturn (events ZDO_NETWORK_START);if ( events & ZDO_ROUTER_START )if ( nwkStatus = ZSuccess )if ( devState = DEV_END_DEVICE )devState = DEV_ROUTER;osal_pwrmgr_device( PWRMGR_ALWAYS_ON );else/ remain as end device!osal_set_event( ZDApp
23、TaskID, ZDO_STATE_CHANGE_EVT );/ Return unprocessed eventsreturn (events ZDO_ROUTER_START);if ( events & ZDO_STATE_CHANGE_EVT )ZDO_UpdateNwkStatus( devState );/ At start up, do one MTO route discovery if the device is a concentratorif ( zgConcentratorEnable = TRUE )/ Start next eventosal_start_timer
24、Ex( NWK_TaskID, NWK_MTO_RTG_REQ_EVT, 100 );/ Return unprocessed eventsreturn (events ZDO_STATE_CHANGE_EVT);if ( events & ZDO_COMMAND_CNF )/ User defined logic/ Return unprocessed eventsreturn (events ZDO_COMMAND_CNF);if ( events & ZDO_NWK_UPDATE_NV )ZDApp_SaveNetworkStateEvt();/ Return unprocessed e
25、ventsreturn (events ZDO_NWK_UPDATE_NV);if ( events & ZDO_DEVICE_RESET )/ The device has been in the UNAUTH state, so reset/ Note: there will be no return from this callSystemReset();if ( ZG_SECURE_ENABLED )return ( ZDApp_ProcessSecEvent( task_id, events ) );else/ Discard or make more handlersreturn
26、0;1.7 開啟網(wǎng)絡(luò)ZDObject.cC+ Codevoid ZDO_StartDevice( byte logicalType, devStartModes_t startMode, byte beaconOrder, byte superframeOrder )ZStatus_t ret;#if defined ( ZIGBEE_FREQ_AGILITY )static uint8 discRetries = 0;#endif#if defined ( ZIGBEE_COMMISSIONING )static uint8 scanCnt = 0;#endifret = ZUnsuppor
27、tedMode;if ( ZG_BUILD_COORDINATOR_TYPE & logicalType = NODETYPE_COORDINATOR ) /當(dāng)設(shè)備作為協(xié)調(diào)器時,執(zhí)行這個條件語句。if ( startMode = MODE_HARD )devState = DEV_COORD_STARTING;/向網(wǎng)絡(luò)層發(fā)送網(wǎng)絡(luò)形成請求。當(dāng)網(wǎng)絡(luò)層執(zhí)行 NLME_NetworkFormationRequest()建立網(wǎng)絡(luò)后,將給予ZDO層反饋信息。/ 接著轉(zhuǎn)去執(zhí)行ZDApp層的 ZDO_NetworkFormationConfirmCB()函數(shù)ret = NLME_NetworkFormatio
28、nRequest( zgConfigPANID, zgApsUseExtendedPANID, zgDefaultChannelList,zgDefaultStartingScanDuration, beaconOrder,superframeOrder, false );else if ( startMode = MODE_RESUME )/ Just start the coordinatordevState = DEV_COORD_STARTING;ret = NLME_StartRouterRequest( beaconOrder, beaconOrder, false );else#
29、if defined( LCD_SUPPORTED )HalLcdWriteScreen( StartDevice ERR, MODE unknown );#endifif ( ZG_BUILD_JOINING_TYPE & (logicalType = NODETYPE_ROUTER | logicalType = NODETYPE_DEVICE) )/當(dāng)設(shè)備作為節(jié)點(diǎn)時,執(zhí)行這個條件語句。if ( (startMode = MODE_JOIN) | (startMode = MODE_REJOIN) )devState = DEV_NWK_DISC;#if defined( MANAGED_
30、SCAN )ZDOManagedScan_Next();ret = NLME_NetworkDiscoveryRequest( managedScanChannelMask, BEACON_ORDER_15_MSEC );#elseret = NLME_NetworkDiscoveryRequest( zgDefaultChannelList, zgDefaultStartingScanDuration );#if defined ( ZIGBEE_FREQ_AGILITY )if ( !( ZDO_Config_Node_Descriptor.CapabilityFlags & CAPINF
31、O_RCVR_ON_IDLE ) &( ret = ZSuccess ) & ( +discRetries = 4 ) )/ For devices with RxOnWhenIdle equals to FALSE, any network channel/ change will not be recieved. On these devices or routers that have/ lost the network, an active scan shall be conducted on the Default/ Channel list using the extended P
32、ANID to find the network. If the/ extended PANID isnt found using the Default Channel list, an scan/ should be completed using all channels.zgDefaultChannelList = MAX_CHANNELS_24GHZ;#endif / ZIGBEE_FREQ_AGILITY#if defined ( ZIGBEE_COMMISSIONING )if (startMode = MODE_REJOIN & scanCnt+ = 5 )/ When Aps
33、UseExtendedPanID is commissioned to a non zero value via/ application specific means, the device shall conduct an active scan/ on the Default Channel list and join the PAN with the same/ ExtendedPanID. If the PAN is not found, an scan should be completed/ on all channels./ When devices rejoin the network and the PAN is not found fromzgDefaultChannelList = MAX_CHANNELS_24GHZ;#endif / ZIGBEE_COMMISSIONING#endifelse if ( startMode = MODE_RESUME )if ( logicalType = NODETYPE_ROUTER )ZMacScanCnf_t scan
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 物料鏟運(yùn)合同(2篇)
- 2025年中國標(biāo)準(zhǔn)型火花塞市場調(diào)查研究報告
- 2025年度公寓式酒店車位租賃合同協(xié)議
- 二零二五年度門衛(wèi)安全教育與培訓(xùn)合同
- 二零二五年度個人向單位提供教育培訓(xùn)貸款借款合同
- 2025年度水電工程安全生產(chǎn)責(zé)任保險合同模板
- 2025-2030年戶外便攜式燃?xì)鉄崴疇t行業(yè)深度調(diào)研及發(fā)展戰(zhàn)略咨詢報告
- 2025年無夾具波峰焊機(jī)項目可行性研究報告
- 2025至2030年金屬包裝箱項目投資價值分析報告
- 2025年旅游紀(jì)念工藝品項目可行性研究報告
- 福建省泉州市晉江市2024-2025學(xué)年七年級上學(xué)期期末生物學(xué)試題(含答案)
- 醫(yī)美注射類知識培訓(xùn)課件
- 2025年春新人教版物理八年級下冊課件 第十章 浮力 第4節(jié) 跨學(xué)科實踐:制作微型密度計
- 2025年廣電網(wǎng)絡(luò)公司工作計劃(3篇)
- 貨運(yùn)車輛駕駛員服務(wù)標(biāo)準(zhǔn)化培訓(xùn)考核試卷
- 財務(wù)BP經(jīng)營分析報告
- 三年級上冊體育課教案
- 2024高考物理二輪復(fù)習(xí)電學(xué)實驗專項訓(xùn)練含解析
- 2024年全國統(tǒng)一高考英語試卷(新課標(biāo)Ⅰ卷)含答案
- 高中英語:倒裝句專項練習(xí)(附答案)
- 2025屆河北衡水?dāng)?shù)學(xué)高三第一學(xué)期期末統(tǒng)考試題含解析
評論
0/150
提交評論