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

📄 zdapp.s51

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

        RSEG BANKED_CODE:CODE:NOROOT(0)
//  512 uint8 ZDOInitDevice( uint16 startDelay )
ZDOInitDevice:
        CFI Block cfiBlock2 Using cfiCommon0
        CFI Function ZDOInitDevice
//  513 {
        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
//  514   uint8 networkStateNV = ZDO_INITDEV_NEW_NETWORK_STATE;
//  515   uint16 extendedDelay = 0;
//  516 
//  517   devState = DEV_INIT;    // Remove the Hold state
        MOV	A,#0x1
        MOV	DPTR,#devState
        MOVX	@DPTR,A
//  518 
//  519   // Initialize leave control logic
//  520   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()
//  521 
//  522   // Check leave control reset settings
//  523   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()
//  524 
//  525   // Leave may make the hold state come back
//  526   if ( devState == DEV_HOLD )
        MOV	DPTR,#devState
        MOVX	A,@DPTR
        JNZ	??ZDOInitDevice_0
//  527     return ( ZDO_INITDEV_LEAVE_NOT_STARTED );   // Don't join - (one time).
        MOV	R1,#0x2
        SJMP	??ZDOInitDevice_1
//  528 
//  529 #if defined ( NV_RESTORE )
//  530   // Get Keypad directly to see if a reset nv is needed.
//  531   // Hold down the SW_BYPASS_NV key (defined in OnBoard.h)
//  532   // while booting to skip past NV Restore.
//  533   if ( HalKeyRead() == SW_BYPASS_NV )
//  534     networkStateNV = ZDO_INITDEV_NEW_NETWORK_STATE;
//  535   else
//  536   {
//  537     // Determine if NV should be restored
//  538     networkStateNV = ZDApp_ReadNetworkRestoreState();
//  539   }
//  540 
//  541   if ( networkStateNV == ZDO_INITDEV_RESTORED_NETWORK_STATE )
//  542   {
//  543     networkStateNV = ZDApp_RestoreNetworkState();
//  544   }
//  545   else
//  546   {
//  547     // Wipe out the network state in NV
//  548     NLME_InitNV();
//  549     NLME_SetDefaultNV();
//  550     ZDAppSetupProtoVersion();
//  551   }
//  552 #endif
//  553 
//  554   if ( networkStateNV == ZDO_INITDEV_NEW_NETWORK_STATE )
//  555   {
//  556     ZDAppDetermineDeviceType();
//  557 
//  558     // Only delay if joining network - not restoring network state
//  559     extendedDelay = (uint16)((NWK_START_DELAY + startDelay)
//  560               + (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
//  561   }
//  562 
//  563   // Trigger the network start
//  564   ZDApp_NetworkInit( extendedDelay );
        ; Setup parameters for call to function ZDApp_NetworkInit
        MOV	DPTR,#(ZDApp_NetworkInit & 0xffff)
        MOV	A,#((ZDApp_Ne

⌨️ 快捷键说明

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