版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)
文檔簡介
1、ZigBee協(xié)議棧初始化網(wǎng)絡(luò)啟動流程編制僅供參考審核批準生效日期地址: 電話:傳真: 郵編: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ò)?;玖鞒蹋簃ain()-osal_init_system()-osalInitTasks()-ZDApp_Init(),進協(xié)議棧初始化函數(shù)ZDApp_Init()。1.1 進入程序入口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 ) /為各自進程添加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é)點建立網(wǎng)絡(luò)、如果終端節(jié)點加入網(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(); /通過判斷預編譯來開啟一些函數(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選項決定是否恢復網(wǎng)絡(luò)狀態(tài)。如果應(yīng)用層強制進行新的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選項決定是否進行網(wǎng)絡(luò)恢復/
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ò)類型,默認路由類型/ 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進入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è)備邏輯類型,啟動模式,信標時間,超幀長度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è)備邏輯類型,啟動模式,信標時間,超幀長度,接著轉(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 ) /當設(shè)備作為協(xié)調(diào)器時,執(zhí)行這個條件語句。if ( startMode = MODE_HARD )devState = DEV_COORD_STARTING;/向網(wǎng)絡(luò)層發(fā)送網(wǎng)絡(luò)形成請求。當網(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) )/當設(shè)備作為節(jié)點時,執(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)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
- 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025年智能化農(nóng)田種植承包合同3篇
- 2025年度棉被電商渠道開發(fā)與運營合作協(xié)議4篇
- 2025年度廚師餐飲項目廚師個人聘用合同范本4篇
- 2025年中國烘干線市場深度分析及投資戰(zhàn)略咨詢報告
- 2025年酸化壓裂助劑行業(yè)深度研究分析報告
- 2020-2025年中國汽車空氣流量傳感器行業(yè)發(fā)展趨勢及投資前景預測報告
- 個體戶設(shè)備購買貸款合同(2024年)
- 2025年銷售人員保密與商業(yè)道德協(xié)議維護企業(yè)市場地位與利益3篇
- 2025年花色絨行業(yè)深度研究分析報告
- 2025年度綠色生態(tài)農(nóng)業(yè)用地抵押借款服務(wù)合同
- 2024-2025學年人教版數(shù)學六年級上冊 期末綜合試卷(含答案)
- 收養(yǎng)能力評分表
- 山東省桓臺第一中學2024-2025學年高一上學期期中考試物理試卷(拓展部)(無答案)
- 中華人民共和國保守國家秘密法實施條例培訓課件
- 管道坡口技術(shù)培訓
- 2024年全國統(tǒng)一高考英語試卷(新課標Ⅰ卷)含答案
- 2024年認證行業(yè)法律法規(guī)及認證基礎(chǔ)知識 CCAA年度確認 試題與答案
- 皮膚儲存新技術(shù)及臨床應(yīng)用
- 外研版七年級英語上冊《閱讀理解》專項練習題(含答案)
- 2024年遼寧石化職業(yè)技術(shù)學院單招職業(yè)適應(yīng)性測試題庫必考題
- 上海市復旦大學附中2024屆高考沖刺模擬數(shù)學試題含解析
評論
0/150
提交評論