⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 zdapp.s51

📁 用IAR开发的ZIGBEE网络路由例子
💻 S51
📖 第 1 页 / 共 5 页
字号:
        MOVX	A,@DPTR
        JNZ	??ZDApp_event_loop_12
//  384     {
//  385       if ( devState == DEV_END_DEVICE )
        MOV	DPTR,#devState
        MOVX	A,@DPTR
        XRL	A,#0x6
        JNZ	??ZDApp_event_loop_13
//  386         devState = DEV_ROUTER;
        MOV	A,#0x7
        MOVX	@DPTR,A
//  387 
//  388       osal_pwrmgr_device( PWRMGR_ALWAYS_ON );
??ZDApp_event_loop_13:
        ; Setup parameters for call to function osal_pwrmgr_device
        MOV	R1,#0x0
        MOV	DPTR,#(osal_pwrmgr_device & 0xffff)
        MOV	A,#((osal_pwrmgr_device >> 16) & 0xff)
        LCALL	?BCALL               ; Banked call to: DPTR()
//  389     }
//  390     else
//  391     {
//  392       // remain as end device!!
//  393     }
//  394     osal_set_event( ZDAppTaskID, ZDO_STATE_CHANGE_EVT );
??ZDApp_event_loop_12:
        ; Setup parameters for call to function osal_set_event
        LCALL	?Subroutine7 & 0xFFFF
??CrossCallReturnLabel_70:
        LCALL	?BCALL               ; Banked call to: DPTR()
//  395 
//  396     // Return unprocessed events
//  397     return (events ^ ZDO_ROUTER_START);
        MOV	A,#0x20
        SJMP	??ZDApp_event_loop_3
//  398   }
//  399 #endif  // RTR
//  400 
//  401   if ( events & ZDO_STATE_CHANGE_EVT )
??ZDApp_event_loop_11:
        MOV	A,R6
        ANL	A,#0x10
        JZ	??ZDApp_event_loop_14
//  402   {
//  403     ZDO_UpdateNwkStatus( devState );
        ; Setup parameters for call to function ZDO_UpdateNwkStatus
        MOV	DPTR,#devState
        MOVX	A,@DPTR
        MOV	R1,A
        MOV	DPTR,#(ZDO_UpdateNwkStatus & 0xffff)
        MOV	A,#((ZDO_UpdateNwkStatus >> 16) & 0xff)
        LCALL	?BCALL               ; Banked call to: DPTR()
//  404 
//  405     // Return unprocessed events
//  406     return (events ^ ZDO_STATE_CHANGE_EVT);
        MOV	A,#0x10
        SJMP	??ZDApp_event_loop_10
//  407   }
//  408 
//  409   if ( events & ZDO_COMMAND_CNF )
??ZDApp_event_loop_14:
        MOV	A,R6
        ANL	A,#0x8
        JZ	??ZDApp_event_loop_15
//  410   {
//  411     // User defined logic
//  412 
//  413     // Return unprocessed events
//  414     return (events ^ ZDO_COMMAND_CNF);
        MOV	A,#0x8
        XRL	A,R6
        MOV	R2,A
        SJMP	??ZDApp_event_loop_5
//  415   }
//  416 
//  417 #if defined( ZDSECMGR_SECURE ) && defined( RTR_NWK )
//  418   if ( events & ZDO_NEW_DEVICE )
//  419   {
//  420     // process the new device event
//  421     if ( ZDSecMgrNewDeviceEvent() == TRUE )
//  422     {
//  423       osal_start_timerEx( ZDAppTaskID, ZDO_NEW_DEVICE, 1000 );
//  424     }
//  425 
//  426     // Return unprocessed events
//  427     return (events ^ ZDO_NEW_DEVICE);
//  428   }
//  429 #endif  // ZDSECMGR_SECURE && RTR
//  430 
//  431 #if defined ( ZDSECMGR_COMMERCIAL )
//  432   if ( events & ZDO_SECMGR_EVENT )
//  433   {
//  434     ZDSecMgrEvent();
//  435 
//  436     // Return unprocessed events
//  437     return (events ^ ZDO_SECMGR_EVENT);
//  438   }
//  439 #endif // defined( ZDSECMGR_COMMERCIAL )
//  440 
//  441 #if   ( SECURE != 0  )
//  442   if ( events & ZDO_DEVICE_AUTH )
//  443   {
//  444     ZDApp_DeviceAuthEvt();
//  445 
//  446     // Return unprocessed events
//  447     return (events ^ ZDO_DEVICE_AUTH);
//  448   }
//  449 #endif  // SECURE
//  450 
//  451   if ( events & ZDO_NWK_UPDATE_NV )
??ZDApp_event_loop_15:
        MOV	A,#0x2
        ANL	A,R7
        MOV	R1,A
        CLR	A
        JNZ	??ZDApp_event_loop_16
        MOV	A,R1
??ZDApp_event_loop_16:
        JZ	??ZDApp_event_loop_17
//  452   {
//  453     ZDApp_SaveNetworkStateEvt();
//  454 
//  455     // Return unprocessed events
//  456     return (events ^ ZDO_NWK_UPDATE_NV);
        MOV	A,#0x2
        SJMP	??ZDApp_event_loop_8
//  457   }
//  458 
//  459 #if ( SECURE != 0  )
//  460   if ( events & ZDO_FRAMECOUNTER_CHANGE )
//  461   {
//  462     if ( nwkFrameCounterChanges++ > MAX_NWK_FRAMECOUNTER_CHANGES )
//  463       ZDApp_SaveNwkKey();
//  464 
//  465     // Return unprocessed events
//  466     return (events ^ ZDO_FRAMECOUNTER_CHANGE);
//  467   }
//  468 #endif
//  469 
//  470   if ( events & ZDO_DEVICE_RESET )
??ZDApp_event_loop_17:
        MOV	A,R6
        ANL	A,#0x4
        JZ	??ZDApp_event_loop_18
//  471   {
//  472     // The device has been in the UNAUTH state, so reset
//  473     // Note: there will be no return from this call
//  474     SystemReset();
        CLR	0xa8.7
        MOV	0xc9,#-0x55
        MOV	0xc9,#0x5b
??ZDApp_event_loop_19:
        NOP
        SJMP	??ZDApp_event_loop_19
//  475   }
//  476 
//  477   // Discard or make more handlers
//  478   return 0;
??ZDApp_event_loop_18:
        MOV	R2,#0x0
        MOV	R3,#0x0
??ZDApp_event_loop_5:
        LJMP	??Subroutine28_1 & 0xFFFF
        CFI EndBlock cfiBlock1
//  479 }
//  480 
//  481 /*********************************************************************
//  482  * Application Functions
//  483  */
//  484 
//  485 /*********************************************************************
//  486  * @fn      ZDOInitDevice
//  487  *
//  488  * @brief   Start the device in the network.  This function will read
//  489  *   ZCD_NV_STARTUP_OPTION (NV item) to determine whether or not to
//  490  *   restore the network state of the device.
//  491  *
//  492  * @param   startDelay - timeDelay to start device (in milliseconds).
//  493  *      There is a jitter added to this delay:
//  494  *              ((NWK_START_DELAY + startDelay)
//  495  *              + (osal_rand() & EXTENDED_JOINING_RANDOM_MASK))
//  496  *
//  497  * NOTE:    If the application would like to force a "new" join, the
//  498  *          application should set the ZCD_STARTOPT_DEFAULT_NETWORK_STATE
//  499  *          bit in the ZCD_NV_STARTUP_OPTION NV item before calling
//  500  *          this function. "new" join means to not restore the network
//  501  *          state of the device. Use zgWriteStartupOptions() to set these
//  502  *          options.
//  503  *
//  504  * @return
//  505  *    ZDO_INITDEV_RESTORED_NETWORK_STATE  - The device's network state was
//  506  *          restored.
//  507  *    ZDO_INITDEV_NEW_NETWORK_STATE - The network state was initialized.
//  508  *          This could mean that ZCD_NV_STARTUP_OPTION said to not restore, or
//  509  *          it could mean that there was no network state to restore.
//  510  *    ZDO_INITDEV_LEAVE_NOT_STARTED - Before the reset, a network leave was issued
//  511  *          with the rejoin option set to TRUE.  So, the device was not
//  512  *          started in the network (one time only).  The next time this
//  513  *          function is called it will start.
//  514  */

        RSEG BANKED_CODE:CODE:NOROOT(0)
//  515 uint8 ZDOInitDevice( uint16 startDelay )
ZDOInitDevice:
        CFI Block cfiBlock2 Using cfiCommon0
        CFI Function ZDOInitDevice
//  516 {
        FUNCALL ZDOInitDevice, ZDApp_LeaveCtrlInit
        LOCFRAME XSTACK, 12, STACK
        ARGFRAME XSTACK, 12, STACK
        FUNCALL ZDOInitDevice, ZDApp_LeaveCtrlStartup
        LOCFRAME XSTACK, 12, STACK
        ARGFRAME XSTACK, 12, STACK
        FUNCALL ZDOInitDevice, osal_rand
        LOCFRAME XSTACK, 12, STACK
        ARGFRAME XSTACK, 12, STACK
        FUNCALL ZDOInitDevice, ZDApp_NetworkInit
        LOCFRAME XSTACK, 12, STACK
        ARGFRAME XSTACK, 12, STACK
        MOV	A,#-0xa
        LCALL	?BANKED_ENTER_XDATA
        CFI DPH0 load(1, XDATA, add(CFA_XSP16, literal(-1)))
        CFI DPL0 load(1, XDATA, add(CFA_XSP16, literal(-2)))
        CFI ?BRET_EXT load(1, XDATA, add(CFA_XSP16, literal(-3)))
        CFI ?RET_HIGH load(1, XDATA, add(CFA_XSP16, literal(-4)))
        CFI ?RET_LOW load(1, XDATA, add(CFA_XSP16, literal(-5)))
        CFI R7 load(1, XDATA, add(CFA_XSP16, literal(-6)))
        CFI V1 load(1, XDATA, add(CFA_XSP16, literal(-7)))
        CFI V0 load(1, XDATA, add(CFA_XSP16, literal(-8)))
        CFI VB load(1, XDATA, add(CFA_XSP16, literal(-9)))
        CFI R6 load(1, XDATA, add(CFA_XSP16, literal(-10)))
        CFI CFA_SP SP+0
        CFI CFA_XSP16 add(XSP16, 10)
        ; Saved register size: 10
        ; Auto size: 2
        MOV	A,#-0x2
        LCALL	?ALLOC_XSTACK8
        CFI CFA_XSP16 add(XSP16, 12)
        MOV	DPL,?XSP + 0
        MOV	DPH,?XSP + 1
        MOV	A,R2
        MOVX	@DPTR,A
        INC	DPTR
        MOV	A,R3
        MOVX	@DPTR,A
//  517   uint8 networkStateNV = ZDO_INITDEV_NEW_NETWORK_STATE;
//  518   uint16 extendedDelay = 0;
//  519 
//  520   devState = DEV_INIT;    // Remove the Hold state
        MOV	A,#0x1
        MOV	DPTR,#devState
        MOVX	@DPTR,A
//  521 
//  522   // Initialize leave control logic
//  523   ZDApp_LeaveCtrlInit();
        ; Setup parameters for call to function ZDApp_LeaveCtrlInit
        MOV	DPTR,#(ZDApp_LeaveCtrlInit & 0xffff)
        MOV	A,#((ZDApp_LeaveCtrlInit >> 16) & 0xff)
        LCALL	?BCALL               ; Banked call to: DPTR()
//  524 
//  525   // Check leave control reset settings
//  526   ZDApp_LeaveCtrlStartup( &devState, &startDelay );
        ; Setup parameters for call to function ZDApp_LeaveCtrlStartup
        MOV	DPL,?XSP + 0
        MOV	DPH,?XSP + 1
        MOV	R4,DPL
        MOV	R5,DPH
        MOV	R2,#(devState & 0xff)
        MOV	R3,#((devState >> 8) & 0xff)
        MOV	DPTR,#(ZDApp_LeaveCtrlStartup & 0xffff)
        MOV	A,#((ZDApp_LeaveCtrlStartup >> 16) & 0xff)
        LCALL	?BCALL               ; Banked call to: DPTR()
//  527 
//  528   // Leave may make the hold state come back
//  529   if ( devState == DEV_HOLD )
        MOV	DPTR,#devState
        MOVX	A,@DPTR
        JNZ	??ZDOInitDevice_0
//  530     return ( ZDO_INITDEV_LEAVE_NOT_STARTED );   // Don't join - (one time).
        MOV	R1,#0x2
        SJMP	??ZDOInitDevice_1
//  531 
//  532 #if defined ( NV_RESTORE )
//  533   // Get Keypad directly to see if a reset nv is needed.
//  534   // Hold down the SW_BYPASS_NV key (defined in OnBoard.h)
//  535   // while booting to skip past NV Restore.
//  536   if ( HalKeyRead() == SW_BYPASS_NV )
//  537     networkStateNV = ZDO_INITDEV_NEW_NETWORK_STATE;
//  538   else
//  539   {
//  540     // Determine if NV should be restored
//  541     networkStateNV = ZDApp_ReadNetworkRestoreState();
//  542   }
//  543 
//  544   if ( networkStateNV == ZDO_INITDEV_RESTORED_NETWORK_STATE )
//  545   {
//  546     networkStateNV = ZDApp_RestoreNetworkState();
//  547   }
//  548   else
//  549   {
//  550     // Wipe out the network state in NV
//  551     NLME_InitNV();
//  552     NLME_SetDefaultNV();
//  553     ZDAppSetupProtoVersion();
//  554   }
//  555 #endif
//  556 
//  557   if ( networkStateNV == ZDO_INITDEV_NEW_NETWORK_STATE )
//  558   {
//  559     ZDAppDetermineDeviceType();
//  560 
//  561     // Only delay if joining network - not restoring network state
//  562     extendedDelay = (uint16)((NWK_START_DELAY + startDelay)
//  563               + (osal_rand() & EXTENDED_JOINING_RANDOM_MASK));
??ZDOInitDevice_0:
        ; Setup parameters for call to function osal_rand
        MOV	DPTR,#(osal_rand & 0xffff)
        MOV	A,#((osal_rand >> 16) & 0xff)
        LCALL	?BCALL               ; Banked call to: DPTR()
        MOV	?V0 + 0,R2
        MOV	R0,?V0 + 0
        MOV	DPL,?XSP + 0
        MOV	DPH,?XSP + 1
        MOV	A,#0x7f
        ANL	A,R0
        MOV	R0,A
        MOVX	A,@DPTR
        ADD	A,R0
        MOV	R0,A
        INC	DPTR
        MOVX	A,@DPTR
        ADDC	A,#0x0
        MOV	R1,A
        MOV	A,#0x64
        ADD	A,R0
        MOV	R2,A
        CLR	A
        ADDC	A,R1
        MOV	R3,A
//  564   }
//  565 
//  566   // Trigger the network start
//  567   

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -