###############################################################################
#                                                                             #
# IAR 8051 C/C++ Compiler V7.30B/W32                    21/Jun/2010  17:06:56 #
# Copyright 2004-2007 IAR Systems. All rights reserved.                       #
#                                                                             #
#    Core               =  plain                                              #
#    Code model         =  banked                                             #
#    Data model         =  large                                              #
#    Calling convention =  xdata reentrant                                    #
#    Constant location  =  data                                               #
#    Dptr setup         =  1,16                                               #
#    Source file        =  C:\Texas Instruments\ZStack-1.4.3-1.2.1\Components #
#                          \stack\zdo\ZDApp.c                                 #
#    Command line       =  -f "C:\Texas Instruments\ZStack-1.4.3-1.2.1\Projec #
#                          ts\zstack\Project\Location\CC2430DB\..\..\..\Tools #
#                          \CC2430DB\f8wCoord.cfg" (-DCPU32MHZ                #
#                          -DFORCE_MAC_NEAR -DROOT=__near_func                #
#                          -DMAC_CFG_APP_PENDING_QUEUE=TRUE                   #
#                          -DZDO_COORDINATOR -DRTR_NWK -DBLINK_LEDS           #
#                          "-DCONST=const __code" -DGENERIC=__generic) -f     #
#                          "C:\Texas Instruments\ZStack-1.4.3-1.2.1\Projects\ #
#                          zstack\Project\Location\CC2430DB\..\..\..\Tools\CC #
#                          2430DB\f8wConfig.cfg" (-DSECURE=1                  #
#                          -DDEFAULT_CHANLIST=0x04000000                      #
#                          -DZDAPP_CONFIG_PAN_ID=0x00FF                       #
#                          -DNWK_START_DELAY=100 -DEXTENDED_JOINING_RANDOM_MA #
#                          SK=0x007F -DBEACON_REQUEST_DELAY=100               #
#                          -DBEACON_REQ_DELAY_MASK=0x00FF                     #
#                          -DROUTE_EXPIRY_TIME=30 -DAPSC_ACK_WAIT_DURATION_PO #
#                          LLED=3000 -DNWK_INDIRECT_MSG_TIMEOUT=7             #
#                          -DMAX_RREQ_ENTRIES=10 -DAPSC_MAX_FRAME_RETRIES=3   #
#                          -DNWK_MAX_DATA_RETRIES=2                           #
#                          -DMAX_POLL_FAILURE_RETRIES=2 -DMAX_BCAST=9         #
#                          -DAPS_MAX_GROUPS=16 -DMAX_RTG_ENTRIES=20           #
#                          -DNWK_MAX_BINDING_ENTRIES=10                       #
#                          -DMAX_BINDING_CLUSTER_IDS=5 "-DDEFAULT_KEY={0x02,  #
#                          0x03, 0x05, 0x07, 0x09, 0x0B, 0x0D, 0x0F, 0x00,    #
#                          0x02, 0x04, 0x06, 0x08, 0x0A, 0x0C, 0x0D}"         #
#                          -DRFD_RCVC_ALWAYS_ON=FALSE -DPOLL_RATE=1000        #
#                          -DQUEUED_POLL_RATE=100 -DRESPONSE_POLL_RATE=100)   #
#                          -DREJOIN_POLL_RATE=440 "C:\Texas                   #
#                          Instruments\ZStack-1.4.3-1.2.1\Components\stack\zd #
#                          o\ZDApp.c" -D CC2430EB -D ZTOOL_P1 -D              #
#                          LOCATION_DONGLE -D MT_TASK -D xNV_RESTORE -D       #
#                          INT_HEAP_LEN=4608 -D HAL_UART_BIG_TX_BUF=1 -D      #
#                          SPI_MGR_DEFAULT_MAX_TX_BUFF=1024 -D                #
#                          SPI_MGR_DEFAULT_OVERFLOW=1 -lC "C:\Texas           #
#                          Instruments\ZStack-1.4.3-1.2.1\Projects\zstack\Pro #
#                          ject\Location\CC2430DB\LocDongle\List\" -lA        #
#                          "C:\Texas Instruments\ZStack-1.4.3-1.2.1\Projects\ #
#                          zstack\Project\Location\CC2430DB\LocDongle\List\"  #
#                          --diag_suppress Pe001,Pa010 --diag_remark pe550    #
#                          -o "C:\Texas Instruments\ZStack-1.4.3-1.2.1\Projec #
#                          ts\zstack\Project\Location\CC2430DB\LocDongle\Obj\ #
#                          " -e --require_prototypes -z9 --no_code_motion     #
#                          --debug --core=plain --dptr=16,1                   #
#                          --data_model=large --code_model=banked             #
#                          --calling_convention=xdata_reentrant               #
#                          --place_constants=data --nr_virtual_regs 8 -I      #
#                          "C:\Texas Instruments\ZStack-1.4.3-1.2.1\Projects\ #
#                          zstack\Project\Location\CC2430DB\" -I "C:\Texas    #
#                          Instruments\ZStack-1.4.3-1.2.1\Projects\zstack\Pro #
#                          ject\Location\CC2430DB\..\SOURCE\" -I "C:\Texas    #
#                          Instruments\ZStack-1.4.3-1.2.1\Projects\zstack\Pro #
#                          ject\Location\CC2430DB\..\..\..\ZMAIN\TI2430DB\"   #
#                          -I "C:\Texas Instruments\ZStack-1.4.3-1.2.1\Projec #
#                          ts\zstack\Project\Location\CC2430DB\..\..\..\..\WX #
#                          L\INCLUDE\" -I "C:\Texas                           #
#                          Instruments\ZStack-1.4.3-1.2.1\Projects\zstack\Pro #
#                          ject\Location\CC2430DB\..\..\..\..\..\COMPONENTS\M #
#                          T\" -I "C:\Texas Instruments\ZStack-1.4.3-1.2.1\Pr #
#                          ojects\zstack\Project\Location\CC2430DB\..\..\..\. #
#                          .\..\COMPONENTS\HAL\INCLUDE\" -I "C:\Texas         #
#                          Instruments\ZStack-1.4.3-1.2.1\Projects\zstack\Pro #
#                          ject\Location\CC2430DB\..\..\..\..\..\COMPONENTS\H #
#                          AL\TARGET\CC2430EB\" -I "C:\Texas                  #
#                          Instruments\ZStack-1.4.3-1.2.1\Projects\zstack\Pro #
#                          ject\Location\CC2430DB\..\..\..\..\..\COMPONENTS\O #
#                          SAL\MCU\CCSOC\" -I "C:\Texas                       #
#                          Instruments\ZStack-1.4.3-1.2.1\Projects\zstack\Pro #
#                          ject\Location\CC2430DB\..\..\..\..\..\COMPONENTS\O #
#                          SAL\INCLUDE\" -I "C:\Texas                         #
#                          Instruments\ZStack-1.4.3-1.2.1\Projects\zstack\Pro #
#                          ject\Location\CC2430DB\..\..\..\..\..\COMPONENTS\S #
#                          TACK\AF\" -I "C:\Texas Instruments\ZStack-1.4.3-1. #
#                          2.1\Projects\zstack\Project\Location\CC2430DB\..\. #
#                          .\..\..\..\COMPONENTS\STACK\NWK\" -I "C:\Texas     #
#                          Instruments\ZStack-1.4.3-1.2.1\Projects\zstack\Pro #
#                          ject\Location\CC2430DB\..\..\..\..\..\COMPONENTS\S #
#                          TACK\SEC\" -I "C:\Texas Instruments\ZStack-1.4.3-1 #
#                          .2.1\Projects\zstack\Project\Location\CC2430DB\..\ #
#                          ..\..\..\..\COMPONENTS\STACK\SYS\" -I "C:\Texas    #
#                          Instruments\ZStack-1.4.3-1.2.1\Projects\zstack\Pro #
#                          ject\Location\CC2430DB\..\..\..\..\..\COMPONENTS\S #
#                          TACK\ZDO\" -I "C:\Texas Instruments\ZStack-1.4.3-1 #
#                          .2.1\Projects\zstack\Project\Location\CC2430DB\..\ #
#                          ..\..\..\..\COMPONENTS\ZMAC\F8W\" -I "C:\Texas     #
#                          Instruments\ZStack-1.4.3-1.2.1\Projects\zstack\Pro #
#                          ject\Location\CC2430DB\..\..\..\..\..\COMPONENTS\Z #
#                          MAC\" -I "C:\Texas Instruments\ZStack-1.4.3-1.2.1\ #
#                          Projects\zstack\Project\Location\CC2430DB\..\..\.. #
#                          \..\..\COMPONENTS\SERVICES\SADDR\" -I "C:\Texas    #
#                          Instruments\ZStack-1.4.3-1.2.1\Projects\zstack\Pro #
#                          ject\Location\CC2430DB\..\..\..\..\..\COMPONENTS\S #
#                          ERVICES\SDATA\" -I "C:\Texas                       #
#                          Instruments\ZStack-1.4.3-1.2.1\Projects\zstack\Pro #
#                          ject\Location\CC2430DB\..\..\..\..\..\COMPONENTS\M #
#                          AC\INCLUDE\" -I "C:\Texas                          #
#                          Instruments\ZStack-1.4.3-1.2.1\Projects\zstack\Pro #
#                          ject\Location\CC2430DB\..\..\..\..\..\COMPONENTS\M #
#                          AC\HIGH_LEVEL\" -I "C:\Texas                       #
#                          Instruments\ZStack-1.4.3-1.2.1\Projects\zstack\Pro #
#                          ject\Location\CC2430DB\..\..\..\..\..\COMPONENTS\M #
#                          AC\LOW_LEVEL\SRF03\" -I "C:\Texas                  #
#                          Instruments\ZStack-1.4.3-1.2.1\Projects\zstack\Pro #
#                          ject\Location\CC2430DB\..\..\..\..\..\COMPONENTS\M #
#                          AC\LOW_LEVEL\SRF03\SINGLE_CHIP\" -I "C:\Program    #
#                          Files\IAR Systems\Embedded Workbench 4.0           #
#                          Evaluation version\8051\INC\" -I "C:\Program       #
#                          Files\IAR Systems\Embedded Workbench 4.0           #
#                          Evaluation version\8051\INC\CLIB\"                 #
#    List file          =  C:\Texas Instruments\ZStack-1.4.3-1.2.1\Projects\z #
#                          stack\Project\Location\CC2430DB\LocDongle\List\ZDA #
#                          pp.lst                                             #
#    Object file        =  C:\Texas Instruments\ZStack-1.4.3-1.2.1\Projects\z #
#                          stack\Project\Location\CC2430DB\LocDongle\Obj\ZDAp #
#                          p.r51                                              #
#                                                                             #
#                                                                             #
###############################################################################

C:\Texas Instruments\ZStack-1.4.3-1.2.1\Components\stack\zdo\ZDApp.c
      1          /**************************************************************************************************
      2            Filename:       ZDApp.c
      3            Revised:        $Date: 2007-11-28 15:44:45 -0800 (Wed, 28 Nov 2007) $
      4            Revision:       $Revision: 15983 $
      5          
      6            Description:    This file contains the interface to the Zigbee Device Application. This is the
      7                            Application part that the use can change. This also contains the Task functions.
      8          
      9          
     10            Copyright 2004-2007 Texas Instruments Incorporated. All rights reserved.
     11          
     12            IMPORTANT: Your use of this Software is limited to those specific rights
     13            granted under the terms of a software license agreement between the user
     14            who downloaded the software, his/her employer (which must be your employer)
     15            and Texas Instruments Incorporated (the "License").  You may not use this
     16            Software unless you agree to abide by the terms of the License. The License
     17            limits your use, and you acknowledge, that the Software may not be modified,
     18            copied or distributed unless embedded on a Texas Instruments microcontroller
     19            or used solely and exclusively in conjunction with a Texas Instruments radio
     20            frequency transceiver, which is integrated into your product.  Other than for
     21            the foregoing purpose, you may not use, reproduce, copy, prepare derivative
     22            works of, modify, distribute, perform, display or sell this Software and/or
     23            its documentation for any purpose.
     24          
     25            YOU FURTHER ACKNOWLEDGE AND AGREE THAT THE SOFTWARE AND DOCUMENTATION ARE
     26            PROVIDED “AS IS?WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED,
     27            INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY, TITLE,
     28            NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL
     29            TEXAS INSTRUMENTS OR ITS LICENSORS BE LIABLE OR OBLIGATED UNDER CONTRACT,
     30            NEGLIGENCE, STRICT LIABILITY, CONTRIBUTION, BREACH OF WARRANTY, OR OTHER
     31            LEGAL EQUITABLE THEORY ANY DIRECT OR INDIRECT DAMAGES OR EXPENSES
     32            INCLUDING BUT NOT LIMITED TO ANY INCIDENTAL, SPECIAL, INDIRECT, PUNITIVE
     33            OR CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, COST OF PROCUREMENT
     34            OF SUBSTITUTE GOODS, TECHNOLOGY, SERVICES, OR ANY CLAIMS BY THIRD PARTIES
     35            (INCLUDING BUT NOT LIMITED TO ANY DEFENSE THEREOF), OR OTHER SIMILAR COSTS.
     36          
     37            Should you have any questions regarding your right to use this Software,
     38            contact Texas Instruments Incorporated at www.TI.com.
     39          **************************************************************************************************/
     40          
     41          /*********************************************************************
     42           * INCLUDES
     43           */
     44          #include "ZComDef.h"
     45          #include "ZMac.h"
     46          #include "OSAL.h"
     47          #include "OSAL_Tasks.h"
     48          #include "OSAL_PwrMgr.h"
     49          #include "OSAL_Nv.h"
     50          #include "AF.h"
     51          #include "APSMEDE.h"
     52          #include "NLMEDE.h"
     53          #include "AddrMgr.h"
     54          #include "ZDProfile.h"
     55          #include "ZDObject.h"
     56          #include "ZDConfig.h"
     57          #include "ZDSecMgr.h"
     58          #include "ZDApp.h"
     59          #include "DebugTrace.h"
     60          #include "nwk_util.h"
     61          #include "OnBoard.h"

   \                                 In  segment SFR_AN, at 0xa8
   \   union <unnamed> volatile __sfr _A_IEN0
   \                     _A_IEN0:
   \   000000                DS 1

   \                                 In  segment SFR_AN, at 0xc9
   \   unsigned char volatile __sfr WDCTL
   \                     WDCTL:
   \   000000                DS 1
     62          #include "ZGlobals.h"
     63          
     64          #if   ( SECURE != 0  )
     65            #include "ssp.h"
     66          #endif
     67          
     68          #if defined( MT_ZDO_FUNC )
     69            #include "MT_ZDO.h"
     70          #endif
     71          
     72          /* HAL */
     73          #include "hal_led.h"
     74          //#include "hal_lcd.h"
     75          #if defined( LCD_SUPPORTED )
     76            #include "lcd128_64.h"
     77          #endif
     78          #include "hal_key.h"
     79          
     80          #if defined( MT_MAC_FUNC ) || defined( MT_MAC_CB_FUNC )
     81            #error "ERROR! MT_MAC functionalities should be disabled on ZDO devices"
     82          #endif
     83          /*********************************************************************
     84           * MACROS
     85           */
     86          
     87          /*********************************************************************
     88           * CONSTANTS
     89           */
     90          #if !defined( NWK_START_DELAY )
     91            #define NWK_START_DELAY             100   // in milliseconds
     92          #endif
     93          
     94          #if !defined( EXTENDED_JOINING_RANDOM_MASK )
     95            #define EXTENDED_JOINING_RANDOM_MASK 0x007F
     96          #endif
     97          
     98          #if !defined( BEACON_REQUEST_DELAY )
     99            #define BEACON_REQUEST_DELAY        100   // in milliseconds
    100          #endif
    101          
    102          #if !defined( BEACON_REQ_DELAY_MASK )
    103            #define BEACON_REQ_DELAY_MASK       0x007F
    104          #endif
    105          
    106          #if defined (AUTO_SOFT_START)
    107            #define MAX_RESUME_RETRY            3
    108            #define NUM_DISC_ATTEMPTS           3
    109          #else
    110            #define MAX_RESUME_RETRY            1
    111          #endif
    112          
    113          #define MAX_DEVICE_UNAUTH_TIMEOUT   5000  // 5 seconds
    114          
    115          // Beacon Order Settings (see NLMEDE.h)
    116          #define DEFAULT_BEACON_ORDER        BEACON_ORDER_NO_BEACONS
    117          #define DEFAULT_SUPERFRAME_ORDER    DEFAULT_BEACON_ORDER
    118          
    119          #if ( SECURE != 0 )
    120            #if !defined( MAX_NWK_FRAMECOUNTER_CHANGES )
    121              // The number of times the frame counter can change before
    122              // saving to NV
    123              #define MAX_NWK_FRAMECOUNTER_CHANGES    1000
    124            #endif
    125          #endif
    126          
    127          // Leave control bits
    128          #define ZDAPP_LEAVE_CTRL_INIT 0
    129          #define ZDAPP_LEAVE_CTRL_SET  1
    130          #define ZDAPP_LEAVE_CTRL_RA   2
    131          
    132          // Standard time to update NWK NV data
    133          #define ZDAPP_UPDATE_NWK_NV_TIME 700
    134          
    135          // Address Manager Stub Implementation
    136          #define ZDApp_NwkWriteNVRequest AddrMgrWriteNVRequest
    137          
    138          /*********************************************************************
    139           * TYPEDEFS
    140           */
    141          
    142          /*********************************************************************
    143           * GLOBAL VARIABLES
    144           */
    145          
    146          #if defined( LCD_SUPPORTED )
    147            byte MatchRsps = 0;
    148          #endif
    149          

   \                                 In  segment XDATA_I, align 1, keep-with-next
    150          byte zdoDiscCounter = 1;
   \                     zdoDiscCounter:
   \   000000                DS 1
   \   000001                REQUIRE `?<Initializer for zdoDiscCounter>`
   \   000001                REQUIRE __INIT_XDATA_I
    151          

   \                                 In  segment XDATA_Z, align 1, keep-with-next
    152          zAddrType_t ZDAppNwkAddr;
   \                     ZDAppNwkAddr:
   \   000000                DS 9
   \   000009                REQUIRE __INIT_XDATA_Z
    153          
    154          #if defined ( ZDO_MGMT_NWKDISC_RESPONSE )
    155            byte zdappMgmtNwkDiscRspTransSeq;
    156            byte zdappMgmtNwkDiscReqInProgress = FALSE;
    157            zAddrType_t zdappMgmtNwkDiscRspAddr;
    158            byte zdappMgmtNwkDiscStartIndex;
    159            byte zdappMgmtSavedNwkState;
    160          #endif
    161          
    162          #if ( SECURE != 0 )

   \                                 In  segment XDATA_Z, align 1, keep-with-next
    163            uint16 nwkFrameCounterChanges = 0;
   \                     nwkFrameCounterChanges:
   \   000000                DS 2
   \   000002                REQUIRE __INIT_XDATA_Z
    164          #endif
    165          
    166          #if defined ( SOFT_START )
    167            static uint8 softStartAllowCoord = TRUE;
    168          #endif
    169          

   \                                 In  segment XDATA_I, align 1, keep-with-next
    170          uint8 continueJoining = TRUE;
   \                     continueJoining:
   \   000000                DS 1
   \   000001                REQUIRE `?<Initializer for continueJoining>`
   \   000001                REQUIRE __INIT_XDATA_I
    171          

   \                                 In  segment XDATA_Z, align 1, keep-with-next
    172          byte  _tmpRejoinState;
   \                     _tmpRejoinState:
   \   000000                DS 1
   \   000001                REQUIRE __INIT_XDATA_Z
    173          
    174          /*********************************************************************
    175           * EXTERNAL VARIABLES
    176           */
    177          
    178          /*********************************************************************
    179           * EXTERNAL FUNCTIONS
    180           */
    181          
    182          /*********************************************************************
    183           * LOCAL FUNCTIONS
    184           */
    185          
    186          void ZDApp_NetworkStartEvt( void );
    187          void ZDApp_DeviceAuthEvt( void );
    188          void ZDApp_SaveNetworkStateEvt( void );
    189          
    190          uint8 ZDApp_ReadNetworkRestoreState( void );
    191          uint8 ZDApp_RestoreNetworkState( void );
    192          void ZDAppDetermineDeviceType( void );
    193          void ZDApp_InitUserDesc( void );
    194          void ZDAppCheckForHoldKey( void );
    195          void ZDApp_ProcessOSALMsg( osal_event_hdr_t *msgPtr );
    196          void ZDApp_ProcessNetworkJoin( void );
    197          void ZDApp_SetCoordAddress( byte endPoint, byte dstEP );
    198          
    199          #if ( SECURE != 0 )
    200            void ZDApp_SaveNwkKey( void );
    201            byte ZDApp_RestoreNwkKey( void );
    202          #endif
    203          
    204          void ZDApp_SendMsg( byte taskID, byte cmd, byte len, byte *buf );
    205          
    206          void ZDApp_ResetTimerStart( uint16 delay );
    207          void ZDApp_ResetTimerCancel( void );
    208          void ZDApp_LeaveCtrlInit( void );
    209          void ZDApp_LeaveCtrlSet( uint8 ra );
    210          uint8 ZDApp_LeaveCtrlBypass( void );
    211          void ZDApp_LeaveCtrlStartup( devStates_t* state, uint16* startDelay );
    212          void ZDApp_LeaveReset( uint8 ra );
    213          void ZDApp_LeaveUpdate( uint16 nwkAddr, uint8* extAddr,
    214                                  uint8 removeChildren );
    215          void ZDApp_NodeProfileSync( ZDO_NetworkDiscoveryCfm_t* cfm );
    216          void ZDApp_ProcessMsgCBs( zdoIncomingMsg_t *inMsg );
    217          void ZDApp_RegisterCBs( void );
    218          void ZDApp_SecInit( uint8 state );
    219          
    220          /*********************************************************************
    221           * LOCAL VARIABLES
    222           */
    223          

   \                                 In  segment XDATA_Z, align 1, keep-with-next
    224          byte ZDAppTaskID;
   \                     ZDAppTaskID:
   \   000000                DS 1
   \   000001                REQUIRE __INIT_XDATA_Z

   \                                 In  segment XDATA_Z, align 1, keep-with-next
    225          byte nwkStatus;
   \                     nwkStatus:
   \   000000                DS 1
   \   000001                REQUIRE __INIT_XDATA_Z

   \                                 In  segment XDATA_Z, align 1, keep-with-next
    226          endPointDesc_t *ZDApp_AutoFindMode_epDesc = (endPointDesc_t *)NULL;
   \                     ZDApp_AutoFindMode_epDesc:
   \   000000                DS 2
   \   000002                REQUIRE __INIT_XDATA_Z

   \                                 In  segment XDATA_Z, align 1, keep-with-next
    227          uint8 ZDApp_LeaveCtrl;
   \                     ZDApp_LeaveCtrl:
   \   000000                DS 1
   \   000001                REQUIRE __INIT_XDATA_Z
    228          
    229          #if defined( HOLD_AUTO_START )
    230            devStates_t devState = DEV_HOLD;
    231          #else

   \                                 In  segment XDATA_I, align 1, keep-with-next
    232            devStates_t devState = DEV_INIT;
   \                     devState:
   \   000000                DS 1
   \   000001                REQUIRE `?<Initializer for devState>`
   \   000001                REQUIRE __INIT_XDATA_I
    233          #endif
    234          
    235          #if defined( ZDO_COORDINATOR ) && !defined( SOFT_START )
    236            // Set the default to coodinator

   \                                 In  segment XDATA_I, align 1, keep-with-next
    237            devStartModes_t devStartMode = MODE_HARD;
   \                     devStartMode:
   \   000000                DS 1
   \   000001                REQUIRE `?<Initializer for devStartMode>`
   \   000001                REQUIRE __INIT_XDATA_I
    238          #else
    239            devStartModes_t devStartMode = MODE_JOIN;     // Assume joining
    240            //devStartModes_t devStartMode = MODE_RESUME; // if already "directly joined"
    241                                  // to parent. Set to make the device do an Orphan scan.
    242          #endif
    243          
    244          #if !defined( ZDO_COORDINATOR ) || defined( SOFT_START )
    245            static uint8 retryCnt;
    246          #endif
    247          

   \                                 In  segment XDATA_I, align 1, keep-with-next
    248          endPointDesc_t ZDApp_epDesc =
   \                     ZDApp_epDesc:
   \   000000                DS 6
   \   000006                REQUIRE `?<Initializer for ZDApp_epDesc>`
   \   000006                REQUIRE __INIT_XDATA_I
    249          {
    250            ZDO_EP,
    251            &ZDAppTaskID,
    252            (SimpleDescriptionFormat_t *)NULL,  // No Simple description for ZDO
    253            (afNetworkLatencyReq_t)0            // No Network Latency req
    254          };
    255          
    256          /*********************************************************************
    257           * @fn      ZDApp_Init
    258           *
    259           * @brief   ZDApp Initialization function.
    260           *
    261           * @param   task_id - ZDApp Task ID
    262           *
    263           * @return  None
    264           */

   \                                 In  segment BANKED_CODE, align 1, keep-with-next
    265          void ZDApp_Init( byte task_id )
   \                     ZDApp_Init:
    266          {
   \   000000   C082         PUSH    DPL
   \   000002   C083         PUSH    DPH
   \   000004                ; Saved register size: 2
   \   000004                ; Auto size: 1
   \   000004   74FF         MOV     A,#-0x1
   \   000006   12....       LCALL   ?ALLOC_XSTACK8
    267            uint8 capabilities;
    268          
    269            // Save the task ID
    270            ZDAppTaskID = task_id;
   \   000009   E9           MOV     A,R1
   \   00000A   90....       MOV     DPTR,#ZDAppTaskID
   \   00000D   F0           MOVX    @DPTR,A
    271          
    272            // Initialize the ZDO global device short address storage
    273            ZDAppNwkAddr.addrMode = Addr16Bit;
   \   00000E   7402         MOV     A,#0x2
   \   000010   90....       MOV     DPTR,#(ZDAppNwkAddr + 8)
   \   000013   F0           MOVX    @DPTR,A
    274            ZDAppNwkAddr.addr.shortAddr = INVALID_NODE_ADDR;
   \   000014   90....       MOV     DPTR,#ZDAppNwkAddr
   \   000017   74FE         MOV     A,#-0x2
   \   000019   F0           MOVX    @DPTR,A
   \   00001A   A3           INC     DPTR
   \   00001B   74FF         MOV     A,#-0x1
   \   00001D   F0           MOVX    @DPTR,A
    275            (void)NLME_GetExtAddr();  // Load the saveExtAddr pointer.
   \   00001E                ; Setup parameters for call to function NLME_GetExtAddr
   \   00001E   12....       LCALL   ??NLME_GetExtAddr?relay
    276          
    277            // Check for manual "Hold Auto Start"
    278            ZDAppCheckForHoldKey();
   \   000021                ; Setup parameters for call to function ZDAppCheckForHoldKey
   \   000021   12....       LCALL   ??ZDAppCheckForHoldKey?relay
    279          
    280            // Initialize ZDO items and setup the device - type of device to create.
    281            ZDO_Init();
   \   000024                ; Setup parameters for call to function ZDO_Init
   \   000024   12....       LCALL   ??ZDO_Init?relay
    282          
    283            // Register the endpoint description with the AF
    284            // This task doesn't have a Simple description, but we still need
    285            // to register the endpoint.
    286            afRegister( (endPointDesc_t *)&ZDApp_epDesc );
   \   000027                ; Setup parameters for call to function afRegister
   \   000027   7A..         MOV     R2,#(ZDApp_epDesc & 0xff)
   \   000029   7B..         MOV     R3,#((ZDApp_epDesc >> 8) & 0xff)
   \   00002B   12....       LCALL   ??afRegister?relay
    287          
    288          #if defined( ZDO_USERDESC_RESPONSE )
    289            ZDApp_InitUserDesc();
    290          #endif // ZDO_USERDESC_RESPONSE
    291          
    292            // set broadcast address mask to support broadcast filtering
    293            NLME_GetRequest(nwkCapabilityInfo, 0, &capabilities);
   \   00002E                ; Setup parameters for call to function NLME_GetRequest
   \   00002E   85..82       MOV     DPL,?XSP + 0
   \   000031   85..83       MOV     DPH,?XSP + 1
   \   000034   AC82         MOV     R4,DPL
   \   000036   AD83         MOV     R5,DPH
   \   000038   7A00         MOV     R2,#0x0
   \   00003A   7B00         MOV     R3,#0x0
   \   00003C   798F         MOV     R1,#-0x71
   \   00003E   12....       LCALL   ??NLME_GetRequest?relay
    294            NLME_SetBroadcastFilter( capabilities );
   \   000041                ; Setup parameters for call to function NLME_SetBroadcastFilter
   \   000041   85..82       MOV     DPL,?XSP + 0
   \   000044   85..83       MOV     DPH,?XSP + 1
   \   000047   E0           MOVX    A,@DPTR
   \   000048   F9           MOV     R1,A
   \   000049   12....       LCALL   ??NLME_SetBroadcastFilter?relay
    295          
    296            // Start the device?
    297            if ( devState != DEV_HOLD )
   \   00004C   90....       MOV     DPTR,#devState
   \   00004F   E0           MOVX    A,@DPTR
   \   000050   6009         JZ      ??ZDApp_Init_0
    298            {
    299              ZDOInitDevice( 0 );
   \   000052                ; Setup parameters for call to function ZDOInitDevice
   \   000052   7A00         MOV     R2,#0x0
   \   000054   7B00         MOV     R3,#0x0
   \   000056   12....       LCALL   ??ZDOInitDevice?relay
   \   000059   800D         SJMP    ??ZDApp_Init_1
    300            }
    301            else
    302            {
    303              // Blink LED to indicate HOLD_START
    304              HalLedBlink ( HAL_LED_4, 0, 50, 500 );
   \                     ??ZDApp_Init_0:
   \   00005B                ; Setup parameters for call to function HalLedBlink
   \   00005B   7CF4         MOV     R4,#-0xc
   \   00005D   7D01         MOV     R5,#0x1
   \   00005F   7B32         MOV     R3,#0x32
   \   000061   7A00         MOV     R2,#0x0
   \   000063   7908         MOV     R1,#0x8
   \   000065   12....       LCALL   ??HalLedBlink?relay
    305            }
    306          
    307            ZDApp_RegisterCBs();
   \                     ??ZDApp_Init_1:
   \   000068                ; Setup parameters for call to function ZDApp_RegisterCBs
   \   000068   12....       LCALL   ??ZDApp_RegisterCBs?relay
    308          } /* ZDO_Init() */
   \   00006B   7401         MOV     A,#0x1
   \   00006D   12....       LCALL   ?DEALLOC_XSTACK8
   \   000070   02....       LJMP    ??Subroutine16_0 & 0xFFFF

   \                                 In  segment BANKED_CODE, align 1, keep-with-next
   \                     ?Subroutine16:
   \   000000   12....       LCALL   ??Subroutine2_0 & 0xFFFF
   \                     ??Subroutine16_0:
   \   000003   D083         POP     DPH
   \   000005   D082         POP     DPL
   \   000007   02....       LJMP    ?BRET
    309          
    310          /*********************************************************************
    311           * @fn          ZDApp_SecInit
    312           *
    313           * @brief       ZDApp initialize security.
    314           *
    315           * @param       state - device initialization state
    316           *
    317           * @return      none
    318           */

   \                                 In  segment BANKED_CODE, align 1, keep-with-next
    319          void ZDApp_SecInit( uint8 state )
   \                     ZDApp_SecInit:
    320          {
   \   000000   74F4         MOV     A,#-0xc
   \   000002   12....       LCALL   ?BANKED_ENTER_XDATA
   \   000005                ; Saved register size: 12
   \   000005                ; Auto size: 0
    321            // Initialize ZigBee Device Security Manager
    322            ZDSecMgrInit();
   \   000005                ; Setup parameters for call to function ZDSecMgrInit
   \   000005   12....       LCALL   ??ZDSecMgrInit?relay
    323          
    324            // -----------------------------------------------------------------
    325            #if ( SECURE != 0 )
    326            // -----------------------------------------------------------------
    327            nwkFrameCounter = 0;
   \   000008   90....       MOV     DPTR,#__Constant_0
   \   00000B   78..         MOV     R0,#?V0 + 0
   \   00000D   12....       LCALL   ?L_MOV_X
   \   000010   90....       MOV     DPTR,#nwkFrameCounter
   \   000013   78..         MOV     R0,#?V0 + 0
   \   000015   12....       LCALL   ?L_MOV_TO_X
    328          
    329            if( _NIB.nwkKeyLoaded == FALSE )
   \   000018   90....       MOV     DPTR,#(_NIB + 61)
   \   00001B   E0           MOVX    A,@DPTR
   \   00001C   700E         JNZ     ??ZDApp_SecInit_0
    330            {
    331              // ---------------------------------------------------------------
    332              #if ( SECURITY_MODE == SECURITY_RESIDENTIAL )
    333              // ---------------------------------------------------------------
    334              #if !defined (ZDO_COORDINATOR)
    335              if ( zgPreConfigKeys )
    336              #endif
    337              {
    338                SSP_UpdateNwkKey( (byte*)zgPreConfigKey, 0);
   \   00001E                ; Setup parameters for call to function SSP_UpdateNwkKey
   \   00001E   7900         MOV     R1,#0x0
   \   000020   7A..         MOV     R2,#(zgPreConfigKey & 0xff)
   \   000022   7B..         MOV     R3,#((zgPreConfigKey >> 8) & 0xff)
   \   000024   12....       LCALL   ??SSP_UpdateNwkKey?relay
    339                SSP_SwitchNwkKey( 0 );
   \   000027                ; Setup parameters for call to function SSP_SwitchNwkKey
   \   000027   7900         MOV     R1,#0x0
   \   000029   12....       LCALL   ??SSP_SwitchNwkKey?relay
    340              }
    341              // ---------------------------------------------------------------
    342              #endif // ( SECURITY_MODE == SECURITY_RESIDENTIAL )
    343              // ---------------------------------------------------------------
    344            }
    345          
    346            if ( state == ZDO_INITDEV_RESTORED_NETWORK_STATE )
    347            {
    348              //Restore NWK frame counter
    349            }
    350            // -----------------------------------------------------------------
    351            #endif
    352            // -----------------------------------------------------------------
    353          }
   \                     ??ZDApp_SecInit_0:
   \   00002C   02....       LJMP    ??Subroutine18_0 & 0xFFFF

   \                                 In  segment BANKED_CODE, align 1, keep-with-next
   \                     ?Subroutine18:
   \   000000   7415         MOV     A,#0x15
   \   000002   12....       LCALL   ?DEALLOC_XSTACK8
   \                     ??Subroutine18_0:
   \   000005   7F04         MOV     R7,#0x4
   \   000007   02....       LJMP    ?BANKED_LEAVE_XDATA
    354          
    355          /*********************************************************************
    356           * @fn      ZDApp_event_loop()
    357           *
    358           * @brief   Main event loop for Zigbee device objects task. This function
    359           *          should be called at periodic intervals.
    360           *
    361           * @param   task_id - Task ID
    362           * @param   events  - Bitmap of events
    363           *
    364           * @return  none
    365           */

   \                                 In  segment BANKED_CODE, align 1, keep-with-next
    366          UINT16 ZDApp_event_loop( byte task_id, UINT16 events )
   \                     ZDApp_event_loop:
    367          {
   \   000000   74F6         MOV     A,#-0xa
   \   000002   12....       LCALL   ?BANKED_ENTER_XDATA
   \   000005                ; Saved register size: 10
   \   000005                ; Auto size: 0
   \   000005   EA           MOV     A,R2
   \   000006   FE           MOV     R6,A
   \   000007   EB           MOV     A,R3
   \   000008   FF           MOV     R7,A
    368            uint8 *msg_ptr;
    369          
    370            if ( events & SYS_EVENT_MSG )
   \   000009   7480         MOV     A,#-0x80
   \   00000B   5F           ANL     A,R7
   \   00000C   F9           MOV     R1,A
   \   00000D   E4           CLR     A
   \   00000E   7001         JNZ     ??ZDApp_event_loop_0
   \   000010   E9           MOV     A,R1
   \                     ??ZDApp_event_loop_0:
   \   000011   7020         JNZ     ??ZDApp_event_loop_1
    371            {
    372              while ( (msg_ptr = osal_msg_receive( ZDAppTaskID )) )
    373              {
    374                ZDApp_ProcessOSALMsg( (osal_event_hdr_t *)msg_ptr );
    375          
    376                // Release the memory
    377                osal_msg_deallocate( msg_ptr );
    378              }
    379          
    380              // Return unprocessed events
    381              return (events ^ SYS_EVENT_MSG);
    382            }
    383          
    384            if ( events & ZDO_STATE_CHANGE_EVT )
   \   000013   EE           MOV     A,R6
   \   000014   5410         ANL     A,#0x10
   \   000016   6034         JZ      ??ZDApp_event_loop_2
    385            {
    386              ZDO_UpdateNwkStatus( devState );
   \   000018                ; Setup parameters for call to function ZDO_UpdateNwkStatus
   \   000018   90....       MOV     DPTR,#devState
   \   00001B   E0           MOVX    A,@DPTR
   \   00001C   F9           MOV     R1,A
   \   00001D   12....       LCALL   ??ZDO_UpdateNwkStatus?relay
    387          
    388              // Return unprocessed events
    389              return (events ^ ZDO_STATE_CHANGE_EVT);
   \   000020   7410         MOV     A,#0x10
   \                     ??ZDApp_event_loop_3:
   \   000022   6E           XRL     A,R6
   \   000023   FA           MOV     R2,A
   \   000024   EF           MOV     A,R7
   \                     ??ZDApp_event_loop_4:
   \   000025   FB           MOV     R3,A
   \   000026   02....       LJMP    ??ZDApp_event_loop_5 & 0xFFFF
    390            }
   \                     ??ZDApp_event_loop_6:
   \   000029                ; Setup parameters for call to function ZDApp_ProcessOSALMsg
   \   000029   12....       LCALL   ??ZDApp_ProcessOSALMsg?relay
   \   00002C                ; Setup parameters for call to function osal_msg_deallocate
   \   00002C   AA..         MOV     R2,?V0 + 0
   \   00002E   AB..         MOV     R3,?V0 + 1
   \   000030   12....       LCALL   ??osal_msg_deallocate?relay
   \                     ??ZDApp_event_loop_1:
   \   000033                ; Setup parameters for call to function osal_msg_receive
   \   000033   90....       MOV     DPTR,#ZDAppTaskID
   \   000036   E0           MOVX    A,@DPTR
   \   000037   F9           MOV     R1,A
   \   000038   12....       LCALL   ??osal_msg_receive?relay
   \   00003B   8A..         MOV     ?V0 + 0,R2
   \   00003D   8B..         MOV     ?V0 + 1,R3
   \   00003F   EA           MOV     A,R2
   \   000040   7001         JNZ     ??ZDApp_event_loop_7
   \   000042   EB           MOV     A,R3
   \                     ??ZDApp_event_loop_7:
   \   000043   70E4         JNZ     ??ZDApp_event_loop_6
   \   000045   EE           MOV     A,R6
   \   000046   FA           MOV     R2,A
   \   000047   7480         MOV     A,#-0x80
   \                     ??ZDApp_event_loop_8:
   \   000049   6F           XRL     A,R7
   \   00004A   80D9         SJMP    ??ZDApp_event_loop_4
    391          
    392          
    393            if ( events & ZDO_NETWORK_INIT )
   \                     ??ZDApp_event_loop_2:
   \   00004C   EE           MOV     A,R6
   \   00004D   A2E0         MOV     C,0xE0 /* A   */.0
   \   00004F   501D         JNC     ??ZDApp_event_loop_9
    394            {
    395              // Initialize apps and start the network
    396              devState = DEV_INIT;
   \   000051   7401         MOV     A,#0x1
   \   000053   90....       MOV     DPTR,#devState
   \   000056   F0           MOVX    @DPTR,A
    397              ZDO_StartDevice( (uint8)ZDO_Config_Node_Descriptor.LogicalType, devStartMode,
    398                               DEFAULT_BEACON_ORDER, DEFAULT_SUPERFRAME_ORDER );
   \   000057                ; Setup parameters for call to function ZDO_StartDevice
   \   000057   7C0F         MOV     R4,#0xf
   \   000059   7B0F         MOV     R3,#0xf
   \   00005B   90....       MOV     DPTR,#devStartMode
   \   00005E   E0           MOVX    A,@DPTR
   \   00005F   FA           MOV     R2,A
   \   000060   90....       MOV     DPTR,#ZDO_Config_Node_Descriptor
   \   000063   E0           MOVX    A,@DPTR
   \   000064   5407         ANL     A,#0x7
   \   000066   F9           MOV     R1,A
   \   000067   12....       LCALL   ??ZDO_StartDevice?relay
    399          
    400              // Return unprocessed events
    401              return (events ^ ZDO_NETWORK_INIT);
   \   00006A   7401         MOV     A,#0x1
   \                     ??ZDApp_event_loop_10:
   \   00006C   80B4         SJMP    ??ZDApp_event_loop_3
    402            }
    403          
    404          #if defined (RTR_NWK)
    405            if ( events & ZDO_NETWORK_START )
   \                     ??ZDApp_event_loop_9:
   \   00006E   5402         ANL     A,#0x2
   \   000070   6007         JZ      ??ZDApp_event_loop_11
    406            {
    407              ZDApp_NetworkStartEvt();
   \   000072                ; Setup parameters for call to function ZDApp_NetworkStartEvt
   \   000072   12....       LCALL   ??ZDApp_NetworkStartEvt?relay
    408          
    409              // Return unprocessed events
    410              return (events ^ ZDO_NETWORK_START);
   \   000075   7402         MOV     A,#0x2
   \   000077   80A9         SJMP    ??ZDApp_event_loop_3
    411            }
    412          #endif  //RTR_NWK
    413          
    414          #if defined ( RTR_NWK )
    415            if ( events & ZDO_ROUTER_START )
   \                     ??ZDApp_event_loop_11:
   \   000079   EE           MOV     A,R6
   \   00007A   5420         ANL     A,#0x20
   \   00007C   601D         JZ      ??ZDApp_event_loop_12
    416            {
    417              if ( nwkStatus == ZSuccess )
   \   00007E   90....       MOV     DPTR,#nwkStatus
   \   000081   E0           MOVX    A,@DPTR
   \   000082   7010         JNZ     ??ZDApp_event_loop_13
    418              {
    419                if ( devState == DEV_END_DEVICE )
   \   000084   90....       MOV     DPTR,#devState
   \   000087   E0           MOVX    A,@DPTR
   \   000088   6406         XRL     A,#0x6
   \   00008A   7003         JNZ     ??ZDApp_event_loop_14
    420                  devState = DEV_ROUTER;
   \   00008C   7407         MOV     A,#0x7
   \   00008E   F0           MOVX    @DPTR,A
    421          
    422                osal_pwrmgr_device( PWRMGR_ALWAYS_ON );
   \                     ??ZDApp_event_loop_14:
   \   00008F                ; Setup parameters for call to function osal_pwrmgr_device
   \   00008F   7900         MOV     R1,#0x0
   \   000091   12....       LCALL   ??osal_pwrmgr_device?relay
    423              }
    424              else
    425              {
    426                // remain as end device!!
    427              }
    428              osal_set_event( ZDAppTaskID, ZDO_STATE_CHANGE_EVT );
   \                     ??ZDApp_event_loop_13:
   \   000094                ; Setup parameters for call to function osal_set_event
   \   000094   12....       LCALL   ?Subroutine2 & 0xFFFF
    429          
    430              // Return unprocessed events
    431              return (events ^ ZDO_ROUTER_START);
   \                     ??CrossCallReturnLabel_48:
   \   000097   7420         MOV     A,#0x20
   \   000099   8087         SJMP    ??ZDApp_event_loop_3
    432            }
    433          #endif  // RTR
    434          
    435          
    436            if ( events & ZDO_COMMAND_CNF )
   \                     ??ZDApp_event_loop_12:
   \   00009B   EE           MOV     A,R6
   \   00009C   5408         ANL     A,#0x8
   \   00009E   6006         JZ      ??ZDApp_event_loop_15
    437            {
    438              // User defined logic
    439          
    440              // Return unprocessed events
    441              return (events ^ ZDO_COMMAND_CNF);
   \   0000A0   7408         MOV     A,#0x8
   \   0000A2   6E           XRL     A,R6
   \   0000A3   FA           MOV     R2,A
   \   0000A4   807C         SJMP    ??ZDApp_event_loop_5
    442            }
    443          
    444          #if defined( ZDSECMGR_SECURE ) && defined( RTR_NWK )
    445            if ( events & ZDO_NEW_DEVICE )
   \                     ??ZDApp_event_loop_15:
   \   0000A6   EE           MOV     A,R6
   \   0000A7   5440         ANL     A,#0x40
   \   0000A9   6014         JZ      ??ZDApp_event_loop_16
    446            {
    447              // process the new device event
    448              if ( ZDSecMgrNewDeviceEvent() == TRUE )
   \   0000AB                ; Setup parameters for call to function ZDSecMgrNewDeviceEvent
   \   0000AB   12....       LCALL   ??ZDSecMgrNewDeviceEvent?relay
   \   0000AE   E9           MOV     A,R1
   \   0000AF   6401         XRL     A,#0x1
   \   0000B1   7007         JNZ     ??CrossCallReturnLabel_7
    449              {
    450                osal_start_timerEx( ZDAppTaskID, ZDO_NEW_DEVICE, 1000 );
   \   0000B3                ; Setup parameters for call to function osal_start_timerEx
   \   0000B3   7CE8         MOV     R4,#-0x18
   \   0000B5   7D03         MOV     R5,#0x3
   \   0000B7   12....       LCALL   ?Subroutine4 & 0xFFFF
    451              }
    452          
    453              // Return unprocessed events
    454              return (events ^ ZDO_NEW_DEVICE);
   \                     ??CrossCallReturnLabel_7:
   \   0000BA   7440         MOV     A,#0x40
   \   0000BC   02....       LJMP    ??ZDApp_event_loop_3 & 0xFFFF
    455            }
    456          #endif  // ZDSECMGR_SECURE && RTR
    457          
    458          #if defined ( ZDSECMGR_COMMERCIAL )
    459            if ( events & ZDO_SECMGR_EVENT )
    460            {
    461              ZDSecMgrEvent();
    462          
    463              // Return unprocessed events
    464              return (events ^ ZDO_SECMGR_EVENT);
    465            }
    466          #endif // defined( ZDSECMGR_COMMERCIAL )
    467          
    468          #if   ( SECURE != 0  )
    469            if ( events & ZDO_DEVICE_AUTH )
   \                     ??ZDApp_event_loop_16:
   \   0000BF   EE           MOV     A,R6
   \   0000C0   5480         ANL     A,#0x80
   \   0000C2   6007         JZ      ??ZDApp_event_loop_17
    470            {
    471              ZDApp_DeviceAuthEvt();
   \   0000C4                ; Setup parameters for call to function ZDApp_DeviceAuthEvt
   \   0000C4   12....       LCALL   ??ZDApp_DeviceAuthEvt?relay
    472          
    473              // Return unprocessed events
    474              return (events ^ ZDO_DEVICE_AUTH);
   \   0000C7   7480         MOV     A,#-0x80
   \   0000C9   80A1         SJMP    ??ZDApp_event_loop_10
    475            }
    476          #endif  // SECURE
    477          
    478            if ( events & ZDO_NWK_UPDATE_NV )
   \                     ??ZDApp_event_loop_17:
   \   0000CB   7402         MOV     A,#0x2
   \   0000CD   5F           ANL     A,R7
   \   0000CE   F9           MOV     R1,A
   \   0000CF   E4           CLR     A
   \   0000D0   7001         JNZ     ??ZDApp_event_loop_18
   \   0000D2   E9           MOV     A,R1
   \                     ??ZDApp_event_loop_18:
   \   0000D3   6005         JZ      ??ZDApp_event_loop_19
    479            {
    480              ZDApp_SaveNetworkStateEvt();
    481          
    482              // Return unprocessed events
    483              return (events ^ ZDO_NWK_UPDATE_NV);
   \   0000D5   7402         MOV     A,#0x2
   \   0000D7   02....       LJMP    ??ZDApp_event_loop_8 & 0xFFFF
    484            }
    485          
    486          #if ( SECURE != 0  )
    487            if ( events & ZDO_FRAMECOUNTER_CHANGE )
   \                     ??ZDApp_event_loop_19:
   \   0000DA   7404         MOV     A,#0x4
   \   0000DC   5F           ANL     A,R7
   \   0000DD   F9           MOV     R1,A
   \   0000DE   E4           CLR     A
   \   0000DF   7001         JNZ     ??ZDApp_event_loop_20
   \   0000E1   E9           MOV     A,R1
   \                     ??ZDApp_event_loop_20:
   \   0000E2   602A         JZ      ??ZDApp_event_loop_21
    488            {
    489              if ( nwkFrameCounterChanges++ > MAX_NWK_FRAMECOUNTER_CHANGES )
   \   0000E4   90....       MOV     DPTR,#nwkFrameCounterChanges
   \   0000E7   E0           MOVX    A,@DPTR
   \   0000E8   F8           MOV     R0,A
   \   0000E9   A3           INC     DPTR
   \   0000EA   E0           MOVX    A,@DPTR
   \   0000EB   F9           MOV     R1,A
   \   0000EC   7401         MOV     A,#0x1
   \   0000EE   28           ADD     A,R0
   \   0000EF   FA           MOV     R2,A
   \   0000F0   E4           CLR     A
   \   0000F1   39           ADDC    A,R1
   \   0000F2   FB           MOV     R3,A
   \   0000F3   90....       MOV     DPTR,#nwkFrameCounterChanges
   \   0000F6   EA           MOV     A,R2
   \   0000F7   F0           MOVX    @DPTR,A
   \   0000F8   A3           INC     DPTR
   \   0000F9   EB           MOV     A,R3
   \   0000FA   F0           MOVX    @DPTR,A
   \   0000FB   C3           CLR     C
   \   0000FC   E8           MOV     A,R0
   \   0000FD   94E9         SUBB    A,#-0x17
   \   0000FF   E9           MOV     A,R1
   \   000100   9403         SUBB    A,#0x3
   \   000102   4003         JC      ??ZDApp_event_loop_22
    490                ZDApp_SaveNwkKey();
   \   000104                ; Setup parameters for call to function ZDApp_SaveNwkKey
   \   000104   12....       LCALL   ??ZDApp_SaveNwkKey?relay
    491          
    492              // Return unprocessed events
    493              return (events ^ ZDO_FRAMECOUNTER_CHANGE);
   \                     ??ZDApp_event_loop_22:
   \   000107   EE           MOV     A,R6
   \   000108   FA           MOV     R2,A
   \   000109   7404         MOV     A,#0x4
   \   00010B   02....       LJMP    ??ZDApp_event_loop_8 & 0xFFFF
    494            }
    495          #endif
    496          
    497            if ( events & ZDO_DEVICE_RESET )
   \                     ??ZDApp_event_loop_21:
   \   00010E   EE           MOV     A,R6
   \   00010F   5404         ANL     A,#0x4
   \   000111   600B         JZ      ??ZDApp_event_loop_23
    498            {
    499              // The device has been in the UNAUTH state, so reset
    500              // Note: there will be no return from this call
    501              SystemReset();
   \   000113   C2AF         CLR     0xa8.7
   \   000115   75C9AB       MOV     0xc9,#-0x55
   \   000118   75C95B       MOV     0xc9,#0x5b
   \                     ??ZDApp_event_loop_24:
   \   00011B   00           NOP
   \   00011C   80FD         SJMP    ??ZDApp_event_loop_24
    502            }
    503          
    504            // Discard or make more handlers
    505            return 0;
   \                     ??ZDApp_event_loop_23:
   \   00011E   7A00         MOV     R2,#0x0
   \   000120   7B00         MOV     R3,#0x0
   \                     ??ZDApp_event_loop_5:
   \   000122   02....       LJMP    ??Subroutine19_1 & 0xFFFF
   \   000125                REQUIRE _A_IEN0
   \   000125                REQUIRE WDCTL
    506          }

   \                                 In  segment BANKED_CODE, align 1, keep-with-next
   \                     ?Subroutine19:
   \   000000   7402         MOV     A,#0x2
   \                     ??Subroutine19_0:
   \   000002   12....       LCALL   ?DEALLOC_XSTACK8
   \                     ??Subroutine19_1:
   \   000005   7F02         MOV     R7,#0x2
   \   000007   02....       LJMP    ?BANKED_LEAVE_XDATA

   \                                 In  segment BANKED_CODE, align 1, keep-with-next
   \                     ?Subroutine4:
   \   000000   7A40         MOV     R2,#0x40
   \                     ??Subroutine4_0:
   \   000002   7B00         MOV     R3,#0x0
   \                     ??Subroutine4_1:
   \   000004   90....       MOV     DPTR,#ZDAppTaskID
   \   000007   E0           MOVX    A,@DPTR
   \   000008   F9           MOV     R1,A
   \   000009   12....       LCALL   ??osal_start_timerEx?relay
   \   00000C   22           RET

   \                                 In  segment BANKED_CODE, align 1, keep-with-next
   \                     ?Subroutine2:
   \   000000   7A10         MOV     R2,#0x10
   \                     ??Subroutine2_0:
   \   000002   7B00         MOV     R3,#0x0
   \   000004   90....       MOV     DPTR,#ZDAppTaskID
   \   000007   E0           MOVX    A,@DPTR
   \   000008   F9           MOV     R1,A
   \   000009   12....       LCALL   ??osal_set_event?relay
   \   00000C   22           RET
    507          
    508          /*********************************************************************
    509           * Application Functions
    510           */
    511          
    512          /*********************************************************************
    513           * @fn      ZDOInitDevice
    514           *
    515           * @brief   Start the device in the network.  This function will read
    516           *   ZCD_NV_STARTUP_OPTION (NV item) to determine whether or not to
    517           *   restore the network state of the device.
    518           *
    519           * @param   startDelay - timeDelay to start device (in milliseconds).
    520           *      There is a jitter added to this delay:
    521           *              ((NWK_START_DELAY + startDelay)
    522           *              + (osal_rand() & EXTENDED_JOINING_RANDOM_MASK))
    523           *
    524           * NOTE:    If the application would like to force a "new" join, the
    525           *          application should set the ZCD_STARTOPT_DEFAULT_NETWORK_STATE
    526           *          bit in the ZCD_NV_STARTUP_OPTION NV item before calling
    527           *          this function. "new" join means to not restore the network
    528           *          state of the device. Use zgWriteStartupOptions() to set these
    529           *          options.
    530           *
    531           * @return
    532           *    ZDO_INITDEV_RESTORED_NETWORK_STATE  - The device's network state was
    533           *          restored.
    534           *    ZDO_INITDEV_NEW_NETWORK_STATE - The network state was initialized.
    535           *          This could mean that ZCD_NV_STARTUP_OPTION said to not restore, or
    536           *          it could mean that there was no network state to restore.
    537           *    ZDO_INITDEV_LEAVE_NOT_STARTED - Before the reset, a network leave was issued
    538           *          with the rejoin option set to TRUE.  So, the device was not
    539           *          started in the network (one time only).  The next time this
    540           *          function is called it will start.
    541           */

   \                                 In  segment BANKED_CODE, align 1, keep-with-next
    542          uint8 ZDOInitDevice( uint16 startDelay )
   \                     ZDOInitDevice:
    543          {
   \   000000   74F6         MOV     A,#-0xa
   \   000002   12....       LCALL   ?BANKED_ENTER_XDATA
   \   000005                ; Saved register size: 10
   \   000005                ; Auto size: 2
   \   000005   74FE         MOV     A,#-0x2
   \   000007   12....       LCALL   ?ALLOC_XSTACK8
   \   00000A   85..82       MOV     DPL,?XSP + 0
   \   00000D   85..83       MOV     DPH,?XSP + 1
   \   000010   EA           MOV     A,R2
   \   000011   F0           MOVX    @DPTR,A
   \   000012   A3           INC     DPTR
   \   000013   EB           MOV     A,R3
   \   000014   F0           MOVX    @DPTR,A
    544            uint8 networkStateNV = ZDO_INITDEV_NEW_NETWORK_STATE;
    545            uint16 extendedDelay = 0;
    546          
    547            devState = DEV_INIT;    // Remove the Hold state
   \   000015   7401         MOV     A,#0x1
   \   000017   90....       MOV     DPTR,#devState
   \   00001A   F0           MOVX    @DPTR,A
    548          
    549            // Initialize leave control logic
    550            ZDApp_LeaveCtrlInit();
   \   00001B                ; Setup parameters for call to function ZDApp_LeaveCtrlInit
   \   00001B   12....       LCALL   ??ZDApp_LeaveCtrlInit?relay
    551          
    552            // Check leave control reset settings
    553            ZDApp_LeaveCtrlStartup( &devState, &startDelay );
   \   00001E                ; Setup parameters for call to function ZDApp_LeaveCtrlStartup
   \   00001E   85..82       MOV     DPL,?XSP + 0
   \   000021   85..83       MOV     DPH,?XSP + 1
   \   000024   AC82         MOV     R4,DPL
   \   000026   AD83         MOV     R5,DPH
   \   000028   7A..         MOV     R2,#(devState & 0xff)
   \   00002A   7B..         MOV     R3,#((devState >> 8) & 0xff)
   \   00002C   12....       LCALL   ??ZDApp_LeaveCtrlStartup?relay
    554          
    555            // Leave may make the hold state come back
    556            if ( devState == DEV_HOLD )
   \   00002F   90....       MOV     DPTR,#devState
   \   000032   E0           MOVX    A,@DPTR
   \   000033   7004         JNZ     ??ZDOInitDevice_0
    557              return ( ZDO_INITDEV_LEAVE_NOT_STARTED );   // Don't join - (one time).
   \   000035   7902         MOV     R1,#0x2
   \   000037   802E         SJMP    ??ZDOInitDevice_1
    558          
    559          #if defined ( NV_RESTORE )
    560            // Get Keypad directly to see if a reset nv is needed.
    561            // Hold down the SW_BYPASS_NV key (defined in OnBoard.h)
    562            // while booting to skip past NV Restore.
    563            if ( HalKeyRead() == SW_BYPASS_NV )
    564              networkStateNV = ZDO_INITDEV_NEW_NETWORK_STATE;
    565            else
    566            {
    567              // Determine if NV should be restored
    568              networkStateNV = ZDApp_ReadNetworkRestoreState();
    569            }
    570          
    571            if ( networkStateNV == ZDO_INITDEV_RESTORED_NETWORK_STATE )
    572            {
    573              networkStateNV = ZDApp_RestoreNetworkState();
    574            }
    575            else
    576            {
    577              // Wipe out the network state in NV
    578              NLME_InitNV();
    579              NLME_SetDefaultNV();
    580            }
    581          #endif
    582          
    583            if ( networkStateNV == ZDO_INITDEV_NEW_NETWORK_STATE )
    584            {
    585              ZDAppDetermineDeviceType();
    586          
    587              // Only delay if joining network - not restoring network state
    588              extendedDelay = (uint16)((NWK_START_DELAY + startDelay)
    589                        + (osal_rand() & EXTENDED_JOINING_RANDOM_MASK));
   \                     ??ZDOInitDevice_0:
   \   000039                ; Setup parameters for call to function osal_rand
   \   000039   12....       LCALL   ??osal_rand?relay
   \   00003C   8A..         MOV     ?V0 + 0,R2
   \   00003E   A8..         MOV     R0,?V0 + 0
   \   000040   85..82       MOV     DPL,?XSP + 0
   \   000043   85..83       MOV     DPH,?XSP + 1
   \   000046   747F         MOV     A,#0x7f
   \   000048   58           ANL     A,R0
   \   000049   F8           MOV     R0,A
   \   00004A   E0           MOVX    A,@DPTR
   \   00004B   28           ADD     A,R0
   \   00004C   F8           MOV     R0,A
   \   00004D   A3           INC     DPTR
   \   00004E   E0           MOVX    A,@DPTR
   \   00004F   3400         ADDC    A,#0x0
   \   000051   F9           MOV     R1,A
   \   000052   7464         MOV     A,#0x64
   \   000054   28           ADD     A,R0
   \   000055   FE           MOV     R6,A
   \   000056   E4           CLR     A
   \   000057   39           ADDC    A,R1
   \   000058   FF           MOV     R7,A
    590            }
    591          
    592            // Initialize device security
    593            ZDApp_SecInit( networkStateNV );
   \   000059                ; Setup parameters for call to function ZDApp_SecInit
   \   000059   7901         MOV     R1,#0x1
   \   00005B   12....       LCALL   ??ZDApp_SecInit?relay
    594          
    595            // Trigger the network start
    596            ZDApp_NetworkInit( extendedDelay );
   \   00005E                ; Setup parameters for call to function ZDApp_NetworkInit
   \   00005E   EE           MOV     A,R6
   \   00005F   FA           MOV     R2,A
   \   000060   EF           MOV     A,R7
   \   000061   FB           MOV     R3,A
   \   000062   12....       LCALL   ??ZDApp_NetworkInit?relay
    597          
    598            return ( networkStateNV );
   \   000065   7901         MOV     R1,#0x1
   \                     ??ZDOInitDevice_1:
   \   000067   02....       LJMP    ?Subroutine19 & 0xFFFF
    599          }
    600          
    601          /*********************************************************************
    602           * @fn      ZDApp_ReadNetworkRestoreState
    603           *
    604           * @brief   Read the ZCD_NV_STARTUP_OPTION NV Item to state whether
    605           *          or not to restore the network state.
    606           *          If the read value has the ZCD_STARTOPT_DEFAULT_NETWORK_STATE
    607           *          bit set return the ZDO_INITDEV_NEW_NETWORK_STATE.
    608           *
    609           * @param   none
    610           *
    611           * @return  ZDO_INITDEV_NEW_NETWORK_STATE
    612           *          or ZDO_INITDEV_RESTORED_NETWORK_STATE based on whether or
    613           *          not ZCD_STARTOPT_DEFAULT_NETWORK_STATE bit is set in
    614           *          ZCD_NV_STARTUP_OPTION
    615           */

   \                                 In  segment BANKED_CODE, align 1, keep-with-next
    616          uint8 ZDApp_ReadNetworkRestoreState( void )
   \                     ZDApp_ReadNetworkRestoreState:
    617          {
   \   000000   74F7         MOV     A,#-0x9
   \   000002   12....       LCALL   ?BANKED_ENTER_XDATA
   \   000005                ; Saved register size: 9
   \   000005                ; Auto size: 0
    618            uint8 networkStateNV = ZDO_INITDEV_RESTORED_NETWORK_STATE;
   \   000005   7E00         MOV     R6,#0x0
    619          
    620            // Look for the New Network State option.
    621            if ( zgReadStartupOptions() & ZCD_STARTOPT_DEFAULT_NETWORK_STATE )
   \   000007                ; Setup parameters for call to function zgReadStartupOptions
   \   000007   12....       LCALL   ??zgReadStartupOptions?relay
   \   00000A   E9           MOV     A,R1
   \   00000B   A2E1         MOV     C,0xE0 /* A   */.1
   \   00000D   5001         JNC     ??ZDApp_ReadNetworkRestoreState_0
    622            {
    623              networkStateNV = ZDO_INITDEV_NEW_NETWORK_STATE;
   \   00000F   0E           INC     R6
    624            }
    625          
    626            return ( networkStateNV );
   \                     ??ZDApp_ReadNetworkRestoreState_0:
   \   000010   EE           MOV     A,R6
   \   000011   F9           MOV     R1,A
   \   000012                REQUIRE ?Subroutine20
   \   000012                ; // Fall through to label ?Subroutine20
    627          }

   \                                 In  segment BANKED_CODE, align 1, keep-with-next
   \                     ?Subroutine20:
   \   000000   7F01         MOV     R7,#0x1
   \   000002   02....       LJMP    ?BANKED_LEAVE_XDATA
    628          
    629          /*********************************************************************
    630           * @fn      ZDAppDetermineDeviceType()
    631           *
    632           * @brief   Determines the type of device to start.  Right now
    633           *          this only works with the SOFT_START feature.  So it doesn't
    634           *          support the end device type.
    635           *
    636           *          Looks at zgDeviceLogicalType and determines what type of
    637           *          device to start.  The types are:
    638           *            ZG_DEVICETYPE_COORDINATOR
    639           *            ZG_DEVICETYPE_ROUTER
    640           *            ZG_DEVICETYPE_ENDDEVICE - not supported yet.
    641           *            ZG_DEVICETYPE_SOFT - looks for coordinator, if one doesn't
    642           *               exist, becomes one.  This option is should only be used
    643           *               if the system is manually configured and you are insured
    644           *               that the first device is started before all the other
    645           *               devices are started.
    646           *
    647           * @param   none
    648           *
    649           * @return  none
    650           */

   \                                 In  segment BANKED_CODE, align 1, keep-with-next
    651          void ZDAppDetermineDeviceType( void )
   \                     ZDAppDetermineDeviceType:
    652          {
   \   000000                ; Saved register size: 0
   \   000000                ; Auto size: 0
    653            if ( zgDeviceLogicalType == ZG_DEVICETYPE_ENDDEVICE )
   \   000000   02....       LJMP    ?BRET
    654              return;
    655          
    656          #if defined ( SOFT_START )
    657            if ( zgDeviceLogicalType == ZG_DEVICETYPE_COORDINATOR )
    658            {
    659              devStartMode = MODE_HARD;     // Start as a coordinator
    660              ZDO_Config_Node_Descriptor.LogicalType = NODETYPE_COORDINATOR;
    661            }
    662            else
    663            {
    664              if ( zgDeviceLogicalType == ZG_DEVICETYPE_ROUTER )
    665              {
    666                softStartAllowCoord = FALSE;  // Don't allow coord to start
    667                continueJoining = TRUE;
    668              }
    669              devStartMode = MODE_JOIN;     // Assume joining
    670            }
    671          #endif // SOFT_START
    672          }
    673          
    674          /*********************************************************************
    675           * @fn      ZDApp_NetworkStartEvt()
    676           *
    677           * @brief   Process the Network Start Event
    678           *
    679           * @param   none
    680           *
    681           * @return  none
    682           */

   \                                 In  segment BANKED_CODE, align 1, keep-with-next
    683          void ZDApp_NetworkStartEvt( void )
   \                     ZDApp_NetworkStartEvt:
    684          {
   \   000000   C082         PUSH    DPL
   \   000002   C083         PUSH    DPH
   \   000004                ; Saved register size: 2
   \   000004                ; Auto size: 0
    685            if ( nwkStatus == ZSuccess )
   \   000004   90....       MOV     DPTR,#nwkStatus
   \   000007   E0           MOVX    A,@DPTR
   \   000008   7012         JNZ     ??ZDApp_NetworkStartEvt_0
    686            {
    687              // Successfully started a ZigBee network
    688              if ( devState == DEV_COORD_STARTING )
   \   00000A   90....       MOV     DPTR,#devState
   \   00000D   E0           MOVX    A,@DPTR
   \   00000E   6408         XRL     A,#0x8
   \   000010   7003         JNZ     ??ZDApp_NetworkStartEvt_1
    689              {
    690                devState = DEV_ZB_COORD;
   \   000012   7409         MOV     A,#0x9
   \   000014   F0           MOVX    @DPTR,A
    691              }
    692          
    693              osal_pwrmgr_device( PWRMGR_ALWAYS_ON );
   \                     ??ZDApp_NetworkStartEvt_1:
   \   000015                ; Setup parameters for call to function osal_pwrmgr_device
   \   000015   7900         MOV     R1,#0x0
   \   000017   12....       LCALL   ??osal_pwrmgr_device?relay
    694              osal_set_event( ZDAppTaskID, ZDO_STATE_CHANGE_EVT );
   \   00001A                ; Setup parameters for call to function osal_set_event
   \   00001A   802D         SJMP    ??ZDApp_NetworkStartEvt_2
    695            }
    696            else
    697            {
    698              // Try again with a higher energy threshold !!
    699              if ( ( NLME_GetEnergyThreshold() + ENERGY_SCAN_INCREMENT ) < 0xff )
   \                     ??ZDApp_NetworkStartEvt_0:
   \   00001C                ; Setup parameters for call to function NLME_GetEnergyThreshold
   \   00001C   12....       LCALL   ??NLME_GetEnergyThreshold?relay
   \   00001F   E9           MOV     A,R1
   \   000020   F8           MOV     R0,A
   \   000021   7410         MOV     A,#0x10
   \   000023   28           ADD     A,R0
   \   000024   F8           MOV     R0,A
   \   000025   E4           CLR     A
   \   000026   3400         ADDC    A,#0x0
   \   000028   F9           MOV     R1,A
   \   000029   E8           MOV     A,R0
   \   00002A   94FF         SUBB    A,#-0x1
   \   00002C   E9           MOV     A,R1
   \   00002D   9400         SUBB    A,#0x0
   \   00002F   C3           CLR     C
   \   000030   65D0         XRL     A,PSW
   \   000032   33           RLC     A
   \   000033   500E         JNC     ??ZDApp_NetworkStartEvt_3
    700              {
    701                NLME_SetEnergyThreshold( (uint8)(NLME_GetEnergyThreshold() + ENERGY_SCAN_INCREMENT) );
   \   000035                ; Setup parameters for call to function NLME_SetEnergyThreshold
   \   000035                ; Setup parameters for call to function NLME_GetEnergyThreshold
   \   000035   12....       LCALL   ??NLME_GetEnergyThreshold?relay
   \   000038   E9           MOV     A,R1
   \   000039   2410         ADD     A,#0x10
   \   00003B   F9           MOV     R1,A
   \   00003C   12....       LCALL   ??NLME_SetEnergyThreshold?relay
    702                osal_set_event( ZDAppTaskID, ZDO_NETWORK_INIT );
   \   00003F                ; Setup parameters for call to function osal_set_event
   \   00003F   7A01         MOV     R2,#0x1
   \   000041   8008         SJMP    ??ZDApp_NetworkStartEvt_4
    703              }
    704              else
    705              {
    706                // Failed to start network. Enter a dormant state (until user intervenes)
    707                devState = DEV_INIT;
   \                     ??ZDApp_NetworkStartEvt_3:
   \   000043   7401         MOV     A,#0x1
   \   000045   90....       MOV     DPTR,#devState
   \   000048   F0           MOVX    @DPTR,A
    708                osal_set_event( ZDAppTaskID, ZDO_STATE_CHANGE_EVT );
   \   000049                ; Setup parameters for call to function osal_set_event
   \                     ??ZDApp_NetworkStartEvt_2:
   \   000049   7A10         MOV     R2,#0x10
   \                     ??ZDApp_NetworkStartEvt_4:
   \   00004B   02....       LJMP    ?Subroutine16 & 0xFFFF
    709              }
    710            }
    711          }
    712          
    713          #if ( SECURE != 0 )
    714          /*********************************************************************
    715           * @fn      ZDApp_DeviceAuthEvt()
    716           *
    717           * @brief   Process the Device Authentic Event
    718           *
    719           * @param   none
    720           *
    721           * @return  none
    722           */

   \                                 In  segment BANKED_CODE, align 1, keep-with-next
    723          void ZDApp_DeviceAuthEvt( void )
   \                     ZDApp_DeviceAuthEvt:
    724          {
   \   000000   C082         PUSH    DPL
   \   000002   C083         PUSH    DPH
   \   000004                ; Saved register size: 2
   \   000004                ; Auto size: 0
    725            // received authentication from trust center
    726            if ( devState == DEV_END_DEVICE_UNAUTH )
   \   000004   90....       MOV     DPTR,#devState
   \   000007   E0           MOVX    A,@DPTR
   \   000008   6405         XRL     A,#0x5
   \   00000A   7027         JNZ     ??ZDApp_DeviceAuthEvt_0
    727            {
    728              // Stop the reset timer so it doesn't reset
    729              ZDApp_ResetTimerCancel();
   \   00000C                ; Setup parameters for call to function ZDApp_ResetTimerCancel
   \   00000C   12....       LCALL   ??ZDApp_ResetTimerCancel?relay
    730          
    731              devState = DEV_END_DEVICE;
   \   00000F   7406         MOV     A,#0x6
   \   000011   90....       MOV     DPTR,#devState
   \   000014   F0           MOVX    @DPTR,A
    732              osal_set_event( ZDAppTaskID, ZDO_STATE_CHANGE_EVT );
   \   000015                ; Setup parameters for call to function osal_set_event
   \   000015   12....       LCALL   ?Subroutine2 & 0xFFFF
    733          
    734              // Set the Power Manager Device
    735          #if defined ( POWER_SAVING )
    736              osal_pwrmgr_device( PWRMGR_BATTERY );
    737          #endif
    738          
    739          #if defined ( RTR_NWK )
    740              if ( ZDO_Config_Node_Descriptor.LogicalType != NODETYPE_DEVICE )
   \                     ??CrossCallReturnLabel_49:
   \   000018   90....       MOV     DPTR,#ZDO_Config_Node_Descriptor
   \   00001B   E0           MOVX    A,@DPTR
   \   00001C   5407         ANL     A,#0x7
   \   00001E   6402         XRL     A,#0x2
   \   000020   6009         JZ      ??ZDApp_DeviceAuthEvt_1
    741              {
    742                // NOTE: first two parameters are not used, see NLMEDE.h for details
    743                NLME_StartRouterRequest( 0, 0, false );
   \   000022                ; Setup parameters for call to function NLME_StartRouterRequest
   \   000022   7B00         MOV     R3,#0x0
   \   000024   7A00         MOV     R2,#0x0
   \   000026   7900         MOV     R1,#0x0
   \   000028   12....       LCALL   ??NLME_StartRouterRequest?relay
    744              }
    745          #endif  // RTR
    746          
    747              // Notify to save info into NV
    748              ZDApp_NVUpdate();
   \                     ??ZDApp_DeviceAuthEvt_1:
   \   00002B                ; Setup parameters for call to function ZDApp_NVUpdate
   \   00002B   12....       LCALL   ??ZDApp_NVUpdate?relay
    749          
    750              // Save off the security
    751              ZDApp_SaveNwkKey();
   \   00002E                ; Setup parameters for call to function ZDApp_SaveNwkKey
   \   00002E   12....       LCALL   ??ZDApp_SaveNwkKey?relay
   \   000031   8003         SJMP    ??ZDApp_DeviceAuthEvt_2
    752          
    753          #if defined ( ZDO_ENDDEVICE_ANNCE_GENERATE )
    754              ZDP_EndDeviceAnnce( ZDAppNwkAddr.addr.shortAddr, saveExtAddr,
    755                                 ZDO_Config_Node_Descriptor.CapabilityFlags, 0 );
    756          #endif
    757            }
    758            else
    759            {
    760              ZDApp_NVUpdate();
   \                     ??ZDApp_DeviceAuthEvt_0:
   \   000033                ; Setup parameters for call to function ZDApp_NVUpdate
   \   000033   12....       LCALL   ??ZDApp_NVUpdate?relay
    761            }
    762          }
   \                     ??ZDApp_DeviceAuthEvt_2:
   \   000036   02....       LJMP    ??Subroutine16_0 & 0xFFFF
    763          #endif
    764          
    765          /*********************************************************************
    766           * @fn      ZDApp_SaveNetworkStateEvt()
    767           *
    768           * @brief   Process the Save the Network State Event
    769           *
    770           * @param   none
    771           *
    772           * @return  none
    773           */

   \                                 In  segment BANKED_CODE, align 1, keep-with-next
    774          void ZDApp_SaveNetworkStateEvt( void )
   \                     ZDApp_SaveNetworkStateEvt:
    775          {
   \   000000                ; Saved register size: 0
   \   000000                ; Auto size: 0
    776          #if defined ( NV_RESTORE )
    777           #if defined ( NV_TURN_OFF_RADIO )
    778            // Turn off the radio's receiver during an NV update
    779            byte RxOnIdle;
    780            byte x = false;
    781            ZMacGetReq( ZMacRxOnIdle, &RxOnIdle );
    782            ZMacSetReq( ZMacRxOnIdle, &x );
    783           #endif
    784          
    785            // Update the Network State in NV
    786            NLME_UpdateNV( NWK_NV_NIB_ENABLE        |
    787                           NWK_NV_DEVICELIST_ENABLE |
    788                           NWK_NV_BINDING_ENABLE    |
    789                           NWK_NV_ADDRMGR_ENABLE );
    790          
    791            // Reset the NV startup option to resume from NV by
    792            // clearing the "New" join option.
    793            zgWriteStartupOptions( FALSE, ZCD_STARTOPT_DEFAULT_NETWORK_STATE );
    794          
    795           #if defined ( NV_TURN_OFF_RADIO )
    796            ZMacSetReq( ZMacRxOnIdle, &RxOnIdle );
    797           #endif
    798          #endif  // NV_RESTORE
    799          }
   \   000000   02....       LJMP    ?BRET
    800          
    801          /*********************************************************************
    802           * @fn      ZDApp_RestoreNetworkState()
    803           *
    804           * @brief   This function will restore the network state of the
    805           *          device if the network state is stored in NV.
    806           *
    807           * @param   none
    808           *
    809           * @return
    810           *    ZDO_INITDEV_RESTORED_NETWORK_STATE  - The device's network state was
    811           *          restored.
    812           *    ZDO_INITDEV_NEW_NETWORK_STATE - The network state was not used.
    813           *          This could mean that zgStartupOption said to not restore, or
    814           *          it could mean that there was no network state to restore.
    815           *
    816           */

   \                                 In  segment BANKED_CODE, align 1, keep-with-next
    817          uint8 ZDApp_RestoreNetworkState( void )
   \                     ZDApp_RestoreNetworkState:
    818          {
   \   000000   74F6         MOV     A,#-0xa
   \   000002   12....       LCALL   ?BANKED_ENTER_XDATA
   \   000005                ; Saved register size: 10
   \   000005                ; Auto size: 21
   \   000005   74EB         MOV     A,#-0x15
   \   000007   12....       LCALL   ?ALLOC_XSTACK8
    819            byte nvStat;
    820          #if ( SECURE != 0 )
    821            nwkActiveKeyItems keyItems;
    822          #endif
    823          
    824            // Initialize NWK NV items
    825            nvStat = NLME_InitNV();
   \   00000A                ; Setup parameters for call to function NLME_InitNV
   \   00000A   12....       LCALL   ??NLME_InitNV?relay
   \   00000D   E9           MOV     A,R1
   \   00000E   FE           MOV     R6,A
    826          
    827            if ( nvStat != NV_OPER_FAILED )
   \   00000F   7410         MOV     A,#0x10
   \   000011   6E           XRL     A,R6
   \   000012   6050         JZ      ??ZDApp_RestoreNetworkState_0
    828            {
    829              if ( NLME_RestoreFromNV() )
   \   000014                ; Setup parameters for call to function NLME_RestoreFromNV
   \   000014   12....       LCALL   ??NLME_RestoreFromNV?relay
   \   000017   E9           MOV     A,R1
   \   000018   6024         JZ      ??ZDApp_RestoreNetworkState_1
    830              {
    831                // Are we a coordinator
    832                ZDAppNwkAddr.addr.shortAddr = NLME_GetShortAddr();
   \   00001A                ; Setup parameters for call to function NLME_GetShortAddr
   \   00001A   12....       LCALL   ??NLME_GetShortAddr?relay
   \   00001D   90....       MOV     DPTR,#ZDAppNwkAddr
   \   000020   EA           MOV     A,R2
   \   000021   F0           MOVX    @DPTR,A
   \   000022   A3           INC     DPTR
   \   000023   EB           MOV     A,R3
   \   000024   F0           MOVX    @DPTR,A
    833                if ( ZDAppNwkAddr.addr.shortAddr == 0 )
   \   000025   90....       MOV     DPTR,#ZDAppNwkAddr
   \   000028   E0           MOVX    A,@DPTR
   \   000029   7002         JNZ     ??ZDApp_RestoreNetworkState_2
   \   00002B   A3           INC     DPTR
   \   00002C   E0           MOVX    A,@DPTR
   \                     ??ZDApp_RestoreNetworkState_2:
   \   00002D   7007         JNZ     ??ZDApp_RestoreNetworkState_3
    834                {
    835                  ZDO_Config_Node_Descriptor.LogicalType = NODETYPE_COORDINATOR;
   \   00002F   90....       MOV     DPTR,#ZDO_Config_Node_Descriptor
   \   000032   E0           MOVX    A,@DPTR
   \   000033   54F8         ANL     A,#0xf8
   \   000035   F0           MOVX    @DPTR,A
    836                }
    837                devStartMode = MODE_RESUME;
   \                     ??ZDApp_RestoreNetworkState_3:
   \   000036   7401         MOV     A,#0x1
   \   000038   90....       MOV     DPTR,#devStartMode
   \   00003B   F0           MOVX    @DPTR,A
   \   00003C   8002         SJMP    ??ZDApp_RestoreNetworkState_4
    838              }
    839              else
    840                nvStat = NV_ITEM_UNINIT;
   \                     ??ZDApp_RestoreNetworkState_1:
   \   00003E   7E0F         MOV     R6,#0xf
    841          
    842          #if   ( SECURE != 0  )
    843              nwkFrameCounterChanges = 0;
   \                     ??ZDApp_RestoreNetworkState_4:
   \   000040   90....       MOV     DPTR,#nwkFrameCounterChanges
   \   000043   E4           CLR     A
   \   000044   F0           MOVX    @DPTR,A
   \   000045   A3           INC     DPTR
   \   000046   F0           MOVX    @DPTR,A
    844              osal_memset( &keyItems, 0, sizeof( nwkActiveKeyItems ) );
   \   000047                ; Setup parameters for call to function osal_memset
   \   000047   7C15         MOV     R4,#0x15
   \   000049   FD           MOV     R5,A
   \   00004A   F9           MOV     R1,A
   \   00004B   12....       LCALL   ??Subroutine8_0 & 0xFFFF
    845              osal_nv_item_init( ZCD_NV_NWKKEY, sizeof(nwkActiveKeyItems), (void *)&keyItems );
   \                     ??CrossCallReturnLabel_19:
   \   00004E   12....       LCALL   ?PUSH_XSTACK_I_TWO
   \   000051   7C15         MOV     R4,#0x15
   \   000053   7D00         MOV     R5,#0x0
   \   000055   7A82         MOV     R2,#-0x7e
   \   000057   7B00         MOV     R3,#0x0
   \   000059   12....       LCALL   ??osal_nv_item_init?relay
   \   00005C   7402         MOV     A,#0x2
   \   00005E   12....       LCALL   ?DEALLOC_XSTACK8
    846          
    847            #if defined ( ZDO_COORDINATOR )
    848              ZDApp_RestoreNwkKey();
   \   000061                ; Setup parameters for call to function ZDApp_RestoreNwkKey
   \   000061   12....       LCALL   ??ZDApp_RestoreNwkKey?relay
    849            #endif // ZDO_COORDINATOR
    850          #endif // SECURE
    851          
    852              // The default for RxOnWhenIdle is true for RTR_NWK and false for end devices
    853              // [setup in the NLME_RestoreFromNV()].  Change it here if you want something
    854              // other than default.
    855            }
    856          
    857            if ( nvStat == ZSUCCESS )
   \                     ??ZDApp_RestoreNetworkState_0:
   \   000064   EE           MOV     A,R6
   \   000065   7004         JNZ     ??ZDApp_RestoreNetworkState_5
    858              return ( ZDO_INITDEV_RESTORED_NETWORK_STATE );
   \   000067   7900         MOV     R1,#0x0
   \   000069   8002         SJMP    ??ZDApp_RestoreNetworkState_6
    859            else
    860              return ( ZDO_INITDEV_NEW_NETWORK_STATE );
   \                     ??ZDApp_RestoreNetworkState_5:
   \   00006B   7901         MOV     R1,#0x1
   \                     ??ZDApp_RestoreNetworkState_6:
   \   00006D                REQUIRE ?Subroutine22
   \   00006D                ; // Fall through to label ?Subroutine22
    861          }

   \                                 In  segment BANKED_CODE, align 1, keep-with-next
   \                     ?Subroutine22:
   \   000000   7415         MOV     A,#0x15
   \   000002   02....       LJMP    ??Subroutine19_0 & 0xFFFF

   \                                 In  segment BANKED_CODE, align 1, keep-with-next
   \                     ?Subroutine8:
   \   000000   7D00         MOV     R5,#0x0
   \   000002   7900         MOV     R1,#0x0
   \                     ??Subroutine8_0:
   \   000004   85..82       MOV     DPL,?XSP + 0
   \   000007   85..83       MOV     DPH,?XSP + 1
   \   00000A   AA82         MOV     R2,DPL
   \   00000C   AB83         MOV     R3,DPH
   \   00000E   12....       LCALL   ??osal_memset?relay
   \   000011                ; Setup parameters for call to function osal_nv_item_init
   \   000011                ; Setup parameters for call to function osal_nv_write
   \   000011                ; Setup parameters for call to function osal_nv_item_init
   \   000011   85..82       MOV     DPL,?XSP + 0
   \   000014   85..83       MOV     DPH,?XSP + 1
   \   000017   8582..       MOV     ?V0 + 0,DPL
   \   00001A   8583..       MOV     ?V0 + 1,DPH
   \   00001D   78..         MOV     R0,#?V0 + 0
   \   00001F   22           RET
    862          
    863          /*********************************************************************
    864           * @fn      ZDApp_InitUserDesc()
    865           *
    866           * @brief   Initialize the User Descriptor, the descriptor is read from NV
    867           *          when needed.  If you want to initialize the User descriptor to
    868           *          something other than all zero, do it here.
    869           *
    870           * @param   none
    871           *
    872           * @return  none
    873           */

   \                                 In  segment BANKED_CODE, align 1, keep-with-next
    874          void ZDApp_InitUserDesc( void )
   \                     ZDApp_InitUserDesc:
    875          {
   \   000000   74F6         MOV     A,#-0xa
   \   000002   12....       LCALL   ?BANKED_ENTER_XDATA
   \   000005                ; Saved register size: 10
   \   000005                ; Auto size: 17
   \   000005   74EF         MOV     A,#-0x11
   \   000007   12....       LCALL   ?ALLOC_XSTACK8
    876            UserDescriptorFormat_t ZDO_DefaultUserDescriptor;
    877          
    878            // Initialize the User Descriptor, the descriptor is read from NV
    879            // when needed.  If you want to initialize the User descriptor to something
    880            // other than all zero, do it here.
    881            osal_memset( &ZDO_DefaultUserDescriptor, 0, sizeof( UserDescriptorFormat_t ) );
   \   00000A                ; Setup parameters for call to function osal_memset
   \   00000A   7C11         MOV     R4,#0x11
   \   00000C   12....       LCALL   ?Subroutine8 & 0xFFFF
    882            if ( ZSUCCESS == osal_nv_item_init( ZCD_NV_USERDESC,
    883                   sizeof(UserDescriptorFormat_t), (void*)&ZDO_DefaultUserDescriptor ) )
   \                     ??CrossCallReturnLabel_17:
   \   00000F   12....       LCALL   ?PUSH_XSTACK_I_TWO
   \   000012   7C11         MOV     R4,#0x11
   \   000014   7D00         MOV     R5,#0x0
   \   000016   7A81         MOV     R2,#-0x7f
   \   000018   7B00         MOV     R3,#0x0
   \   00001A   12....       LCALL   ??osal_nv_item_init?relay
   \   00001D   7402         MOV     A,#0x2
   \   00001F   12....       LCALL   ?DEALLOC_XSTACK8
   \   000022   E9           MOV     A,R1
   \   000023   7033         JNZ     ??ZDApp_InitUserDesc_0
    884            {
    885              if ( ZSUCCESS == osal_nv_read( ZCD_NV_USERDESC, 0,
    886                   sizeof(UserDescriptorFormat_t), (void*)&ZDO_DefaultUserDescriptor ) )
   \   000025                ; Setup parameters for call to function osal_nv_read
   \   000025   78..         MOV     R0,#?V0 + 0
   \   000027   12....       LCALL   ?PUSH_XSTACK_I_TWO
   \   00002A   75..11       MOV     ?V0 + 0,#0x11
   \   00002D   75..00       MOV     ?V0 + 1,#0x0
   \   000030   78..         MOV     R0,#?V0 + 0
   \   000032   12....       LCALL   ?PUSH_XSTACK_I_TWO
   \   000035   7C00         MOV     R4,#0x0
   \   000037   7D00         MOV     R5,#0x0
   \   000039   7A81         MOV     R2,#-0x7f
   \   00003B   7B00         MOV     R3,#0x0
   \   00003D   12....       LCALL   ??osal_nv_read?relay
   \   000040   7404         MOV     A,#0x4
   \   000042   12....       LCALL   ?DEALLOC_XSTACK8
   \   000045   E9           MOV     A,R1
   \   000046   7010         JNZ     ??ZDApp_InitUserDesc_0
    887              {
    888                if ( ZDO_DefaultUserDescriptor.len != 0 )
   \   000048   85..82       MOV     DPL,?XSP + 0
   \   00004B   85..83       MOV     DPH,?XSP + 1
   \   00004E   E0           MOVX    A,@DPTR
   \   00004F   6007         JZ      ??ZDApp_InitUserDesc_0
    889                {
    890                  ZDO_Config_Node_Descriptor.UserDescAvail = TRUE;
   \   000051   90....       MOV     DPTR,#ZDO_Config_Node_Descriptor
   \   000054   E0           MOVX    A,@DPTR
   \   000055   D2E4         SETB    0xE0 /* A   */.4
   \   000057   F0           MOVX    @DPTR,A
    891                }
    892              }
    893            }
    894          }
   \                     ??ZDApp_InitUserDesc_0:
   \   000058   7411         MOV     A,#0x11
   \   00005A   02....       LJMP    ??Subroutine19_0 & 0xFFFF
    895          
    896          /*********************************************************************
    897           * @fn      ZDAppCheckForHoldKey()
    898           *
    899           * @brief   Check for key to set the device into Hold Auto Start
    900           *
    901           * @param   none
    902           *
    903           * @return  none
    904           */

   \                                 In  segment BANKED_CODE, align 1, keep-with-next
    905          void ZDAppCheckForHoldKey( void )
   \                     ZDAppCheckForHoldKey:
    906          {
   \   000000   C082         PUSH    DPL
   \   000002   C083         PUSH    DPH
   \   000004                ; Saved register size: 2
   \   000004                ; Auto size: 0
    907          #if (defined HAL_KEY) && (HAL_KEY == TRUE)
    908            // Get Keypad directly to see if a HOLD_START is needed.
    909            // Hold down the SW_BYPASS_START key (see OnBoard.h)
    910            // while booting to avoid starting up the device.
    911            if ( HalKeyRead () == SW_BYPASS_START)
   \   000004                ; Setup parameters for call to function HalKeyRead
   \   000004   12....       LCALL   ??HalKeyRead?relay
   \   000007   E9           MOV     A,R1
   \   000008   6401         XRL     A,#0x1
   \   00000A   7005         JNZ     ??ZDAppCheckForHoldKey_0
    912            {
    913              // Change the device state to HOLD on start up
    914              devState = DEV_HOLD;
   \   00000C   E4           CLR     A
   \   00000D   90....       MOV     DPTR,#devState
   \   000010   F0           MOVX    @DPTR,A
    915            }
    916          #endif // HAL_KEY
    917          }
   \                     ??ZDAppCheckForHoldKey_0:
   \   000011   02....       LJMP    ??Subroutine16_0 & 0xFFFF
    918          
    919          /*********************************************************************
    920           * @fn      ZDApp_ProcessOSALMsg()
    921           *
    922           * @brief   Process the incoming task message.
    923           *
    924           * @param   msgPtr - message to process
    925           *
    926           * @return  none
    927           */

   \                                 In  segment BANKED_CODE, align 1, keep-with-next
    928          void ZDApp_ProcessOSALMsg( osal_event_hdr_t *msgPtr )
   \                     ZDApp_ProcessOSALMsg:
    929          {
   \   000000   C082         PUSH    DPL
   \   000002   C083         PUSH    DPH
   \   000004                ; Saved register size: 2
   \   000004                ; Auto size: 0
    930            // Data Confirmation message fields
    931            byte sentEP;       // This should always be 0
    932            byte sentStatus;
    933            afDataConfirm_t *afDataConfirm;
    934          
    935            switch ( msgPtr->event )
   \   000004   8A82         MOV     DPL,R2
   \   000006   8B83         MOV     DPH,R3
   \   000008   E0           MOVX    A,@DPTR
   \   000009   12....       LCALL   ?UC_SWITCH_SPARSE
   \                     `?<Jumptable for ZDApp_ProcessOSALMsg>_0`:
   \   00000C   00           DB        0
   \   00000D   03           DB        3
   \   00000E   07           DB        7
   \   00000F   ....         DW        ??ZDApp_ProcessOSALMsg_0
   \   000011   1A           DB        26
   \   000012   ....         DW        ??ZDApp_ProcessOSALMsg_1
   \   000014   D3           DB        211
   \   000015   ....         DW        ??ZDApp_ProcessOSALMsg_2
   \   000017   ....         DW        ??ZDApp_ProcessOSALMsg_3
    936            {
    937              // Incoming ZDO Message
    938              case AF_INCOMING_MSG_CMD:
    939                ZDP_IncomingData( (afIncomingMSGPacket_t *)msgPtr );
   \                     ??ZDApp_ProcessOSALMsg_1:
   \   000019                ; Setup parameters for call to function ZDP_IncomingData
   \   000019   12....       LCALL   ??ZDP_IncomingData?relay
   \   00001C   8008         SJMP    ??ZDApp_ProcessOSALMsg_3
    940                break;
    941          
    942              case ZDO_CB_MSG:
    943                ZDApp_ProcessMsgCBs( (zdoIncomingMsg_t *)msgPtr );
   \                     ??ZDApp_ProcessOSALMsg_2:
   \   00001E                ; Setup parameters for call to function ZDApp_ProcessMsgCBs
   \   00001E   12....       LCALL   ??ZDApp_ProcessMsgCBs?relay
   \   000021   8003         SJMP    ??ZDApp_ProcessOSALMsg_3
    944                break;
    945          
    946              case AF_DATA_CONFIRM_CMD:
    947                // This message is received as a confirmation of a data packet sent.
    948                // The status is of ZStatus_t type [defined in NLMEDE.h]
    949                // The message fields are defined in AF.h
    950                afDataConfirm = (afDataConfirm_t *)msgPtr;
    951                sentEP = afDataConfirm->endpoint;
    952                sentStatus = afDataConfirm->hdr.status;
    953          
    954                // Action taken when confirmation is received.
    955                /* Put code here */
    956          #if !defined ( RTR_NWK )
    957                if ( sentStatus == ZMacNoACK )
    958                {
    959                  //ZDApp_SendMsg( ZDAppTaskID, ZDO_NWK_JOIN_REQ, sizeof(osal_event_hdr_t), NULL );
    960                }
    961          #else
    962               (void)sentStatus;
    963          #endif
    964                break;
    965          
    966              case ZDO_NWK_DISC_CNF:
    967                if (devState != DEV_NWK_DISC)
    968                {
    969                }
    970          #if !defined ( ZDO_COORDINATOR ) || defined ( SOFT_START )
    971            #if defined ( MANAGED_SCAN )
    972                else if ( (((ZDO_NetworkDiscoveryCfm_t *)msgPtr)->hdr.status == ZDO_SUCCESS) && (zdoDiscCounter > NUM_DISC_ATTEMPTS) )
    973            #else
    974                else if ( (((ZDO_NetworkDiscoveryCfm_t *)msgPtr)->hdr.status == ZDO_SUCCESS) && (zdoDiscCounter++ > NUM_DISC_ATTEMPTS) )
    975            #endif
    976                {
    977                  if ( devStartMode == MODE_JOIN )
    978                  {
    979                    devState = DEV_NWK_JOINING;
    980          
    981                    ZDApp_NodeProfileSync((ZDO_NetworkDiscoveryCfm_t *)msgPtr);
    982          
    983                    if ( NLME_JoinRequest( ((ZDO_NetworkDiscoveryCfm_t *)msgPtr)->extendedPANID,
    984                         BUILD_UINT16( ((ZDO_NetworkDiscoveryCfm_t *)msgPtr)->panIdLSB, ((ZDO_NetworkDiscoveryCfm_t *)msgPtr)->panIdMSB ),
    985                         ((ZDO_NetworkDiscoveryCfm_t *)msgPtr)->logicalChannel,
    986                         ZDO_Config_Node_Descriptor.CapabilityFlags ) != ZSuccess )
    987                    {
    988                      ZDApp_NetworkInit( (uint16)(NWK_START_DELAY
    989                          + ((uint16)(osal_rand()& EXTENDED_JOINING_RANDOM_MASK))) );
    990                    }
    991                  }
    992                  else if ( devStartMode == MODE_REJOIN )
    993                  {
    994                    devState = DEV_NWK_REJOIN;
    995                    if ( NLME_ReJoinRequest() != ZSuccess )
    996                    {
    997                      ZDApp_NetworkInit( (uint16)(NWK_START_DELAY
    998                          + ((uint16)(osal_rand()& EXTENDED_JOINING_RANDOM_MASK))) );
    999                    }
   1000                  }
   1001          
   1002                  if ( ZDO_Config_Node_Descriptor.CapabilityFlags & CAPINFO_RCVR_ON_IDLE )
   1003                  {
   1004                    // The receiver is on, turn network layer polling off.
   1005                    NLME_SetPollRate( 0 );
   1006                    NLME_SetQueuedPollRate( 0 );
   1007                    NLME_SetResponseRate( 0 );
   1008                  }
   1009                }
   1010                else
   1011                {
   1012          #if defined ( SOFT_START ) && !defined ( VIRTKEY_SOFT_START )
   1013            #if defined ( MANAGED_SCAN )
   1014                  if ( (softStartAllowCoord)
   1015                      && (((ZDO_NetworkDiscoveryCfm_t *)msgPtr)->hdr.status != ZDO_SUCCESS )
   1016                        && (zdoDiscCounter > NUM_DISC_ATTEMPTS) )
   1017            #else
   1018                  if ( (softStartAllowCoord)
   1019                      && (((ZDO_NetworkDiscoveryCfm_t *)msgPtr)->hdr.status != ZDO_SUCCESS )
   1020                        && (zdoDiscCounter++ > NUM_DISC_ATTEMPTS) )
   1021            #endif
   1022                  {
   1023                    ZDO_Config_Node_Descriptor.LogicalType = NODETYPE_COORDINATOR;
   1024                    devStartMode = MODE_HARD;
   1025                  }
   1026                  else if ( continueJoining == FALSE )
   1027                  {
   1028                    devState = DEV_HOLD;
   1029                    osal_stop_timerEx( ZDAppTaskID, ZDO_NETWORK_INIT );
   1030                    break;    // Don't init
   1031                  }
   1032          #endif
   1033            #if defined ( MANAGED_SCAN )
   1034                  ZDApp_NetworkInit( MANAGEDSCAN_DELAY_BETWEEN_SCANS );
   1035            #else
   1036                  if ( continueJoining )
   1037                  {
   1038                    ZDApp_NetworkInit( (uint16)(BEACON_REQUEST_DELAY
   1039                        + ((uint16)(osal_rand()& BEACON_REQ_DELAY_MASK))) );
   1040                  }
   1041            #endif
   1042                }
   1043          #endif  // !ZDO_COORDINATOR
   1044                break;
   1045          
   1046          #if !defined( ZDO_COORDINATOR ) || defined( SOFT_START )
   1047              case ZDO_NWK_JOIN_IND:
   1048                ZDApp_ProcessNetworkJoin();
   1049                break;
   1050          
   1051              case ZDO_NWK_JOIN_REQ:
   1052                retryCnt = 0;
   1053                devStartMode = MODE_RESUME;
   1054                _tmpRejoinState = true;
   1055                zgDefaultStartingScanDuration = BEACON_ORDER_60_MSEC;
   1056                ZDApp_NetworkInit( 0 );
   1057          
   1058                // indicate state change to apps
   1059                devState = DEV_INIT;
   1060                osal_set_event( ZDAppTaskID, ZDO_STATE_CHANGE_EVT );
   1061                break;
   1062          #endif  // !ZDO_COORDINATOR
   1063          
   1064          #if defined ( ZDSECMGR_SECURE )
   1065            #if defined ( ZDSECMGR_COMMERCIAL )
   1066                  case ZDO_ESTABLISH_KEY_CFM:
   1067                    ZDSecMgrEstablishKeyCfm
   1068                      ( (ZDO_EstablishKeyCfm_t*)msgPtr );
   1069                    break;
   1070            #endif
   1071          
   1072            #if defined ( ZDSECMGR_COMMERCIAL )
   1073              #if !defined ( ZDO_COORDINATOR ) || defined ( SOFT_START )
   1074                  case ZDO_ESTABLISH_KEY_IND:
   1075                    ZDSecMgrEstablishKeyInd
   1076                      ( (ZDO_EstablishKeyInd_t*)msgPtr );
   1077                    break;
   1078              #endif
   1079            #endif
   1080          
   1081            #if !defined ( ZDO_COORDINATOR ) || defined( SOFT_START )
   1082                  case ZDO_TRANSPORT_KEY_IND:
   1083                    ZDSecMgrTransportKeyInd
   1084                      ( (ZDO_TransportKeyInd_t*)msgPtr );
   1085                    break;
   1086            #endif
   1087          
   1088            #if defined ( ZDO_COORDINATOR )
   1089                  case ZDO_UPDATE_DEVICE_IND:
   1090                    ZDSecMgrUpdateDeviceInd
   1091                      ( (ZDO_UpdateDeviceInd_t*)msgPtr );
   \                     ??ZDApp_ProcessOSALMsg_0:
   \   000023                ; Setup parameters for call to function ZDSecMgrUpdateDeviceInd
   \   000023   12....       LCALL   ??ZDSecMgrUpdateDeviceInd?relay
   1092                    break;
   1093            #endif
   1094          
   1095            #if defined ( RTR_NWK )
   1096              #if !defined ( ZDO_COORDINATOR ) || defined( SOFT_START )
   1097                  case ZDO_REMOVE_DEVICE_IND:
   1098                    ZDSecMgrRemoveDeviceInd
   1099                      ( (ZDO_RemoveDeviceInd_t*)msgPtr );
   1100                    break;
   1101              #endif
   1102            #endif
   1103          
   1104            #if defined ( ZDSECMGR_COMMERCIAL )
   1105              #if defined ( ZDO_COORDINATOR )
   1106                  case ZDO_REQUEST_KEY_IND:
   1107                    ZDSecMgrRequestKeyInd
   1108                      ( (ZDO_RequestKeyInd_t*)msgPtr );
   1109                    break;
   1110              #endif
   1111            #endif
   1112          
   1113            #if !defined ( ZDO_COORDINATOR ) || defined( SOFT_START )
   1114                  case ZDO_SWITCH_KEY_IND:
   1115                    ZDSecMgrSwitchKeyInd
   1116                      ( (ZDO_SwitchKeyInd_t*)msgPtr );
   1117                    break;
   1118            #endif
   1119          
   1120          #endif // defined ( ZDSECMGR_SECURE )
   1121          
   1122              default:
   1123                break;
   1124            }
   1125          
   1126            (void)sentEP;
   1127          }
   \                     ??ZDApp_ProcessOSALMsg_3:
   \   000026   02....       LJMP    ??Subroutine16_0 & 0xFFFF
   1128          
   1129          /*********************************************************************
   1130           * @fn      ZDApp_ProcessMsgCBs()
   1131           *
   1132           * @brief   Process response messages
   1133           *
   1134           * @param   none
   1135           *
   1136           * @return  none
   1137           */

   \                                 In  segment BANKED_CODE, align 1, keep-with-next
   1138          void ZDApp_ProcessMsgCBs( zdoIncomingMsg_t *inMsg )
   \                     ZDApp_ProcessMsgCBs:
   1139          {
   \   000000   74F6         MOV     A,#-0xa
   \   000002   12....       LCALL   ?BANKED_ENTER_XDATA
   \   000005                ; Saved register size: 10
   \   000005                ; Auto size: 23
   \   000005   74E9         MOV     A,#-0x17
   \   000007   12....       LCALL   ?ALLOC_XSTACK8
   \   00000A   EA           MOV     A,R2
   \   00000B   FE           MOV     R6,A
   \   00000C   EB           MOV     A,R3
   \   00000D   FF           MOV     R7,A
   1140            switch ( inMsg->clusterID )
   \   00000E   12....       LCALL   ?Subroutine9 & 0xFFFF
   \                     ??CrossCallReturnLabel_20:
   \   000011   F5..         MOV     ?V0 + 1,A
   \   000013   78..         MOV     R0,#?V0 + 0
   \   000015   12....       LCALL   ?US_SWITCH_SPARSE
   \                     `?<Jumptable for ZDApp_ProcessMsgCBs>_0`:
   \   000018   0100         DW        1
   \   00001A   2180         DW        32801
   \   00001C   2280         DW        32802
   \   00001E   ....         DW        ??ZDApp_ProcessMsgCBs_0
   \   000020   0100         DW        1
   \   000022   2000         DW        32
   \   000024   ....         DW        ??ZDApp_ProcessMsgCBs_1
   \   000026   ....         DW        ??CrossCallReturnLabel_13
   1141            {
   1142          #if defined ( ZDO_NWKADDR_REQUEST ) || defined ( ZDO_IEEEADDR_REQUEST ) || defined ( REFLECTOR )
   1143              case NWK_addr_rsp:
   1144              case IEEE_addr_rsp:
   1145                {
   1146                  ZDO_NwkIEEEAddrResp_t *pAddrRsp;
   1147                  pAddrRsp = ZDO_ParseAddrRsp( inMsg );
   1148                  if ( pAddrRsp )
   1149                  {
   1150                    if ( pAddrRsp->status == ZSuccess )
   1151                    {
   1152                      ZDO_UpdateAddrManager( pAddrRsp->nwkAddr, pAddrRsp->extAddr );
   1153                    }
   1154                    osal_mem_free( pAddrRsp );
   1155                  }
   1156                }
   1157                break;
   1158          #endif
   1159          
   1160          #if defined ( REFLECTOR )
   1161              case Bind_req:
   1162              case Unbind_req:
   1163                {
   1164                  ZDO_BindUnbindReq_t bindReq;
   1165                  ZDO_ParseBindUnbindReq( inMsg, &bindReq );
   1166                  ZDO_ProcessBindUnbindReq( inMsg, &bindReq );
   1167                }
   1168                break;
   1169          #endif
   1170          
   1171          #if defined ( ZDO_COORDINATOR )
   1172              case Bind_rsp:
   1173              case Unbind_rsp:
   1174                if ( matchED )
   \                     ??ZDApp_ProcessMsgCBs_0:
   \   000028   90....       MOV     DPTR,#matchED
   \   00002B   E0           MOVX    A,@DPTR
   \   00002C   7002         JNZ     ??ZDApp_ProcessMsgCBs_2
   \   00002E   A3           INC     DPTR
   \   00002F   E0           MOVX    A,@DPTR
   \                     ??ZDApp_ProcessMsgCBs_2:
   \   000030   6068         JZ      ??CrossCallReturnLabel_13
   1175                {
   1176                  ZDMatchSendState(
   1177                       (uint8)((inMsg->clusterID == Bind_rsp) ? ZDMATCH_REASON_BIND_RSP : ZDMATCH_REASON_UNBIND_RSP),
   1178                       ZDO_ParseBindRsp(inMsg), inMsg->TransSeq );
   \   000032   12....       LCALL   ?Subroutine10 & 0xFFFF
   \                     ??CrossCallReturnLabel_22:
   \   000035   6421         XRL     A,#0x21
   \   000037   7004         JNZ     ??ZDApp_ProcessMsgCBs_3
   \   000039   A3           INC     DPTR
   \   00003A   E0           MOVX    A,@DPTR
   \   00003B   6480         XRL     A,#0x80
   \                     ??ZDApp_ProcessMsgCBs_3:
   \   00003D   7004         JNZ     ??ZDApp_ProcessMsgCBs_4
   \   00003F   7903         MOV     R1,#0x3
   \   000041   8002         SJMP    ??ZDApp_ProcessMsgCBs_5
   \                     ??ZDApp_ProcessMsgCBs_4:
   \   000043   7902         MOV     R1,#0x2
   \                     ??ZDApp_ProcessMsgCBs_5:
   \   000045                ; Setup parameters for call to function ZDMatchSendState
   \   000045   EE           MOV     A,R6
   \   000046   240F         ADD     A,#0xf
   \   000048   12....       LCALL   ??Subroutine11_0 & 0xFFFF
   \                     ??CrossCallReturnLabel_26:
   \   00004B   FB           MOV     R3,A
   \   00004C   EE           MOV     A,R6
   \   00004D   2411         ADD     A,#0x11
   \   00004F   12....       LCALL   ??Subroutine11_0 & 0xFFFF
   \                     ??CrossCallReturnLabel_27:
   \   000052   F8           MOV     R0,A
   \   000053   A3           INC     DPTR
   \   000054   E0           MOVX    A,@DPTR
   \   000055   F583         MOV     DPH,A
   \   000057   8882         MOV     DPL,R0
   \   000059   E0           MOVX    A,@DPTR
   \   00005A   FA           MOV     R2,A
   \   00005B   12....       LCALL   ??ZDMatchSendState?relay
   \   00005E   803A         SJMP    ??CrossCallReturnLabel_13
   1179                }
   1180                break;
   1181          
   1182              case End_Device_Bind_req:
   1183                {
   1184                  ZDEndDeviceBind_t bindReq;
   1185                  ZDO_ParseEndDeviceBindReq( inMsg, &bindReq );
   \                     ??ZDApp_ProcessMsgCBs_1:
   \   000060                ; Setup parameters for call to function ZDO_ParseEndDeviceBindReq
   \   000060   85..82       MOV     DPL,?XSP + 0
   \   000063   85..83       MOV     DPH,?XSP + 1
   \   000066   AC82         MOV     R4,DPL
   \   000068   AD83         MOV     R5,DPH
   \   00006A   12....       LCALL   ??ZDO_ParseEndDeviceBindReq?relay
   1186                  ZDO_MatchEndDeviceBind( &bindReq );
   \   00006D                ; Setup parameters for call to function ZDO_MatchEndDeviceBind
   \   00006D   85..82       MOV     DPL,?XSP + 0
   \   000070   85..83       MOV     DPH,?XSP + 1
   \   000073   AA82         MOV     R2,DPL
   \   000075   AB83         MOV     R3,DPH
   \   000077   12....       LCALL   ??ZDO_MatchEndDeviceBind?relay
   1187          
   1188                  // Freeing the cluster lists - if allocated.
   1189                  if ( bindReq.numInClusters )
   \   00007A   7411         MOV     A,#0x11
   \   00007C   12....       LCALL   ?XSTACK_DISP0_8
   \   00007F   E0           MOVX    A,@DPTR
   \   000080   6008         JZ      ??CrossCallReturnLabel_12
   1190                    osal_mem_free( bindReq.inClusters );
   \   000082                ; Setup parameters for call to function osal_mem_free
   \   000082   7412         MOV     A,#0x12
   \   000084   12....       LCALL   ?XSTACK_DISP0_8
   \   000087   12....       LCALL   ?Subroutine5 & 0xFFFF
   1191                  if ( bindReq.numOutClusters )
   \                     ??CrossCallReturnLabel_12:
   \   00008A   7414         MOV     A,#0x14
   \   00008C   12....       LCALL   ?XSTACK_DISP0_8
   \   00008F   E0           MOVX    A,@DPTR
   \   000090   6008         JZ      ??CrossCallReturnLabel_13
   1192                    osal_mem_free( bindReq.outClusters );
   \   000092                ; Setup parameters for call to function osal_mem_free
   \   000092   7415         MOV     A,#0x15
   \   000094   12....       LCALL   ?XSTACK_DISP0_8
   \   000097   12....       LCALL   ?Subroutine5 & 0xFFFF
   1193                }
   1194                break;
   1195          #endif
   1196            }
   1197          }
   \                     ??CrossCallReturnLabel_13:
   \   00009A   7417         MOV     A,#0x17
   \   00009C   02....       LJMP    ??Subroutine19_0 & 0xFFFF

   \                                 In  segment BANKED_CODE, align 1, keep-with-next
   \                     ?Subroutine5:
   \   000000   E0           MOVX    A,@DPTR
   \   000001   FA           MOV     R2,A
   \   000002   A3           INC     DPTR
   \   000003   E0           MOVX    A,@DPTR
   \   000004   FB           MOV     R3,A
   \   000005   12....       LCALL   ??osal_mem_free?relay
   \   000008   22           RET

   \                                 In  segment BANKED_CODE, align 1, keep-with-next
   \                     ?Subroutine10:
   \   000000   12....       LCALL   ?Subroutine14 & 0xFFFF
   \                     ??CrossCallReturnLabel_43:
   \   000003   22           RET

   \                                 In  segment BANKED_CODE, align 1, keep-with-next
   \                     ?Subroutine14:
   \   000000   12....       LCALL   ?Subroutine15 & 0xFFFF
   \                     ??CrossCallReturnLabel_45:
   \   000003   E0           MOVX    A,@DPTR
   \   000004   22           RET

   \                                 In  segment BANKED_CODE, align 1, keep-with-next
   \                     ?Subroutine15:
   \   000000   EE           MOV     A,R6
   \   000001   240C         ADD     A,#0xc
   \   000003   F582         MOV     DPL,A
   \   000005   EF           MOV     A,R7
   \   000006   3400         ADDC    A,#0x0
   \   000008   F583         MOV     DPH,A
   \   00000A   22           RET

   \                                 In  segment BANKED_CODE, align 1, keep-with-next
   \                     ?Subroutine11:
   \   000000   EE           MOV     A,R6
   \   000001   240B         ADD     A,#0xb
   \                     ??Subroutine11_0:
   \   000003   F582         MOV     DPL,A
   \   000005   EF           MOV     A,R7
   \                     ??Subroutine11_1:
   \   000006   3400         ADDC    A,#0x0
   \   000008   F583         MOV     DPH,A
   \   00000A   E0           MOVX    A,@DPTR
   \   00000B   22           RET

   \                                 In  segment BANKED_CODE, align 1, keep-with-next
   \                     ?Subroutine9:
   \   000000   12....       LCALL   ?Subroutine14 & 0xFFFF
   \                     ??CrossCallReturnLabel_42:
   \   000003   F5..         MOV     ?V0 + 0,A
   \   000005   A3           INC     DPTR
   \   000006   E0           MOVX    A,@DPTR
   \   000007   22           RET
   1198          
   1199          /*********************************************************************
   1200           * @fn      ZDApp_RegisterCBs()
   1201           *
   1202           * @brief   Process response messages
   1203           *
   1204           * @param   none
   1205           *
   1206           * @return  none
   1207           */

   \                                 In  segment BANKED_CODE, align 1, keep-with-next
   1208          void ZDApp_RegisterCBs( void )
   \                     ZDApp_RegisterCBs:
   1209          {
   \   000000   C082         PUSH    DPL
   \   000002   C083         PUSH    DPH
   \   000004                ; Saved register size: 2
   \   000004                ; Auto size: 0
   1210          #if defined ( ZDO_IEEEADDR_REQUEST ) || defined ( REFLECTOR )
   1211            ZDO_RegisterForZDOMsg( ZDAppTaskID, IEEE_addr_rsp );
   1212          #endif
   1213          #if defined ( ZDO_NWKADDR_REQUEST ) || defined ( REFLECTOR )
   1214            ZDO_RegisterForZDOMsg( ZDAppTaskID, NWK_addr_rsp );
   1215          #endif
   1216          #if defined ( ZDO_COORDINATOR )
   1217            ZDO_RegisterForZDOMsg( ZDAppTaskID, Bind_rsp );
   \   000004                ; Setup parameters for call to function ZDO_RegisterForZDOMsg
   \   000004   7A21         MOV     R2,#0x21
   \   000006   12....       LCALL   ?Subroutine6 & 0xFFFF
   1218            ZDO_RegisterForZDOMsg( ZDAppTaskID, Unbind_rsp );
   \                     ??CrossCallReturnLabel_14:
   \   000009                ; Setup parameters for call to function ZDO_RegisterForZDOMsg
   \   000009   7A22         MOV     R2,#0x22
   \   00000B   12....       LCALL   ?Subroutine6 & 0xFFFF
   1219            ZDO_RegisterForZDOMsg( ZDAppTaskID, End_Device_Bind_req );
   \                     ??CrossCallReturnLabel_15:
   \   00000E                ; Setup parameters for call to function ZDO_RegisterForZDOMsg
   \   00000E   7A20         MOV     R2,#0x20
   \   000010   7B00         MOV     R3,#0x0
   \   000012   12....       LCALL   ??Subroutine6_0 & 0xFFFF
   1220          #endif
   1221          #if defined ( REFLECTOR )
   1222            ZDO_RegisterForZDOMsg( ZDAppTaskID, Bind_req );
   1223            ZDO_RegisterForZDOMsg( ZDAppTaskID, Unbind_req );
   1224          #endif
   1225          }
   \                     ??CrossCallReturnLabel_16:
   \   000015   02....       LJMP    ??Subroutine16_0 & 0xFFFF

   \                                 In  segment BANKED_CODE, align 1, keep-with-next
   \                     ?Subroutine6:
   \   000000   7B80         MOV     R3,#-0x80
   \                     ??Subroutine6_0:
   \   000002   90....       MOV     DPTR,#ZDAppTaskID
   \   000005   E0           MOVX    A,@DPTR
   \   000006   F9           MOV     R1,A
   \   000007   12....       LCALL   ??ZDO_RegisterForZDOMsg?relay
   \   00000A   22           RET
   1226          
   1227          #if !defined( ZDO_COORDINATOR ) || defined( SOFT_START )
   1228          /*********************************************************************
   1229           * @fn      ZDApp_ProcessNetworkJoin()
   1230           *
   1231           * @brief
   1232           *
   1233           *   Save off the Network key information.
   1234           *
   1235           * @param   none
   1236           *
   1237           * @return  none
   1238           */
   1239          void ZDApp_ProcessNetworkJoin( void )
   1240          {
   1241            if ( (devState == DEV_NWK_JOINING) ||
   1242                ((devState == DEV_NWK_ORPHAN)  &&
   1243                 (ZDO_Config_Node_Descriptor.LogicalType == NODETYPE_ROUTER)) )
   1244            {
   1245              // Result of a Join attempt by this device.
   1246              if ( nwkStatus == ZSuccess )
   1247              {
   1248                osal_set_event( ZDAppTaskID, ZDO_STATE_CHANGE_EVT );
   1249          
   1250          #if defined ( POWER_SAVING )
   1251                osal_pwrmgr_device( PWRMGR_BATTERY );
   1252          #endif
   1253          
   1254          #if   ( SECURE != 0  )
   1255                if ( _NIB.SecurityLevel && (ZDApp_RestoreNwkKey() == false ) )
   1256                {
   1257                  // wait for auth from trust center!!
   1258                  devState = DEV_END_DEVICE_UNAUTH;
   1259          
   1260                  // Start the reset timer for MAX UNAUTH time
   1261                  ZDApp_ResetTimerStart( MAX_DEVICE_UNAUTH_TIMEOUT );
   1262                }
   1263                else
   1264          #endif  // SECURE
   1265                {
   1266          #if defined ( RTR_NWK )
   1267                  if ( devState == DEV_NWK_ORPHAN
   1268                      && ZDO_Config_Node_Descriptor.LogicalType != NODETYPE_DEVICE )
   1269                  {
   1270                    // Change NIB state to router for restore
   1271                    _NIB.nwkState = NWK_ROUTER;
   1272                  }
   1273          #endif
   1274                  devState = DEV_END_DEVICE;
   1275          #if defined ( RTR_NWK )
   1276                  // NOTE: first two parameters are not used, see NLMEDE.h for details
   1277            #if !defined (AUTO_SOFT_START)
   1278                  if ( ZDO_Config_Node_Descriptor.LogicalType != NODETYPE_DEVICE )
   1279                  {
   1280                    NLME_StartRouterRequest( 0, 0, false );
   1281                  }
   1282            #endif // AUTO_SOFT_START
   1283          #endif  // RTR
   1284          
   1285          #if defined ( ZDO_ENDDEVICE_ANNCE_GENERATE )
   1286                  ZDP_EndDeviceAnnce( ZDAppNwkAddr.addr.shortAddr, saveExtAddr,
   1287                                     ZDO_Config_Node_Descriptor.CapabilityFlags, 0 );
   1288          #endif
   1289                }
   1290              }
   1291              else
   1292              {
   1293                if ( (devStartMode == MODE_RESUME) && (++retryCnt >= MAX_RESUME_RETRY) )
   1294                {
   1295                  if ( _NIB.nwkPanId == 0xFFFF || _NIB.nwkPanId == INVALID_PAN_ID )
   1296                    devStartMode = MODE_JOIN;
   1297                  else
   1298                  {
   1299                    devStartMode = MODE_REJOIN;
   1300                    _tmpRejoinState = true;
   1301                  }
   1302                }
   1303          
   1304                if ( (NLME_GetShortAddr() != INVALID_NODE_ADDR) ||
   1305                     (_NIB.nwkDevAddress != INVALID_NODE_ADDR) )
   1306                {
   1307                  uint16 addr = INVALID_NODE_ADDR;
   1308                  // Invalidate nwk addr so end device does not use in its data reqs.
   1309                  _NIB.nwkDevAddress = INVALID_NODE_ADDR;
   1310                  ZMacSetReq( ZMacShortAddress, (byte *)&addr );
   1311                }
   1312          
   1313                zdoDiscCounter = 1;
   1314          
   1315          //      ZDApp_NetworkInit( (uint16)
   1316          //                         ((NWK_START_DELAY * (osal_rand() & 0x0F)) +
   1317          //                          (NWK_START_DELAY * 5)) );
   1318                ZDApp_NetworkInit( (uint16)(NWK_START_DELAY
   1319                     + ((uint16)(osal_rand()& EXTENDED_JOINING_RANDOM_MASK))) );
   1320              }
   1321            }
   1322            else if ( devState == DEV_NWK_ORPHAN || devState == DEV_NWK_REJOIN )
   1323            {
   1324              // results of an orphaning attempt by this device
   1325              if (nwkStatus == ZSuccess)
   1326              {
   1327          #if ( SECURE != 0 )
   1328                ZDApp_RestoreNwkKey();
   1329          #endif
   1330                devState = DEV_END_DEVICE;
   1331                osal_set_event( ZDAppTaskID, ZDO_STATE_CHANGE_EVT );
   1332                // setup Power Manager Device
   1333          #if defined ( POWER_SAVING )
   1334                osal_pwrmgr_device( PWRMGR_BATTERY );
   1335          #endif
   1336          
   1337                if ( ZDO_Config_Node_Descriptor.CapabilityFlags & CAPINFO_RCVR_ON_IDLE )
   1338                {
   1339                  // The receiver is on, turn network layer polling off.
   1340                  NLME_SetPollRate( 0 );
   1341                  NLME_SetQueuedPollRate( 0 );
   1342                  NLME_SetResponseRate( 0 );
   1343                }
   1344          
   1345          #if defined ( ZDO_ENDDEVICE_ANNCE_GENERATE )
   1346                ZDP_EndDeviceAnnce( ZDAppNwkAddr.addr.shortAddr, saveExtAddr,
   1347                                   ZDO_Config_Node_Descriptor.CapabilityFlags, 0 );
   1348          #endif
   1349          
   1350              }
   1351              else
   1352              {
   1353                if ( (devStartMode == MODE_RESUME) && (++retryCnt >= MAX_RESUME_RETRY) )
   1354                {
   1355                  if ( _NIB.nwkPanId == 0xFFFF || _NIB.nwkPanId == INVALID_PAN_ID )
   1356                    devStartMode = MODE_JOIN;
   1357                  else
   1358                  {
   1359                    devStartMode = MODE_REJOIN;
   1360                    _tmpRejoinState = true;
   1361                  }
   1362                }
   1363          
   1364                // setup a retry for later...
   1365                ZDApp_NetworkInit( (uint16)(NWK_START_DELAY
   1366                     + (osal_rand()& EXTENDED_JOINING_RANDOM_MASK)) );
   1367              }
   1368            }
   1369            else
   1370            {
   1371              // this is an error case!!
   1372            }
   1373          }
   1374          #endif // !ZDO_COORDINATOR
   1375          
   1376          #if ( SECURE != 0 )
   1377          /*********************************************************************
   1378           * @fn      ZDApp_SaveNwkKey()
   1379           *
   1380           * @brief   Save off the Network key information.
   1381           *
   1382           * @param   none
   1383           *
   1384           * @return  none
   1385           */

   \                                 In  segment BANKED_CODE, align 1, keep-with-next
   1386          void ZDApp_SaveNwkKey( void )
   \                     ZDApp_SaveNwkKey:
   1387          {
   \   000000   74F4         MOV     A,#-0xc
   \   000002   12....       LCALL   ?BANKED_ENTER_XDATA
   \   000005                ; Saved register size: 12
   \   000005                ; Auto size: 21
   \   000005   74EB         MOV     A,#-0x15
   \   000007   12....       LCALL   ?ALLOC_XSTACK8
   1388            nwkActiveKeyItems keyItems;
   1389          
   1390            SSP_ReadNwkActiveKey( &keyItems );
   \   00000A                ; Setup parameters for call to function SSP_ReadNwkActiveKey
   \   00000A   85..82       MOV     DPL,?XSP + 0
   \   00000D   85..83       MOV     DPH,?XSP + 1
   \   000010   AA82         MOV     R2,DPL
   \   000012   AB83         MOV     R3,DPH
   \   000014   12....       LCALL   ??SSP_ReadNwkActiveKey?relay
   1391            keyItems.frameCounter++;
   \   000017   90....       MOV     DPTR,#__Constant_1
   \   00001A   78..         MOV     R0,#?V0 + 0
   \   00001C   12....       LCALL   ?L_MOV_X
   \   00001F   7411         MOV     A,#0x11
   \   000021   12....       LCALL   ?XSTACK_DISP0_8
   \   000024   78..         MOV     R0,#?V0 + 0
   \   000026   12....       LCALL   ?L_ADD_TO_X
   1392          
   1393            osal_nv_write( ZCD_NV_NWKKEY, 0, sizeof( nwkActiveKeyItems ),
   1394                          (void *)&keyItems );
   \   000029                ; Setup parameters for call to function osal_nv_write
   \   000029   85..82       MOV     DPL,?XSP + 0
   \   00002C   85..83       MOV     DPH,?XSP + 1
   \   00002F   8582..       MOV     ?V0 + 0,DPL
   \   000032   8583..       MOV     ?V0 + 1,DPH
   \   000035   78..         MOV     R0,#?V0 + 0
   \   000037   12....       LCALL   ?PUSH_XSTACK_I_TWO
   \   00003A   75..15       MOV     ?V0 + 0,#0x15
   \   00003D   75..00       MOV     ?V0 + 1,#0x0
   \   000040   78..         MOV     R0,#?V0 + 0
   \   000042   12....       LCALL   ?PUSH_XSTACK_I_TWO
   \   000045   12....       LCALL   ?Subroutine13 & 0xFFFF
   \                     ??CrossCallReturnLabel_38:
   \   000048   12....       LCALL   ?DEALLOC_XSTACK8
   1395          
   1396            nwkFrameCounterChanges = 0;
   \   00004B   90....       MOV     DPTR,#nwkFrameCounterChanges
   \   00004E   E4           CLR     A
   \   00004F   F0           MOVX    @DPTR,A
   \   000050   A3           INC     DPTR
   \   000051   F0           MOVX    @DPTR,A
   1397          }
   \   000052                REQUIRE ?Subroutine18
   \   000052                ; // Fall through to label ?Subroutine18

   \                                 In  segment BANKED_CODE, align 1, keep-with-next
   \                     ?Subroutine13:
   \   000000   7C00         MOV     R4,#0x0
   \   000002   7D00         MOV     R5,#0x0
   \   000004   7A82         MOV     R2,#-0x7e
   \                     ??Subroutine13_0:
   \   000006   7B00         MOV     R3,#0x0
   \   000008   12....       LCALL   ??osal_nv_write?relay
   \   00000B   7404         MOV     A,#0x4
   \   00000D   22           RET
   1398          
   1399          /*********************************************************************
   1400           * @fn      ZDApp_ResetNwkKey()
   1401           *
   1402           * @brief   Reset the Network key information in NV.
   1403           *
   1404           * @param   none
   1405           *
   1406           * @return  none
   1407           */

   \                                 In  segment BANKED_CODE, align 1, keep-with-next
   1408          void ZDApp_ResetNwkKey( void )
   \                     ZDApp_ResetNwkKey:
   1409          {
   \   000000   74F6         MOV     A,#-0xa
   \   000002   12....       LCALL   ?BANKED_ENTER_XDATA
   \   000005                ; Saved register size: 10
   \   000005                ; Auto size: 21
   \   000005   74EB         MOV     A,#-0x15
   \   000007   12....       LCALL   ?ALLOC_XSTACK8
   1410            nwkActiveKeyItems keyItems;
   1411          
   1412            osal_memset( &keyItems, 0, sizeof( nwkActiveKeyItems ) );
   \   00000A                ; Setup parameters for call to function osal_memset
   \   00000A   7C15         MOV     R4,#0x15
   \   00000C   12....       LCALL   ?Subroutine8 & 0xFFFF
   1413            osal_nv_write( ZCD_NV_NWKKEY, 0, sizeof( nwkActiveKeyItems ),
   1414                          (void *)&keyItems );
   \                     ??CrossCallReturnLabel_18:
   \   00000F   12....       LCALL   ?PUSH_XSTACK_I_TWO
   \   000012   75..15       MOV     ?V0 + 0,#0x15
   \   000015   75..00       MOV     ?V0 + 1,#0x0
   \   000018   78..         MOV     R0,#?V0 + 0
   \   00001A   12....       LCALL   ?PUSH_XSTACK_I_TWO
   \   00001D   12....       LCALL   ?Subroutine13 & 0xFFFF
   \                     ??CrossCallReturnLabel_39:
   \   000020   12....       LCALL   ?DEALLOC_XSTACK8
   1415          }
   \   000023   02....       LJMP    ?Subroutine22 & 0xFFFF
   1416          #endif
   1417          
   1418          #if ( SECURE != 0 )
   1419          /*********************************************************************
   1420           * @fn      ZDApp_RestoreNwkKey()
   1421           *
   1422           * @brief
   1423           *
   1424           *   Save off the Network key information.
   1425           *
   1426           * @param   none
   1427           *
   1428           * @return  true if restored from NV, false if not
   1429           */

   \                                 In  segment BANKED_CODE, align 1, keep-with-next
   1430          byte ZDApp_RestoreNwkKey( void )
   \                     ZDApp_RestoreNwkKey:
   1431          {
   \   000000   74F4         MOV     A,#-0xc
   \   000002   12....       LCALL   ?BANKED_ENTER_XDATA
   \   000005                ; Saved register size: 12
   \   000005                ; Auto size: 21
   \   000005   74EB         MOV     A,#-0x15
   \   000007   12....       LCALL   ?ALLOC_XSTACK8
   1432            nwkActiveKeyItems keyItems;
   1433            byte ret = false;
   \   00000A   7E00         MOV     R6,#0x0
   1434          
   1435            if ( osal_nv_read( ZCD_NV_NWKKEY, 0, sizeof(nwkActiveKeyItems), (void*)&keyItems )
   1436                == ZSUCCESS )
   \   00000C                ; Setup parameters for call to function osal_nv_read
   \   00000C   85..82       MOV     DPL,?XSP + 0
   \   00000F   85..83       MOV     DPH,?XSP + 1
   \   000012   8582..       MOV     ?V0 + 0,DPL
   \   000015   8583..       MOV     ?V0 + 1,DPH
   \   000018   78..         MOV     R0,#?V0 + 0
   \   00001A   12....       LCALL   ?PUSH_XSTACK_I_TWO
   \   00001D   75..15       MOV     ?V0 + 0,#0x15
   \   000020   8E..         MOV     ?V0 + 1,R6
   \   000022   78..         MOV     R0,#?V0 + 0
   \   000024   12....       LCALL   ?PUSH_XSTACK_I_TWO
   \   000027   7C00         MOV     R4,#0x0
   \   000029   7D00         MOV     R5,#0x0
   \   00002B   7A82         MOV     R2,#-0x7e
   \   00002D   7B00         MOV     R3,#0x0
   \   00002F   12....       LCALL   ??osal_nv_read?relay
   \   000032   7404         MOV     A,#0x4
   \   000034   12....       LCALL   ?DEALLOC_XSTACK8
   \   000037   E9           MOV     A,R1
   \   000038   7049         JNZ     ??ZDApp_RestoreNwkKey_0
   1437            {
   1438              if ( keyItems.frameCounter > 0 )
   \   00003A   7411         MOV     A,#0x11
   \   00003C   12....       LCALL   ?XSTACK_DISP0_8
   \   00003F   C082         PUSH    DPL
   \   000041   C083         PUSH    DPH
   \   000043   90....       MOV     DPTR,#__Constant_0
   \   000046   78..         MOV     R0,#?V0 + 0
   \   000048   12....       LCALL   ?L_MOV_X
   \   00004B   D083         POP     DPH
   \   00004D   D082         POP     DPL
   \   00004F   78..         MOV     R0,#?V0 + 0
   \   000051   12....       LCALL   ?L_EQ_X
   \   000054   6023         JZ      ??ZDApp_RestoreNwkKey_1
   1439              {
   1440                // Restore the key information
   1441                keyItems.frameCounter += MAX_NWK_FRAMECOUNTER_CHANGES;
   1442                nwkFrameCounter = keyItems.frameCounter;
   \   000056   7411         MOV     A,#0x11
   \   000058   12....       LCALL   ?XSTACK_DISP0_8
   \   00005B   C082         PUSH    DPL
   \   00005D   C083         PUSH    DPH
   \   00005F   90....       MOV     DPTR,#__Constant_3e8
   \   000062   78..         MOV     R0,#?V0 + 0
   \   000064   12....       LCALL   ?L_MOV_X
   \   000067   D083         POP     DPH
   \   000069   D082         POP     DPL
   \   00006B   78..         MOV     R0,#?V0 + 0
   \   00006D   12....       LCALL   ?L_ADD_X
   \   000070   90....       MOV     DPTR,#nwkFrameCounter
   \   000073   78..         MOV     R0,#?V0 + 0
   \   000075   12....       LCALL   ?L_MOV_TO_X
   1443                ret = true;
   \   000078   0E           INC     R6
   1444              }
   1445          
   1446              // Force a save for the first frame counter increment
   1447              nwkFrameCounterChanges = MAX_NWK_FRAMECOUNTER_CHANGES + 1;
   \                     ??ZDApp_RestoreNwkKey_1:
   \   000079   90....       MOV     DPTR,#nwkFrameCounterChanges
   \   00007C   74E9         MOV     A,#-0x17
   \   00007E   F0           MOVX    @DPTR,A
   \   00007F   A3           INC     DPTR
   \   000080   7403         MOV     A,#0x3
   \   000082   F0           MOVX    @DPTR,A
   1448            }
   1449            return ( ret );
   \                     ??ZDApp_RestoreNwkKey_0:
   \   000083   EE           MOV     A,R6
   \   000084   F9           MOV     R1,A
   \   000085   02....       LJMP    ?Subroutine18 & 0xFFFF
   1450          }
   1451          #endif
   1452          
   1453          /*********************************************************************
   1454           * @fn      ZDApp_ResetTimerStart
   1455           *
   1456           * @brief   Start the reset timer.
   1457           *
   1458           * @param   delay - delay time(ms) before reset
   1459           *
   1460           * @return  none
   1461           */

   \                                 In  segment BANKED_CODE, align 1, keep-with-next
   1462          void ZDApp_ResetTimerStart( uint16 delay )
   \                     ZDApp_ResetTimerStart:
   1463          {
   \   000000   C082         PUSH    DPL
   \   000002   C083         PUSH    DPH
   \   000004                ; Saved register size: 2
   \   000004                ; Auto size: 0
   1464            // Start the rest timer
   1465            osal_start_timerEx( ZDAppTaskID, ZDO_DEVICE_RESET, delay );
   \   000004                ; Setup parameters for call to function osal_start_timerEx
   \   000004   EA           MOV     A,R2
   \   000005   FC           MOV     R4,A
   \   000006   EB           MOV     A,R3
   \   000007   FD           MOV     R5,A
   \   000008   7A04         MOV     R2,#0x4
   \   00000A   12....       LCALL   ??Subroutine4_0 & 0xFFFF
   1466          }
   \                     ??CrossCallReturnLabel_9:
   \   00000D   02....       LJMP    ??Subroutine16_0 & 0xFFFF
   1467          
   1468          /*********************************************************************
   1469           * @fn      ZDApp_ResetTimerCancel
   1470           *
   1471           * @brief   Cancel the reset timer.
   1472           *
   1473           * @param   none
   1474           *
   1475           * @return  none
   1476           */

   \                                 In  segment BANKED_CODE, align 1, keep-with-next
   1477          void ZDApp_ResetTimerCancel( void )
   \                     ZDApp_ResetTimerCancel:
   1478          {
   \   000000   C082         PUSH    DPL
   \   000002   C083         PUSH    DPH
   \   000004                ; Saved register size: 2
   \   000004                ; Auto size: 0
   1479            // Cancel the reset timer
   1480            osal_stop_timerEx( ZDAppTaskID, ZDO_DEVICE_RESET );
   \   000004                ; Setup parameters for call to function osal_stop_timerEx
   \   000004   7A04         MOV     R2,#0x4
   \   000006   7B00         MOV     R3,#0x0
   \   000008   90....       MOV     DPTR,#ZDAppTaskID
   \   00000B   E0           MOVX    A,@DPTR
   \   00000C   F9           MOV     R1,A
   \   00000D   12....       LCALL   ??osal_stop_timerEx?relay
   1481          }
   \   000010   02....       LJMP    ??Subroutine16_0 & 0xFFFF
   1482          
   1483          /*********************************************************************
   1484           * @fn      ZDApp_LeaveCtrlInit
   1485           *
   1486           * @brief   Initialize the leave control logic.
   1487           *
   1488           * @param   none
   1489           *
   1490           * @return  none
   1491           */

   \                                 In  segment BANKED_CODE, align 1, keep-with-next
   1492          void ZDApp_LeaveCtrlInit( void )
   \                     ZDApp_LeaveCtrlInit:
   1493          {
   \   000000   74F6         MOV     A,#-0xa
   \   000002   12....       LCALL   ?BANKED_ENTER_XDATA
   \   000005                ; Saved register size: 10
   \   000005                ; Auto size: 0
   1494            uint8 status;
   1495          
   1496          
   1497            // Initialize control state
   1498            ZDApp_LeaveCtrl = ZDAPP_LEAVE_CTRL_INIT;
   \   000005   12....       LCALL   ?Subroutine0 & 0xFFFF
   1499          
   1500            status = osal_nv_item_init( ZCD_NV_LEAVE_CTRL,
   1501                                        sizeof(ZDApp_LeaveCtrl),
   1502                                        &ZDApp_LeaveCtrl );
   1503          
   1504            if ( status == ZSUCCESS )
   \                     ??CrossCallReturnLabel_0:
   \   000008   12....       LCALL   ?PUSH_XSTACK_I_TWO
   \   00000B   7C01         MOV     R4,#0x1
   \   00000D   7D00         MOV     R5,#0x0
   \   00000F   7A85         MOV     R2,#-0x7b
   \   000011   7B00         MOV     R3,#0x0
   \   000013   12....       LCALL   ??osal_nv_item_init?relay
   \   000016   7402         MOV     A,#0x2
   \   000018   12....       LCALL   ?DEALLOC_XSTACK8
   \   00001B   E9           MOV     A,R1
   \   00001C   7020         JNZ     ??ZDApp_LeaveCtrlInit_0
   1505            {
   1506              // Read saved control
   1507              osal_nv_read( ZCD_NV_LEAVE_CTRL,
   1508                            0,
   1509                            sizeof( uint8 ),
   1510                            &ZDApp_LeaveCtrl);
   \   00001E                ; Setup parameters for call to function osal_nv_read
   \   00001E   78..         MOV     R0,#?V0 + 0
   \   000020   12....       LCALL   ?PUSH_XSTACK_I_TWO
   \   000023   75..01       MOV     ?V0 + 0,#0x1
   \   000026   75..00       MOV     ?V0 + 1,#0x0
   \   000029   78..         MOV     R0,#?V0 + 0
   \   00002B   12....       LCALL   ?PUSH_XSTACK_I_TWO
   \   00002E   7C00         MOV     R4,#0x0
   \   000030   7D00         MOV     R5,#0x0
   \   000032   7A85         MOV     R2,#-0x7b
   \   000034   7B00         MOV     R3,#0x0
   \   000036   12....       LCALL   ??osal_nv_read?relay
   \   000039   7404         MOV     A,#0x4
   \   00003B   12....       LCALL   ?DEALLOC_XSTACK8
   1511            }
   1512          }
   \                     ??ZDApp_LeaveCtrlInit_0:
   \   00003E   80..         SJMP    ??Subroutine19_1

   \                                 In  segment BANKED_CODE, align 1, keep-with-next
   \                     ?Subroutine0:
   \   000000   E4           CLR     A
   \   000001   90....       MOV     DPTR,#ZDApp_LeaveCtrl
   \   000004   F0           MOVX    @DPTR,A
   \   000005                ; Setup parameters for call to function osal_nv_item_init
   \   000005                ; Setup parameters for call to function osal_nv_write
   \   000005   75....       MOV     ?V0 + 0,#(ZDApp_LeaveCtrl & 0xff)
   \   000008   75....       MOV     ?V0 + 1,#((ZDApp_LeaveCtrl >> 8) & 0xff)
   \   00000B   78..         MOV     R0,#?V0 + 0
   \   00000D   22           RET
   1513          
   1514          /*********************************************************************
   1515           * @fn      ZDApp_LeaveCtrlSet
   1516           *
   1517           * @brief   Set the leave control logic.
   1518           *
   1519           * @param   ra - reassociate flag
   1520           *
   1521           * @return  none
   1522           */

   \                                 In  segment BANKED_CODE, align 1, keep-with-next
   1523          void ZDApp_LeaveCtrlSet( uint8 ra )
   \                     ZDApp_LeaveCtrlSet:
   1524          {
   \   000000   74F6         MOV     A,#-0xa
   \   000002   12....       LCALL   ?BANKED_ENTER_XDATA
   \   000005                ; Saved register size: 10
   \   000005                ; Auto size: 0
   1525            ZDApp_LeaveCtrl = ZDAPP_LEAVE_CTRL_SET;
   \   000005   7401         MOV     A,#0x1
   \   000007   90....       MOV     DPTR,#ZDApp_LeaveCtrl
   \   00000A   F0           MOVX    @DPTR,A
   1526          
   1527            if ( ra == TRUE )
   \   00000B   69           XRL     A,R1
   \   00000C   7003         JNZ     ??ZDApp_LeaveCtrlSet_0
   1528            {
   1529              ZDApp_LeaveCtrl |= ZDAPP_LEAVE_CTRL_RA;
   \   00000E   7403         MOV     A,#0x3
   \   000010   F0           MOVX    @DPTR,A
   1530            }
   1531          
   1532            // Write the leave control
   1533            osal_nv_write( ZCD_NV_LEAVE_CTRL,
   1534                           0,
   1535                           sizeof( uint8 ),
   1536                           &ZDApp_LeaveCtrl);
   \                     ??ZDApp_LeaveCtrlSet_0:
   \   000011                ; Setup parameters for call to function osal_nv_write
   \   000011   75....       MOV     ?V0 + 0,#(ZDApp_LeaveCtrl & 0xff)
   \   000014   75....       MOV     ?V0 + 1,#((ZDApp_LeaveCtrl >> 8) & 0xff)
   \   000017   78..         MOV     R0,#?V0 + 0
   \   000019   12....       LCALL   ?PUSH_XSTACK_I_TWO
   \   00001C   75..01       MOV     ?V0 + 0,#0x1
   \   00001F   75..00       MOV     ?V0 + 1,#0x0
   \   000022   78..         MOV     R0,#?V0 + 0
   \   000024   12....       LCALL   ?PUSH_XSTACK_I_TWO
   \   000027   7C00         MOV     R4,#0x0
   \   000029   7D00         MOV     R5,#0x0
   \   00002B   7A85         MOV     R2,#-0x7b
   \   00002D   12....       LCALL   ??Subroutine13_0 & 0xFFFF
   \                     ??CrossCallReturnLabel_40:
   \   000030   80..         SJMP    ??Subroutine19_0
   1537          }
   1538          
   1539          /*********************************************************************
   1540           * @fn      ZDApp_LeaveCtrlBypass
   1541           *
   1542           * @brief   Check if NV restore should be skipped during a leave reset.
   1543           *
   1544           * @param   none
   1545           *
   1546           * @return  uint8 - (TRUE bypass:FALSE do not bypass)
   1547           */

   \                                 In  segment BANKED_CODE, align 1, keep-with-next
   1548          uint8 ZDApp_LeaveCtrlBypass( void )
   \                     ZDApp_LeaveCtrlBypass:
   1549          {
   \   000000   C082         PUSH    DPL
   \   000002   C083         PUSH    DPH
   \   000004                ; Saved register size: 2
   \   000004                ; Auto size: 0
   1550            uint8 bypass;
   1551          
   1552            if ( ZDApp_LeaveCtrl & ZDAPP_LEAVE_CTRL_SET )
   1553            {
   1554              bypass = TRUE;
   1555            }
   1556            else
   1557            {
   1558              bypass = FALSE;
   1559            }
   1560          
   1561            return bypass;
   \   000004   90....       MOV     DPTR,#ZDApp_LeaveCtrl
   \   000007   E0           MOVX    A,@DPTR
   \   000008   A2E0         MOV     C,0xE0 /* A   */.0
   \   00000A   E4           CLR     A
   \   00000B   92E0         MOV     0xE0 /* A   */.0,C
   \   00000D   F9           MOV     R1,A
   \   00000E   80..         SJMP    ??Subroutine16_0
   1562          }
   1563          
   1564          /*********************************************************************
   1565           * @fn      ZDApp_LeaveCtrlStartup
   1566           *
   1567           * @brief   Check for startup conditions during a leave reset.
   1568           *
   1569           * @param   state      - devState_t determined by leave control logic
   1570           * @param   startDelay - startup delay
   1571           *
   1572           * @return  none
   1573           */

   \                                 In  segment BANKED_CODE, align 1, keep-with-next
   1574          void ZDApp_LeaveCtrlStartup( devStates_t* state, uint16* startDelay )
   \                     ZDApp_LeaveCtrlStartup:
   1575          {
   \   000000   74F6         MOV     A,#-0xa
   \   000002   12....       LCALL   ?BANKED_ENTER_XDATA
   \   000005                ; Saved register size: 10
   \   000005                ; Auto size: 0
   1576            *startDelay = 0;
   \   000005   8C82         MOV     DPL,R4
   \   000007   8D83         MOV     DPH,R5
   \   000009   E4           CLR     A
   \   00000A   F0           MOVX    @DPTR,A
   \   00000B   A3           INC     DPTR
   \   00000C   F0           MOVX    @DPTR,A
   1577          
   1578            if ( ZDApp_LeaveCtrl & ZDAPP_LEAVE_CTRL_SET )
   \   00000D   90....       MOV     DPTR,#ZDApp_LeaveCtrl
   \   000010   E0           MOVX    A,@DPTR
   \   000011   A2E0         MOV     C,0xE0 /* A   */.0
   \   000013   5033         JNC     ??ZDApp_LeaveCtrlStartup_0
   1579            {
   1580              if ( ZDApp_LeaveCtrl & ZDAPP_LEAVE_CTRL_RA )
   \   000015   A2E1         MOV     C,0xE0 /* A   */.1
   \   000017   500C         JNC     ??ZDApp_LeaveCtrlStartup_1
   1581              {
   1582                *startDelay = 5000;
   \   000019   8C82         MOV     DPL,R4
   \   00001B   8D83         MOV     DPH,R5
   \   00001D   7488         MOV     A,#-0x78
   \   00001F   F0           MOVX    @DPTR,A
   \   000020   A3           INC     DPTR
   \   000021   7413         MOV     A,#0x13
   \   000023   8005         SJMP    ??ZDApp_LeaveCtrlStartup_2
   1583              }
   1584              else
   1585              {
   1586                *state = DEV_HOLD;
   \                     ??ZDApp_LeaveCtrlStartup_1:
   \   000025   E4           CLR     A
   \   000026   8A82         MOV     DPL,R2
   \   000028   8B83         MOV     DPH,R3
   \                     ??ZDApp_LeaveCtrlStartup_2:
   \   00002A   F0           MOVX    @DPTR,A
   1587              }
   1588          
   1589              // Set leave control to initialized state
   1590              ZDApp_LeaveCtrl = ZDAPP_LEAVE_CTRL_INIT;
   \   00002B   12....       LCALL   ?Subroutine0 & 0xFFFF
   1591          
   1592              // Write initialized control
   1593              osal_nv_write( ZCD_NV_LEAVE_CTRL,
   1594                            0,
   1595                            sizeof( uint8 ),
   1596                            &ZDApp_LeaveCtrl);
   \                     ??CrossCallReturnLabel_1:
   \   00002E   12....       LCALL   ?PUSH_XSTACK_I_TWO
   \   000031   75..01       MOV     ?V0 + 0,#0x1
   \   000034   75..00       MOV     ?V0 + 1,#0x0
   \   000037   78..         MOV     R0,#?V0 + 0
   \   000039   12....       LCALL   ?PUSH_XSTACK_I_TWO
   \   00003C   7C00         MOV     R4,#0x0
   \   00003E   7D00         MOV     R5,#0x0
   \   000040   7A85         MOV     R2,#-0x7b
   \   000042   12....       LCALL   ??Subroutine13_0 & 0xFFFF
   \                     ??CrossCallReturnLabel_41:
   \   000045   12....       LCALL   ?DEALLOC_XSTACK8
   1597            }
   1598          }
   \                     ??ZDApp_LeaveCtrlStartup_0:
   \   000048   80..         SJMP    ??Subroutine19_1
   1599          
   1600          /*********************************************************************
   1601           * @fn      ZDApp_LeaveReset
   1602           *
   1603           * @brief   Setup a device reset due to a leave indication/confirm.
   1604           *
   1605           * @param   ra - reassociate flag
   1606           *
   1607           * @return  none
   1608           */

   \                                 In  segment BANKED_CODE, align 1, keep-with-next
   1609          void ZDApp_LeaveReset( uint8 ra )
   \                     ZDApp_LeaveReset:
   1610          {
   \   000000   C082         PUSH    DPL
   \   000002   C083         PUSH    DPH
   \   000004                ; Saved register size: 2
   \   000004                ; Auto size: 0
   1611            ZDApp_LeaveCtrlSet( ra );
   \   000004                ; Setup parameters for call to function ZDApp_LeaveCtrlSet
   \   000004   12....       LCALL   ??ZDApp_LeaveCtrlSet?relay
   1612          
   1613            ZDApp_ResetTimerStart( 5000 );
   \   000007                ; Setup parameters for call to function ZDApp_ResetTimerStart
   \   000007   7A88         MOV     R2,#-0x78
   \   000009   7B13         MOV     R3,#0x13
   \   00000B   12....       LCALL   ??ZDApp_ResetTimerStart?relay
   1614          }
   \   00000E   80..         SJMP    ??Subroutine16_0
   1615          
   1616          /*********************************************************************
   1617           * @fn      ZDApp_LeaveUpdate
   1618           *
   1619           * @brief   Update local device data related to leaving device.
   1620           *
   1621           * @param   nwkAddr        - NWK address of leaving device
   1622           * @param   extAddr        - EXT address of leaving device
   1623           * @param   removeChildren - remove children of leaving device
   1624           *
   1625           * @return  none
   1626           */

   \                                 In  segment BANKED_CODE, align 1, keep-with-next
   1627          void ZDApp_LeaveUpdate( uint16 nwkAddr, uint8* extAddr,
   \                     ZDApp_LeaveUpdate:
   1628                                  uint8 removeChildren )
   1629          {
   \   000000   C082         PUSH    DPL
   \   000002   C083         PUSH    DPH
   \   000004                ; Saved register size: 2
   \   000004                ; Auto size: 0
   \   000004   EC           MOV     A,R4
   \   000005   FA           MOV     R2,A
   \   000006   ED           MOV     A,R5
   \   000007   FB           MOV     R3,A
   1630            /*
   1631            AddrMgrEntry_t entry;
   1632            */
   1633          
   1634          
   1635            // Remove if child
   1636            NLME_RemoveChild( extAddr, removeChildren );
   \   000008                ; Setup parameters for call to function NLME_RemoveChild
   \   000008   12....       LCALL   ??NLME_RemoveChild?relay
   1637          
   1638            /*
   1639            // Set NWK address to invalid
   1640            entry.user    = ADDRMGR_USER_DEFAULT;
   1641            entry.nwkAddr = INVALID_NODE_ADDR;
   1642            AddrMgrExtAddrSet( entry.extAddr, extAddr );
   1643            AddrMgrEntryUpdate( &entry );
   1644          
   1645            // Check
   1646            if ( removeChildren == TRUE )
   1647            {
   1648              // Set index to INVALID_NODE_ADDR to start search
   1649              entry.index = INVALID_NODE_ADDR;
   1650          
   1651              // Get first entry
   1652              AddrMgrEntryGetNext( &entry );
   1653          
   1654              // Remove all descendents
   1655              while ( entry.index != INVALID_NODE_ADDR )
   1656              {
   1657                // Check NWK address allocation algorithm
   1658                if ( RTG_ANCESTOR( entry.nwkAddr, thisAddr ) != 0 )
   1659                {
   1660                  // Set NWK address to invalid
   1661                  entry.nwkAddr = INVALID_NODE_ADDR;
   1662                  AddrMgrEntryUpdate( &entry );
   1663                }
   1664          
   1665                // Get next entry
   1666                AddrMgrEntryGetNext( &entry );
   1667              }
   1668            }
   1669            */
   1670          }
   \   00000B   80..         SJMP    ??Subroutine16_0
   1671          
   1672          /*********************************************************************
   1673           * CALLBACK FUNCTIONS
   1674           */
   1675          
   1676          /*********************************************************************
   1677           * @fn      ZDApp_SendEventMsg()
   1678           *
   1679           * @brief
   1680           *
   1681           *   Sends a Network Join message
   1682           *
   1683           * @param  cmd - command ID
   1684           * @param  len - length (in bytes) of the buf field
   1685           * @param  buf - buffer for the rest of the message.
   1686           *
   1687           * @return  none
   1688           */

   \                                 In  segment BANKED_CODE, align 1, keep-with-next
   1689          void ZDApp_SendEventMsg( byte cmd, byte len, byte *buf )
   \                     ZDApp_SendEventMsg:
   1690          {
   \   000000   C082         PUSH    DPL
   \   000002   C083         PUSH    DPH
   \   000004                ; Saved register size: 2
   \   000004                ; Auto size: 0
   1691            ZDApp_SendMsg( ZDAppTaskID, cmd, len, buf );
   \   000004                ; Setup parameters for call to function ZDApp_SendMsg
   \   000004   EA           MOV     A,R2
   \   000005   FB           MOV     R3,A
   \   000006   E9           MOV     A,R1
   \   000007   FA           MOV     R2,A
   \   000008                REQUIRE ?Subroutine21
   \   000008                ; // Fall through to label ?Subroutine21
   1692          }

   \                                 In  segment BANKED_CODE, align 1, keep-with-next
   \                     ?Subroutine21:
   \   000000   12....       LCALL   ?Subroutine7 & 0xFFFF
   \                     ??CrossCallReturnLabel_46:
   \   000003   80..         SJMP    ??Subroutine16_0

   \                                 In  segment BANKED_CODE, align 1, keep-with-next
   \                     ?Subroutine7:
   \   000000   90....       MOV     DPTR,#ZDAppTaskID
   \   000003   E0           MOVX    A,@DPTR
   \   000004   F9           MOV     R1,A
   \   000005   12....       LCALL   ??ZDApp_SendMsg?relay
   \   000008   22           RET
   1693          
   1694          /*********************************************************************
   1695           * @fn      ZDApp_SendMsg()
   1696           *
   1697           * @brief   Sends a OSAL message
   1698           *
   1699           * @param  taskID - Where to send the message
   1700           * @param  cmd - command ID
   1701           * @param  len - length (in bytes) of the buf field
   1702           * @param  buf - buffer for the rest of the message.
   1703           *
   1704           * @return  none
   1705           */

   \                                 In  segment BANKED_CODE, align 1, keep-with-next
   1706          void ZDApp_SendMsg( byte taskID, byte cmd, byte len, byte *buf )
   \                     ZDApp_SendMsg:
   1707          {
   \   000000   74F0         MOV     A,#-0x10
   \   000002   12....       LCALL   ?BANKED_ENTER_XDATA
   \   000005                ; Saved register size: 16
   \   000005                ; Auto size: 0
   \   000005   E9           MOV     A,R1
   \   000006   FE           MOV     R6,A
   \   000007   8A..         MOV     ?V0 + 3,R2
   \   000009   EB           MOV     A,R3
   \   00000A   FF           MOV     R7,A
   \   00000B   8C..         MOV     ?V0 + 6,R4
   \   00000D   8D..         MOV     ?V0 + 7,R5
   1708            osal_event_hdr_t *msgPtr;
   1709          
   1710            // Send the address to the task
   1711            msgPtr = (osal_event_hdr_t *)osal_msg_allocate( len );
   \   00000F                ; Setup parameters for call to function osal_msg_allocate
   \   00000F   FA           MOV     R2,A
   \   000010   7B00         MOV     R3,#0x0
   \   000012   12....       LCALL   ??osal_msg_allocate?relay
   \   000015   8A..         MOV     ?V0 + 4,R2
   \   000017   8B..         MOV     ?V0 + 5,R3
   1712            if ( msgPtr )
   \   000019   EA           MOV     A,R2
   \   00001A   7001         JNZ     ??ZDApp_SendMsg_0
   \   00001C   EB           MOV     A,R3
   \                     ??ZDApp_SendMsg_0:
   \   00001D   6037         JZ      ??ZDApp_SendMsg_1
   1713            {
   1714              if ( (len > 0) && (buf != NULL) )
   \   00001F   EF           MOV     A,R7
   \   000020   6022         JZ      ??ZDApp_SendMsg_2
   \   000022   E5..         MOV     A,?V0 + 6
   \   000024   7002         JNZ     ??ZDApp_SendMsg_3
   \   000026   E5..         MOV     A,?V0 + 7
   \                     ??ZDApp_SendMsg_3:
   \   000028   601A         JZ      ??ZDApp_SendMsg_2
   1715                osal_memcpy( msgPtr, buf, len );
   \   00002A                ; Setup parameters for call to function osal_memcpy
   \   00002A   85....       MOV     ?V0 + 0,?V0 + 6
   \   00002D   85....       MOV     ?V0 + 1,?V0 + 7
   \   000030   75..00       MOV     ?V0 + 2,#0x0
   \   000033   78..         MOV     R0,#?V0 + 0
   \   000035   12....       LCALL   ?PUSH_XSTACK_I_THREE
   \   000038   EF           MOV     A,R7
   \   000039   FC           MOV     R4,A
   \   00003A   7D00         MOV     R5,#0x0
   \   00003C   12....       LCALL   ??osal_memcpy?relay
   \   00003F   7403         MOV     A,#0x3
   \   000041   12....       LCALL   ?DEALLOC_XSTACK8
   1716          
   1717              msgPtr->event = cmd;
   \                     ??ZDApp_SendMsg_2:
   \   000044   85..82       MOV     DPL,?V0 + 4
   \   000047   85..83       MOV     DPH,?V0 + 5
   \   00004A   E5..         MOV     A,?V0 + 3
   \   00004C   F0           MOVX    @DPTR,A
   1718              osal_msg_send( taskID, (byte *)msgPtr );
   \   00004D                ; Setup parameters for call to function osal_msg_send
   \   00004D   AA..         MOV     R2,?V0 + 4
   \   00004F   AB..         MOV     R3,?V0 + 5
   \   000051   EE           MOV     A,R6
   \   000052   F9           MOV     R1,A
   \   000053   12....       LCALL   ??osal_msg_send?relay
   1719            }
   1720          }
   \                     ??ZDApp_SendMsg_1:
   \   000056   7F08         MOV     R7,#0x8
   \   000058   02....       LJMP    ?BANKED_LEAVE_XDATA
   1721          
   1722          /*********************************************************************
   1723           * Call Back Functions from NWK  - API
   1724           */
   1725          
   1726          /*********************************************************************
   1727           * @fn          ZDO_NetworkDiscoveryConfirmCB
   1728           *
   1729           * @brief       This function returns a choice of PAN to join.
   1730           *
   1731           * @param       ResultCount - Number of routers discovered
   1732           * @param               NetworkList - Pointer to list of network descriptors
   1733           *
   1734           * @return      ZStatus_t
   1735           */
   1736          #define STACK_PROFILE_MAX 2

   \                                 In  segment BANKED_CODE, align 1, keep-with-next
   1737          ZStatus_t ZDO_NetworkDiscoveryConfirmCB( byte ResultCount,
   \                     ZDO_NetworkDiscoveryConfirmCB:
   1738                                                   networkDesc_t *NetworkList )
   1739          {
   \   000000   74F6         MOV     A,#-0xa
   \   000002   12....       LCALL   ?BANKED_ENTER_XDATA
   \   000005                ; Saved register size: 10
   \   000005                ; Auto size: 14
   \   000005   74F2         MOV     A,#-0xe
   \   000007   12....       LCALL   ?ALLOC_XSTACK8
   \   00000A   E9           MOV     A,R1
   \   00000B   FE           MOV     R6,A
   \   00000C   EA           MOV     A,R2
   \   00000D   F8           MOV     R0,A
   \   00000E   EB           MOV     A,R3
   \   00000F   F9           MOV     R1,A
   1740            networkDesc_t *pNwkDesc;
   1741            ZDO_NetworkDiscoveryCfm_t msg;
   1742            byte  i;
   1743            uint8 stackProfile;
   1744            uint8 stackProfilePro;
   1745            uint8 selected;
   1746          
   1747          #if defined ( ZDO_MGMT_NWKDISC_RESPONSE )
   1748            if ( zdappMgmtNwkDiscReqInProgress )
   1749            {
   1750              zdappMgmtNwkDiscReqInProgress = false;
   1751              ZDO_FinishProcessingMgmtNwkDiscReq( ResultCount, NetworkList );
   1752              return ( ZSuccess );
   1753            }
   1754          #endif
   1755          
   1756            // process discovery results
   1757            stackProfilePro = FALSE;
   \   000010   75..00       MOV     ?V0 + 1,#0x0
   1758            selected = FALSE;
   1759          
   1760            for ( stackProfile = 0; stackProfile < STACK_PROFILE_MAX; stackProfile++ )
   \   000013   7F00         MOV     R7,#0x0
   1761            {
   1762              pNwkDesc = NetworkList;
   \                     ??ZDO_NetworkDiscoveryConfirmCB_0:
   \   000015   E8           MOV     A,R0
   \   000016   FA           MOV     R2,A
   \   000017   E9           MOV     A,R1
   \   000018   FB           MOV     R3,A
   1763              for ( i = 0; i < ResultCount; i++, pNwkDesc = pNwkDesc->nextDesc )
   \   000019   75..00       MOV     ?V0 + 0,#0x0
   \   00001C   8056         SJMP    ??ZDO_NetworkDiscoveryConfirmCB_1
   1764              {
   1765                if ( zgConfigPANID != 0xFFFF )
   1766                {
   1767                  // PAN Id is preconfigured. check if it matches
   1768                  // only 14 bits of pan id is used
   1769                  if ( pNwkDesc->panId != ( zgConfigPANID & 0x3FFF ) )
   1770                    continue;
   1771                }
   1772          
   1773                // check that network is allowing joining
   1774                //------------------------------------------------------------
   1775                #if defined( RTR_NWK )
   1776                //------------------------------------------------------------
   1777                if ( stackProfilePro == FALSE )
   1778                {
   1779                  if ( !pNwkDesc->routerCapacity )
   1780                  {
   1781                    continue;
   1782                  }
   1783                }
   1784                else
   1785                {
   1786                  if ( !pNwkDesc->deviceCapacity )
   \                     ??ZDO_NetworkDiscoveryConfirmCB_2:
   \   00001E   A3           INC     DPTR
   \   00001F   E0           MOVX    A,@DPTR
   \   000020   6043         JZ      ??ZDO_NetworkDiscoveryConfirmCB_3
   1787                  {
   1788                    continue;
   1789                  }
   1790                }
   1791                //------------------------------------------------------------
   1792                #else
   1793                //------------------------------------------------------------
   1794                if ( !pNwkDesc->deviceCapacity )
   1795                {
   1796                  continue;
   1797                }
   1798                //------------------------------------------------------------
   1799                #endif
   1800                //------------------------------------------------------------
   1801                // check version of zigbee protocol
   1802                if ( pNwkDesc->version != _NIB.nwkProtocolVersion )
   \                     ??ZDO_NetworkDiscoveryConfirmCB_4:
   \   000022   8A82         MOV     DPL,R2
   \   000024   8B83         MOV     DPH,R3
   \   000026   A3           INC     DPTR
   \   000027   A3           INC     DPTR
   \   000028   A3           INC     DPTR
   \   000029   A3           INC     DPTR
   \   00002A   A3           INC     DPTR
   \   00002B   A3           INC     DPTR
   \   00002C   A3           INC     DPTR
   \   00002D   E0           MOVX    A,@DPTR
   \   00002E   FC           MOV     R4,A
   \   00002F   90....       MOV     DPTR,#(_NIB + 17)
   \   000032   E0           MOVX    A,@DPTR
   \   000033   6C           XRL     A,R4
   \   000034   702F         JNZ     ??ZDO_NetworkDiscoveryConfirmCB_3
   1803                  continue;
   1804          
   1805                // check version of stack profile
   1806                if ( pNwkDesc->stackProfile != zgStackProfile  )
   \   000036   8A82         MOV     DPL,R2
   \   000038   8B83         MOV     DPH,R3
   \   00003A   A3           INC     DPTR
   \   00003B   A3           INC     DPTR
   \   00003C   A3           INC     DPTR
   \   00003D   A3           INC     DPTR
   \   00003E   A3           INC     DPTR
   \   00003F   A3           INC     DPTR
   \   000040   A3           INC     DPTR
   \   000041   A3           INC     DPTR
   \   000042   E0           MOVX    A,@DPTR
   \   000043   FC           MOV     R4,A
   \   000044   90....       MOV     DPTR,#zgStackProfile
   \   000047   E0           MOVX    A,@DPTR
   \   000048   6C           XRL     A,R4
   \   000049   7003         JNZ     $+5
   \   00004B   02....       LJMP    ??ZDO_NetworkDiscoveryConfirmCB_5 & 0xFFFF
   1807                {
   1808                  if ( pNwkDesc->stackProfile == ZIGBEEPRO_PROFILE )
   \   00004E   8A82         MOV     DPL,R2
   \   000050   8B83         MOV     DPH,R3
   \   000052   A3           INC     DPTR
   \   000053   A3           INC     DPTR
   \   000054   A3           INC     DPTR
   \   000055   A3           INC     DPTR
   \   000056   A3           INC     DPTR
   \   000057   A3           INC     DPTR
   \   000058   A3           INC     DPTR
   \   000059   A3           INC     DPTR
   \   00005A   E0           MOVX    A,@DPTR
   \   00005B   6402         XRL     A,#0x2
   \   00005D   7003         JNZ     ??ZDO_NetworkDiscoveryConfirmCB_6
   1809                    stackProfilePro = TRUE;
   \   00005F   75..01       MOV     ?V0 + 1,#0x1
   1810          
   1811                  if ( stackProfile == 0 )
   \                     ??ZDO_NetworkDiscoveryConfirmCB_6:
   \   000062   EF           MOV     A,R7
   \   000063   706F         JNZ     ??ZDO_NetworkDiscoveryConfirmCB_5
   1812                  {
   1813                    continue;
   1814                  }
   1815                }
   \                     ??ZDO_NetworkDiscoveryConfirmCB_3:
   \   000065   05..         INC     ?V0 + 0
   \   000067   EA           MOV     A,R2
   \   000068   2415         ADD     A,#0x15
   \   00006A   F582         MOV     DPL,A
   \   00006C   EB           MOV     A,R3
   \   00006D   12....       LCALL   ??Subroutine11_1 & 0xFFFF
   \                     ??CrossCallReturnLabel_28:
   \   000070   FA           MOV     R2,A
   \   000071   A3           INC     DPTR
   \   000072   E0           MOVX    A,@DPTR
   \   000073   FB           MOV     R3,A
   \                     ??ZDO_NetworkDiscoveryConfirmCB_1:
   \   000074   E5..         MOV     A,?V0 + 0
   \   000076   C3           CLR     C
   \   000077   9E           SUBB    A,R6
   \   000078   503D         JNC     ??ZDO_NetworkDiscoveryConfirmCB_7
   \   00007A   90....       MOV     DPTR,#zgConfigPANID
   \   00007D   E0           MOVX    A,@DPTR
   \   00007E   64FF         XRL     A,#0xff
   \   000080   7004         JNZ     ??ZDO_NetworkDiscoveryConfirmCB_8
   \   000082   A3           INC     DPTR
   \   000083   E0           MOVX    A,@DPTR
   \   000084   64FF         XRL     A,#0xff
   \                     ??ZDO_NetworkDiscoveryConfirmCB_8:
   \   000086   6017         JZ      ??ZDO_NetworkDiscoveryConfirmCB_9
   \   000088   90....       MOV     DPTR,#zgConfigPANID
   \   00008B   E0           MOVX    A,@DPTR
   \   00008C   FC           MOV     R4,A
   \   00008D   A3           INC     DPTR
   \   00008E   E0           MOVX    A,@DPTR
   \   00008F   543F         ANL     A,#0x3f
   \   000091   FD           MOV     R5,A
   \   000092   8B83         MOV     DPH,R3
   \   000094   8A82         MOV     DPL,R2
   \   000096   E0           MOVX    A,@DPTR
   \   000097   6C           XRL     A,R4
   \   000098   7003         JNZ     ??ZDO_NetworkDiscoveryConfirmCB_10
   \   00009A   A3           INC     DPTR
   \   00009B   E0           MOVX    A,@DPTR
   \   00009C   6D           XRL     A,R5
   \                     ??ZDO_NetworkDiscoveryConfirmCB_10:
   \   00009D   70C6         JNZ     ??ZDO_NetworkDiscoveryConfirmCB_3
   \                     ??ZDO_NetworkDiscoveryConfirmCB_9:
   \   00009F   E5..         MOV     A,?V0 + 1
   \   0000A1   8A82         MOV     DPL,R2
   \   0000A3   8B83         MOV     DPH,R3
   \   0000A5   A3           INC     DPTR
   \   0000A6   A3           INC     DPTR
   \   0000A7   A3           INC     DPTR
   \   0000A8   A3           INC     DPTR
   \   0000A9   A3           INC     DPTR
   \   0000AA   6003         JZ      $+5
   \   0000AC   02....       LJMP    ??ZDO_NetworkDiscoveryConfirmCB_2 & 0xFFFF
   \   0000AF   E0           MOVX    A,@DPTR
   \   0000B0   6003         JZ      $+5
   \   0000B2   02....       LJMP    ??ZDO_NetworkDiscoveryConfirmCB_4 & 0xFFFF
   \   0000B5   80AE         SJMP    ??ZDO_NetworkDiscoveryConfirmCB_3
   1816          
   1817                // check if beacon order is the right value..
   1818                //  if ( pNwkDesc->beaconOrder < ZDO_CONFIG_MAX_BO )
   1819                //    continue;
   1820          
   1821                // choose this pan for joining
   1822                break;
   1823              }
   1824          
   1825              if (i < ResultCount)
   1826              {
   1827               selected = TRUE;
   1828                break;
   1829              }
   1830          
   1831              // break if selected or stack profile pro wasn't found
   1832              if ( (selected == TRUE) || (stackProfilePro == FALSE) )
   \                     ??ZDO_NetworkDiscoveryConfirmCB_7:
   \   0000B7   E5..         MOV     A,?V0 + 1
   \   0000B9   600A         JZ      ??ZDO_NetworkDiscoveryConfirmCB_11
   1833              {
   1834                break;
   1835              }
   1836            }
   \   0000BB   0F           INC     R7
   \   0000BC   EF           MOV     A,R7
   \   0000BD   C3           CLR     C
   \   0000BE   9402         SUBB    A,#0x2
   \   0000C0   5003         JNC     $+5
   \   0000C2   02....       LJMP    ??ZDO_NetworkDiscoveryConfirmCB_0 & 0xFFFF
   1837          
   1838            if ( i == ResultCount )
   \                     ??ZDO_NetworkDiscoveryConfirmCB_11:
   \   0000C5   EE           MOV     A,R6
   \   0000C6   65..         XRL     A,?V0 + 0
   \   0000C8   700A         JNZ     ??ZDO_NetworkDiscoveryConfirmCB_5
   1839            {
   1840              msg.hdr.status = ZDO_FAIL;   // couldn't find appropriate PAN to join !
   \   0000CA   7401         MOV     A,#0x1
   \   0000CC   12....       LCALL   ?XSTACK_DISP0_8
   \   0000CF   7401         MOV     A,#0x1
   \   0000D1   F0           MOVX    @DPTR,A
   \   0000D2   8058         SJMP    ??ZDO_NetworkDiscoveryConfirmCB_12
   1841            }
   1842            else
   1843            {
   1844              msg.hdr.status = ZDO_SUCCESS;
   \                     ??ZDO_NetworkDiscoveryConfirmCB_5:
   \   0000D4   7401         MOV     A,#0x1
   \   0000D6   12....       LCALL   ?XSTACK_DISP0_8
   \   0000D9   E4           CLR     A
   \   0000DA   F0           MOVX    @DPTR,A
   1845              msg.panIdLSB = LO_UINT16( pNwkDesc->panId );
   \   0000DB   8A82         MOV     DPL,R2
   \   0000DD   8B83         MOV     DPH,R3
   \   0000DF   E0           MOVX    A,@DPTR
   \   0000E0   C0E0         PUSH    A
   \   0000E2   7402         MOV     A,#0x2
   \   0000E4   12....       LCALL   ?XSTACK_DISP0_8
   \   0000E7   D0E0         POP     A
   \   0000E9   12....       LCALL   ?Subroutine1 & 0xFFFF
   1846              msg.panIdMSB = HI_UINT16( pNwkDesc->panId );
   \                     ??CrossCallReturnLabel_2:
   \   0000EC   E0           MOVX    A,@DPTR
   \   0000ED   C0E0         PUSH    A
   \   0000EF   7403         MOV     A,#0x3
   \   0000F1   12....       LCALL   ?XSTACK_DISP0_8
   \   0000F4   D0E0         POP     A
   \   0000F6   12....       LCALL   ?Subroutine1 & 0xFFFF
   1847              msg.logicalChannel = pNwkDesc->logicalChannel;
   \                     ??CrossCallReturnLabel_3:
   \   0000F9   A3           INC     DPTR
   \   0000FA   E0           MOVX    A,@DPTR
   \   0000FB   C0E0         PUSH    A
   \   0000FD   7404         MOV     A,#0x4
   \   0000FF   12....       LCALL   ?XSTACK_DISP0_8
   \   000102   D0E0         POP     A
   \   000104   12....       LCALL   ?Subroutine1 & 0xFFFF
   1848              msg.version = pNwkDesc->version;
   \                     ??CrossCallReturnLabel_4:
   \   000107   A3           INC     DPTR
   \   000108   A3           INC     DPTR
   \   000109   A3           INC     DPTR
   \   00010A   A3           INC     DPTR
   \   00010B   A3           INC     DPTR
   \   00010C   A3           INC     DPTR
   \   00010D   E0           MOVX    A,@DPTR
   \   00010E   C0E0         PUSH    A
   \   000110   7405         MOV     A,#0x5
   \   000112   12....       LCALL   ?XSTACK_DISP0_8
   \   000115   D0E0         POP     A
   \   000117   F0           MOVX    @DPTR,A
   1849              osal_cpyExtAddr( msg.extendedPANID, pNwkDesc->extendedPANID );
   \   000118                ; Setup parameters for call to function osal_cpyExtAddr
   \   000118   EA           MOV     A,R2
   \   000119   240D         ADD     A,#0xd
   \   00011B   FC           MOV     R4,A
   \   00011C   EB           MOV     A,R3
   \   00011D   3400         ADDC    A,#0x0
   \   00011F   FD           MOV     R5,A
   \   000120   7406         MOV     A,#0x6
   \   000122   12....       LCALL   ?XSTACK_DISP0_8
   \   000125   AA82         MOV     R2,DPL
   \   000127   AB83         MOV     R3,DPH
   \   000129   12....       LCALL   ??osal_cpyExtAddr?relay
   1850            }
   1851          
   1852            ZDApp_SendMsg( ZDAppTaskID, ZDO_NWK_DISC_CNF, sizeof(ZDO_NetworkDiscoveryCfm_t), (byte *)&msg );
   \                     ??ZDO_NetworkDiscoveryConfirmCB_12:
   \   00012C                ; Setup parameters for call to function ZDApp_SendMsg
   \   00012C   85..82       MOV     DPL,?XSP + 0
   \   00012F   85..83       MOV     DPH,?XSP + 1
   \   000132   AC82         MOV     R4,DPL
   \   000134   AD83         MOV     R5,DPH
   \   000136   7B0E         MOV     R3,#0xe
   \   000138   7A01         MOV     R2,#0x1
   \   00013A   12....       LCALL   ?Subroutine7 & 0xFFFF
   1853          
   1854            return (ZSuccess);
   \                     ??CrossCallReturnLabel_47:
   \   00013D   7900         MOV     R1,#0x0
   \   00013F   740E         MOV     A,#0xe
   \   000141   02....       LJMP    ??Subroutine19_0 & 0xFFFF
   1855          }  // ZDO_NetworkDiscoveryConfirmCB

   \                                 In  segment BANKED_CODE, align 1, keep-with-next
   \                     ?Subroutine1:
   \   000000   F0           MOVX    @DPTR,A
   \   000001   8A82         MOV     DPL,R2
   \   000003   8B83         MOV     DPH,R3
   \   000005   A3           INC     DPTR
   \   000006   22           RET
   1856          
   1857          /*********************************************************************
   1858           * @fn          ZDO_NetworkFormationConfirmCB
   1859           *
   1860           * @brief       This function reports the results of the request to
   1861           *              initialize a coordinator in a network.
   1862           *
   1863           * @param       Status - Result of NLME_NetworkFormationRequest()
   1864           *
   1865           * @return      none
   1866           */

   \                                 In  segment BANKED_CODE, align 1, keep-with-next
   1867          void ZDO_NetworkFormationConfirmCB( ZStatus_t Status )
   \                     ZDO_NetworkFormationConfirmCB:
   1868          {
   \   000000   C082         PUSH    DPL
   \   000002   C083         PUSH    DPH
   \   000004                ; Saved register size: 2
   \   000004                ; Auto size: 0
   1869          #if defined(ZDO_COORDINATOR)
   1870            nwkStatus = (byte)Status;
   \   000004   E9           MOV     A,R1
   \   000005   90....       MOV     DPTR,#nwkStatus
   \   000008   F0           MOVX    @DPTR,A
   1871          
   1872            if ( Status == ZSUCCESS )
   \   000009   700A         JNZ     ??ZDO_NetworkFormationConfirmCB_0
   1873            {
   1874              // LED on shows Coordinator started
   1875              HalLedSet ( HAL_LED_3, HAL_LED_MODE_ON );
   \   00000B                ; Setup parameters for call to function HalLedSet
   \   00000B   12....       LCALL   ?Subroutine12 & 0xFFFF
   1876          
   1877              // LED off forgets HOLD_AUTO_START
   1878              HalLedSet (HAL_LED_4, HAL_LED_MODE_OFF);
   1879          
   1880          #if defined ( ZBIT )
   1881              SIM_SetColor(0xd0ffd0);
   1882          #endif
   1883          
   1884              if ( devState == DEV_HOLD )
   \                     ??CrossCallReturnLabel_35:
   \   00000E   700C         JNZ     ??ZDO_NetworkFormationConfirmCB_1
   1885              {
   1886                // Began with HOLD_AUTO_START
   1887                devState = DEV_COORD_STARTING;
   \   000010   7408         MOV     A,#0x8
   \   000012   F0           MOVX    @DPTR,A
   \   000013   8007         SJMP    ??ZDO_NetworkFormationConfirmCB_1
   1888              }
   1889            }
   1890          #if defined(BLINK_LEDS)
   1891            else
   1892              HalLedSet ( HAL_LED_3, HAL_LED_MODE_FLASH );  // Flash LED to show failure
   \                     ??ZDO_NetworkFormationConfirmCB_0:
   \   000015                ; Setup parameters for call to function HalLedSet
   \   000015   7A04         MOV     R2,#0x4
   \   000017   7904         MOV     R1,#0x4
   \   000019   12....       LCALL   ??HalLedSet?relay
   1893          #endif
   1894          
   1895            osal_set_event( ZDAppTaskID, ZDO_NETWORK_START );
   \                     ??ZDO_NetworkFormationConfirmCB_1:
   \   00001C                ; Setup parameters for call to function osal_set_event
   \   00001C   7A02         MOV     R2,#0x2
   \   00001E   02....       LJMP    ?Subroutine16 & 0xFFFF
   1896          #endif  //ZDO_COORDINATOR
   1897          }

   \                                 In  segment BANKED_CODE, align 1, keep-with-next
   \                     ?Subroutine12:
   \   000000   7A01         MOV     R2,#0x1
   \   000002   7904         MOV     R1,#0x4
   \   000004   12....       LCALL   ??HalLedSet?relay
   \   000007                ; Setup parameters for call to function HalLedSet
   \   000007                ; Setup parameters for call to function HalLedSet
   \   000007                ; Setup parameters for call to function HalLedSet
   \   000007   7A00         MOV     R2,#0x0
   \   000009   7908         MOV     R1,#0x8
   \   00000B   12....       LCALL   ??HalLedSet?relay
   \   00000E   90....       MOV     DPTR,#devState
   \   000011   E0           MOVX    A,@DPTR
   \   000012   22           RET
   1898          
   1899          #if defined(RTR_NWK)
   1900          /*********************************************************************
   1901           * @fn          ZDO_StartRouterConfirmCB
   1902           *
   1903           * @brief       This function reports the results of the request to
   1904           *              start functioning as a router in a network.
   1905           *
   1906           * @param       Status - Result of NLME_StartRouterRequest()
   1907           *
   1908           * @return      none
   1909           */

   \                                 In  segment BANKED_CODE, align 1, keep-with-next
   1910          void ZDO_StartRouterConfirmCB( ZStatus_t Status )
   \                     ZDO_StartRouterConfirmCB:
   1911          {
   \   000000   C082         PUSH    DPL
   \   000002   C083         PUSH    DPH
   \   000004                ; Saved register size: 2
   \   000004                ; Auto size: 0
   1912            nwkStatus = (byte)Status;
   \   000004   E9           MOV     A,R1
   \   000005   90....       MOV     DPTR,#nwkStatus
   \   000008   F0           MOVX    @DPTR,A
   1913          
   1914            if ( Status == ZSUCCESS )
   \   000009   700A         JNZ     ??ZDO_StartRouterConfirmCB_0
   1915            {
   1916              // LED on shows Router started
   1917              HalLedSet ( HAL_LED_3, HAL_LED_MODE_ON );
   \   00000B                ; Setup parameters for call to function HalLedSet
   \   00000B   12....       LCALL   ?Subroutine12 & 0xFFFF
   1918              // LED off forgets HOLD_AUTO_START
   1919              HalLedSet ( HAL_LED_4, HAL_LED_MODE_OFF);
   1920              if ( devState == DEV_HOLD )
   \                     ??CrossCallReturnLabel_36:
   \   00000E   700C         JNZ     ??ZDO_StartRouterConfirmCB_1
   1921              {
   1922                // Began with HOLD_AUTO_START
   1923                devState = DEV_END_DEVICE;
   \   000010   7406         MOV     A,#0x6
   \   000012   F0           MOVX    @DPTR,A
   \   000013   8007         SJMP    ??ZDO_StartRouterConfirmCB_1
   1924              }
   1925            }
   1926          #if defined(BLINK_LEDS)
   1927            else
   1928              HalLedSet( HAL_LED_3, HAL_LED_MODE_FLASH );  // Flash LED to show failure
   \                     ??ZDO_StartRouterConfirmCB_0:
   \   000015                ; Setup parameters for call to function HalLedSet
   \   000015   7A04         MOV     R2,#0x4
   \   000017   7904         MOV     R1,#0x4
   \   000019   12....       LCALL   ??HalLedSet?relay
   1929          #endif
   1930          
   1931            osal_set_event( ZDAppTaskID, ZDO_ROUTER_START );
   \                     ??ZDO_StartRouterConfirmCB_1:
   \   00001C                ; Setup parameters for call to function osal_set_event
   \   00001C   7A20         MOV     R2,#0x20
   \   00001E   02....       LJMP    ?Subroutine16 & 0xFFFF
   1932          }
   1933          #endif  //RTR_NWK
   1934          
   1935          /*********************************************************************
   1936           * @fn          ZDO_JoinConfirmCB
   1937           *
   1938           * @brief       This function allows the next hight layer to be notified
   1939           *              of the results of its request to join itself or another
   1940           *              device to a network.
   1941           *
   1942           * @param       Status - Result of NLME_JoinRequest()
   1943           *
   1944           * @return      none
   1945           */

   \                                 In  segment BANKED_CODE, align 1, keep-with-next
   1946          void ZDO_JoinConfirmCB( uint16 PanId, ZStatus_t Status )
   \                     ZDO_JoinConfirmCB:
   1947          {
   \   000000   C082         PUSH    DPL
   \   000002   C083         PUSH    DPH
   \   000004                ; Saved register size: 2
   \   000004                ; Auto size: 0
   1948            nwkStatus = (byte)Status;
   \   000004   E9           MOV     A,R1
   \   000005   90....       MOV     DPTR,#nwkStatus
   \   000008   F0           MOVX    @DPTR,A
   1949          
   1950            if ( Status == ZSUCCESS )
   \   000009   700A         JNZ     ??ZDO_JoinConfirmCB_0
   1951            {
   1952              // LED on shows device joined
   1953              HalLedSet ( HAL_LED_3, HAL_LED_MODE_ON );
   \   00000B                ; Setup parameters for call to function HalLedSet
   \   00000B   12....       LCALL   ?Subroutine12 & 0xFFFF
   1954              // LED off forgets HOLD_AUTO_START
   1955              HalLedSet ( HAL_LED_4, HAL_LED_MODE_OFF);
   1956              if ( (devState == DEV_HOLD) )
   \                     ??CrossCallReturnLabel_37:
   \   00000E   700C         JNZ     ??ZDO_JoinConfirmCB_1
   1957              {
   1958                // Began with HOLD_AUTO_START
   1959                devState = DEV_NWK_JOINING;
   \   000010   7403         MOV     A,#0x3
   \   000012   F0           MOVX    @DPTR,A
   \   000013   8007         SJMP    ??ZDO_JoinConfirmCB_1
   1960              }
   1961          #if !  ( SECURE != 0  )
   1962              // Notify to save info into NV
   1963              ZDApp_NVUpdate();
   1964          #endif
   1965            }
   1966          #if defined(BLINK_LEDS)
   1967            else
   1968              HalLedSet ( HAL_LED_3, HAL_LED_MODE_FLASH );  // Flash LED to show failure
   \                     ??ZDO_JoinConfirmCB_0:
   \   000015                ; Setup parameters for call to function HalLedSet
   \   000015   7A04         MOV     R2,#0x4
   \   000017   7904         MOV     R1,#0x4
   \   000019   12....       LCALL   ??HalLedSet?relay
   1969          #endif
   1970          
   1971            // Notify ZDApp
   1972            ZDApp_SendMsg( ZDAppTaskID, ZDO_NWK_JOIN_IND, sizeof(osal_event_hdr_t), (byte*)NULL );
   \                     ??ZDO_JoinConfirmCB_1:
   \   00001C                ; Setup parameters for call to function ZDApp_SendMsg
   \   00001C   7C00         MOV     R4,#0x0
   \   00001E   7D00         MOV     R5,#0x0
   \   000020   7B02         MOV     R3,#0x2
   \   000022   7A02         MOV     R2,#0x2
   \   000024   02....       LJMP    ?Subroutine21 & 0xFFFF
   1973          }
   1974          
   1975          /*********************************************************************
   1976           * @fn          ZDO_JoinIndicationCB
   1977           *
   1978           * @brief       This function allows the next higher layer of a
   1979           *              coordinator to be notified of a remote join request.
   1980           *
   1981           * @param       ShortAddress - 16-bit address
   1982           * @param       ExtendedAddress - IEEE (64-bit) address
   1983           * @param       CapabilityInformation - Association Capability Information
   1984           *
   1985           * @return      ZStatus_t
   1986           */
   1987          #if defined(RTR_NWK)

   \                                 In  segment BANKED_CODE, align 1, keep-with-next
   1988          ZStatus_t ZDO_JoinIndicationCB( uint16 ShortAddress, byte *ExtendedAddress,
   \                     ZDO_JoinIndicationCB:
   1989                                                   byte CapabilityInformation )
   1990          {
   \   000000   C082         PUSH    DPL
   \   000002   C083         PUSH    DPH
   \   000004                ; Saved register size: 2
   \   000004                ; Auto size: 0
   1991          #if defined (AUTO_SOFT_START)
   1992              ZDX_PostCoordinatorIEEE(ShortAddress);
   1993          #endif
   1994          
   1995            // Notify to save info into NV
   1996            ZDApp_NVUpdate();
   \   000004                ; Setup parameters for call to function ZDApp_NVUpdate
   \   000004   12....       LCALL   ??ZDApp_NVUpdate?relay
   1997          
   1998          #if   ( SECURE != 0  )
   1999            // send notification to TC of new device..
   2000            if ( _NIB.SecurityLevel )
   \   000007   90....       MOV     DPTR,#(_NIB + 12)
   \   00000A   E0           MOVX    A,@DPTR
   \   00000B   6007         JZ      ??CrossCallReturnLabel_8
   2001              osal_start_timerEx( ZDAppTaskID, ZDO_NEW_DEVICE, 600 );
   \   00000D                ; Setup parameters for call to function osal_start_timerEx
   \   00000D   7C58         MOV     R4,#0x58
   \   00000F   7D02         MOV     R5,#0x2
   \   000011   12....       LCALL   ?Subroutine4 & 0xFFFF
   2002          #endif  // SECURE
   2003          
   2004            return ( ZSuccess );
   \                     ??CrossCallReturnLabel_8:
   \   000014   7900         MOV     R1,#0x0
   \   000016   02....       LJMP    ??Subroutine16_0 & 0xFFFF
   2005          }
   2006          #endif  //RTR_NWK
   2007          
   2008          /*********************************************************************
   2009           * @fn          ZDO_LeaveCnf
   2010           *
   2011           * @brief       This function allows the next higher layer to be
   2012           *              notified of the results of its request for this or
   2013           *              a child device to leave the network.
   2014           *
   2015           * @param       cnf - NLME_LeaveCnf_t
   2016           *
   2017           * @return      none
   2018           */

   \                                 In  segment BANKED_CODE, align 1, keep-with-next
   2019          void ZDO_LeaveCnf( NLME_LeaveCnf_t* cnf )
   \                     ZDO_LeaveCnf:
   2020          {
   \   000000   74F7         MOV     A,#-0x9
   \   000002   12....       LCALL   ?BANKED_ENTER_XDATA
   \   000005                ; Saved register size: 9
   \   000005                ; Auto size: 0
   \   000005   EA           MOV     A,R2
   \   000006   FE           MOV     R6,A
   \   000007   EB           MOV     A,R3
   \   000008   FF           MOV     R7,A
   2021            // Check for this device
   2022            if ( osal_ExtAddrEqual( cnf->extAddr,
   2023                                    NLME_GetExtAddr() ) == TRUE )
   \   000009                ; Setup parameters for call to function osal_ExtAddrEqual
   \   000009                ; Setup parameters for call to function NLME_GetExtAddr
   \   000009   12....       LCALL   ??NLME_GetExtAddr?relay
   \   00000C   EA           MOV     A,R2
   \   00000D   FC           MOV     R4,A
   \   00000E   EB           MOV     A,R3
   \   00000F   FD           MOV     R5,A
   \   000010   EE           MOV     A,R6
   \   000011   2402         ADD     A,#0x2
   \   000013   FA           MOV     R2,A
   \   000014   EF           MOV     A,R7
   \   000015   3400         ADDC    A,#0x0
   \   000017   FB           MOV     R3,A
   \   000018   12....       LCALL   ??osal_ExtAddrEqual?relay
   \   00001B   E9           MOV     A,R1
   \   00001C   6401         XRL     A,#0x1
   \   00001E   7009         JNZ     ??ZDO_LeaveCnf_0
   2024            {
   2025              // Prepare to leave with reset
   2026              ZDApp_LeaveReset( cnf->rejoin );
   \   000020                ; Setup parameters for call to function ZDApp_LeaveReset
   \   000020   12....       LCALL   ?Subroutine11 & 0xFFFF
   \                     ??CrossCallReturnLabel_29:
   \   000023   F9           MOV     R1,A
   \   000024   12....       LCALL   ??ZDApp_LeaveReset?relay
   \   000027   8011         SJMP    ??CrossCallReturnLabel_5
   2027            }
   2028            //------------------------------------------------------------------
   2029            #if defined( RTR_NWK )
   2030            //------------------------------------------------------------------
   2031            else
   2032            {
   2033              // Remove device address(optionally descendents) from data
   2034              ZDApp_LeaveUpdate( cnf->dstAddr,
   2035                                 cnf->extAddr,
   2036                                 cnf->removeChildren );
   \                     ??ZDO_LeaveCnf_0:
   \   000029                ; Setup parameters for call to function NLME_RemoveChild
   \   000029   8E82         MOV     DPL,R6
   \   00002B   8F83         MOV     DPH,R7
   \   00002D   A3           INC     DPTR
   \   00002E   A3           INC     DPTR
   \   00002F   A3           INC     DPTR
   \   000030   A3           INC     DPTR
   \   000031   A3           INC     DPTR
   \   000032   A3           INC     DPTR
   \   000033   A3           INC     DPTR
   \   000034   A3           INC     DPTR
   \   000035   A3           INC     DPTR
   \   000036   A3           INC     DPTR
   \   000037   12....       LCALL   ?Subroutine3 & 0xFFFF
   2037            }
   2038            //------------------------------------------------------------------
   2039            #endif
   2040            //------------------------------------------------------------------
   2041          }
   \                     ??CrossCallReturnLabel_5:
   \   00003A   02....       LJMP    ?Subroutine20 & 0xFFFF
   2042          
   2043          /*********************************************************************
   2044           * @fn          ZDO_LeaveInd
   2045           *
   2046           * @brief       This function allows the next higher layer of a
   2047           *              device to be notified of a remote leave request or
   2048           *              indication.
   2049           *
   2050           * @param       ind - NLME_LeaveInd_t
   2051           *
   2052           * @return      none
   2053           */

   \                                 In  segment BANKED_CODE, align 1, keep-with-next
   2054          void ZDO_LeaveInd( NLME_LeaveInd_t* ind )
   \                     ZDO_LeaveInd:
   2055          {
   \   000000   74F6         MOV     A,#-0xa
   \   000002   12....       LCALL   ?BANKED_ENTER_XDATA
   \   000005                ; Saved register size: 10
   \   000005                ; Auto size: 2
   \   000005   74FE         MOV     A,#-0x2
   \   000007   12....       LCALL   ?ALLOC_XSTACK8
   \   00000A   EA           MOV     A,R2
   \   00000B   FE           MOV     R6,A
   \   00000C   EB           MOV     A,R3
   \   00000D   FF           MOV     R7,A
   2056            uint8 leave;
   2057          
   2058          
   2059            // Parent is requesting the leave - NWK layer filters out illegal
   2060            // requests
   2061            if ( ind->request == TRUE )
   \   00000E   8E82         MOV     DPL,R6
   \   000010   8F83         MOV     DPH,R7
   \   000012   A3           INC     DPTR
   \   000013   A3           INC     DPTR
   \   000014   A3           INC     DPTR
   \   000015   A3           INC     DPTR
   \   000016   A3           INC     DPTR
   \   000017   A3           INC     DPTR
   \   000018   A3           INC     DPTR
   \   000019   A3           INC     DPTR
   \   00001A   A3           INC     DPTR
   \   00001B   A3           INC     DPTR
   \   00001C   E0           MOVX    A,@DPTR
   \   00001D   6401         XRL     A,#0x1
   \   00001F   7020         JNZ     ??ZDO_LeaveInd_0
   2062            {
   2063              // Notify network of leave
   2064              //----------------------------------------------------------------
   2065              #if defined( RTR_NWK )
   2066              //----------------------------------------------------------------
   2067              NLME_LeaveRsp_t rsp;
   2068              rsp.rejoin         = ind->rejoin;
   \   000021   12....       LCALL   ?Subroutine10 & 0xFFFF
   \                     ??CrossCallReturnLabel_23:
   \   000024   C0E0         PUSH    A
   \   000026   7401         MOV     A,#0x1
   \   000028   12....       LCALL   ?XSTACK_DISP0_8
   \   00002B   D0E0         POP     A
   \   00002D   F0           MOVX    @DPTR,A
   2069              rsp.removeChildren = ind->removeChildren;
   \   00002E   12....       LCALL   ?Subroutine11 & 0xFFFF
   \                     ??CrossCallReturnLabel_30:
   \   000031   85..82       MOV     DPL,?XSP + 0
   \   000034   85..83       MOV     DPH,?XSP + 1
   \   000037   F0           MOVX    @DPTR,A
   2070              NLME_LeaveRsp( &rsp );
   \   000038                ; Setup parameters for call to function NLME_LeaveRsp
   \   000038   AA82         MOV     R2,DPL
   \   00003A   AB83         MOV     R3,DPH
   \   00003C   12....       LCALL   ??NLME_LeaveRsp?relay
   \   00003F   8029         SJMP    ??ZDO_LeaveInd_1
   2071              //----------------------------------------------------------------
   2072              #endif
   2073              //----------------------------------------------------------------
   2074          
   2075              // Prepare to leave with reset
   2076              ZDApp_LeaveReset( ind->rejoin );
   2077            }
   2078            else
   2079            {
   2080              leave = FALSE;
   2081          
   2082              // Check if this device needs to leave as a child or descendent
   2083              if ( ind->srcAddr == NLME_GetCoordShortAddr() )
   \                     ??ZDO_LeaveInd_0:
   \   000041                ; Setup parameters for call to function NLME_GetCoordShortAddr
   \   000041   12....       LCALL   ??NLME_GetCoordShortAddr?relay
   \   000044   8A..         MOV     ?V0 + 0,R2
   \   000046   8B..         MOV     ?V0 + 1,R3
   \   000048   A8..         MOV     R0,?V0 + 0
   \   00004A   A9..         MOV     R1,?V0 + 1
   \   00004C   8E82         MOV     DPL,R6
   \   00004E   8F83         MOV     DPH,R7
   \   000050   E0           MOVX    A,@DPTR
   \   000051   68           XRL     A,R0
   \   000052   7003         JNZ     ??ZDO_LeaveInd_2
   \   000054   A3           INC     DPTR
   \   000055   E0           MOVX    A,@DPTR
   \   000056   69           XRL     A,R1
   \                     ??ZDO_LeaveInd_2:
   \   000057   701A         JNZ     ??ZDO_LeaveInd_3
   2084              {
   2085                if ( ( ind->removeChildren == TRUE               ) ||
   2086                     ( ZDO_Config_Node_Descriptor.LogicalType ==
   2087                       NODETYPE_DEVICE                           )    )
   \   000059   12....       LCALL   ?Subroutine11 & 0xFFFF
   \                     ??CrossCallReturnLabel_31:
   \   00005C   6401         XRL     A,#0x1
   \   00005E   600A         JZ      ??ZDO_LeaveInd_1
   \   000060   90....       MOV     DPTR,#ZDO_Config_Node_Descriptor
   \   000063   E0           MOVX    A,@DPTR
   \   000064   5407         ANL     A,#0x7
   \   000066   6402         XRL     A,#0x2
   \   000068   7009         JNZ     ??ZDO_LeaveInd_3
   2088                {
   2089                  leave = TRUE;
   2090                }
   2091              }
   2092              else if ( ind->removeChildren == TRUE )
   2093              {
   2094                // Check NWK address allocation algorithm
   2095                //leave = RTG_ANCESTOR(nwkAddr,thisAddr);
   2096              }
   2097          
   2098              if ( leave == TRUE )
   2099              {
   2100                // Prepare to leave with reset
   2101                ZDApp_LeaveReset( ind->rejoin );
   \                     ??ZDO_LeaveInd_1:
   \   00006A                ; Setup parameters for call to function ZDApp_LeaveReset
   \   00006A   12....       LCALL   ?Subroutine10 & 0xFFFF
   \                     ??CrossCallReturnLabel_24:
   \   00006D   F9           MOV     R1,A
   \   00006E   12....       LCALL   ??ZDApp_LeaveReset?relay
   \   000071   800D         SJMP    ??CrossCallReturnLabel_6
   2102              }
   2103              else
   2104              {
   2105                // Remove device address(optionally descendents) from data
   2106                ZDApp_LeaveUpdate( ind->srcAddr,
   2107                                   ind->extAddr,
   2108                                   ind->removeChildren );
   \                     ??ZDO_LeaveInd_3:
   \   000073                ; Setup parameters for call to function NLME_RemoveChild
   \   000073   EE           MOV     A,R6
   \   000074   240B         ADD     A,#0xb
   \   000076   F582         MOV     DPL,A
   \   000078   EF           MOV     A,R7
   \   000079   3400         ADDC    A,#0x0
   \   00007B   F583         MOV     DPH,A
   \   00007D   12....       LCALL   ?Subroutine3 & 0xFFFF
   2109              }
   2110            }
   2111          }
   \                     ??CrossCallReturnLabel_6:
   \   000080   02....       LJMP    ?Subroutine19 & 0xFFFF
   2112          
   2113          /*********************************************************************
   2114           * @fn          ZDO_SyncIndicationCB
   2115           *
   2116           * @brief       This function allows the next higher layer of a
   2117           *              coordinator to be notified of a loss of synchronization
   2118           *                          with the parent/child device.
   2119           *
   2120           * @param       type: 0 - child; 1 - parent
   2121           *
   2122           *
   2123           * @return      none
   2124           */

   \                                 In  segment BANKED_CODE, align 1, keep-with-next
   2125          void ZDO_SyncIndicationCB( byte type, uint16 shortAddr )
   \                     ZDO_SyncIndicationCB:
   2126          {
   \   000000                ; Saved register size: 0
   \   000000                ; Auto size: 0
   2127          
   2128          #if !defined ( RTR_NWK )
   2129              if ( type == 1 )
   2130              {
   2131                ZDApp_SendMsg( ZDAppTaskID, ZDO_NWK_JOIN_REQ, sizeof(osal_event_hdr_t), NULL );
   2132              }
   2133          #endif
   2134            return;
   \   000000   02....       LJMP    ?BRET
   2135          }
   2136          
   2137          /*********************************************************************
   2138           * @fn          ZDO_PollConfirmCB
   2139           *
   2140           * @brief       This function allows the next higher layer to be
   2141           *              notified of a Poll Confirm.
   2142           *
   2143           * @param       none
   2144           *
   2145           * @return      none
   2146           */

   \                                 In  segment BANKED_CODE, align 1, keep-with-next
   2147          void ZDO_PollConfirmCB( byte status )
   \                     ZDO_PollConfirmCB:
   2148          {
   \   000000                ; Saved register size: 0
   \   000000                ; Auto size: 0
   2149            return;
   \   000000   02....       LJMP    ?BRET
   2150          }
   2151          
   2152          /******************************************************************************
   2153           * @fn          ZDApp_NwkWriteNVRequest (stubs AddrMgrWriteNVRequest)
   2154           *
   2155           * @brief       Stub routine implemented by NHLE. NHLE should call
   2156           *              <AddrMgrWriteNV> when appropriate.
   2157           *
   2158           * @param       none
   2159           *
   2160           * @return      none
   2161           */

   \                                 In  segment BANKED_CODE, align 1, keep-with-next
   2162          void ZDApp_NwkWriteNVRequest( void )
   \                     AddrMgrWriteNVRequest:
   2163          {
   \   000000   74F6         MOV     A,#-0xa
   \   000002   12....       LCALL   ?BANKED_ENTER_XDATA
   \   000005                ; Saved register size: 10
   \   000005                ; Auto size: 0
   2164            if ( !osal_get_timeoutEx( ZDAppTaskID, ZDO_NWK_UPDATE_NV ) )
   \   000005                ; Setup parameters for call to function osal_get_timeoutEx
   \   000005   7A00         MOV     R2,#0x0
   \   000007   7B02         MOV     R3,#0x2
   \   000009   90....       MOV     DPTR,#ZDAppTaskID
   \   00000C   E0           MOVX    A,@DPTR
   \   00000D   F9           MOV     R1,A
   \   00000E   12....       LCALL   ??osal_get_timeoutEx?relay
   \   000011   EA           MOV     A,R2
   \   000012   7001         JNZ     ??AddrMgrWriteNVRequest_0
   \   000014   EB           MOV     A,R3
   \                     ??AddrMgrWriteNVRequest_0:
   \   000015   7003         JNZ     ??AddrMgrWriteNVRequest_1
   2165            {
   2166              // Trigger to save info into NV
   2167              ZDApp_NVUpdate();
   \   000017                ; Setup parameters for call to function ZDApp_NVUpdate
   \   000017   12....       LCALL   ??ZDApp_NVUpdate?relay
   2168            }
   2169          }
   \                     ??AddrMgrWriteNVRequest_1:
   \   00001A   02....       LJMP    ??Subroutine19_1 & 0xFFFF
   2170          
   2171          /*********************************************************************
   2172           * Call Back Functions from Security  - API
   2173           */
   2174          
   2175          #if defined( ZDO_COORDINATOR )
   2176           /*********************************************************************
   2177           * @fn          ZDO_UpdateDeviceIndication
   2178           *
   2179           * @brief       This function notifies the "Trust Center" of a
   2180           *              network when a device joins or leaves the network.
   2181           *
   2182           * @param       extAddr - pointer to 64 bit address of new device
   2183           * @param       status  - 0 if a new device joined securely
   2184           *                      - 1 if a new device joined un-securely
   2185           *                      - 2 if a device left the network
   2186           *
   2187           * @return      true if newly joined device should be allowed to
   2188           *                                              remain on network
   2189           */

   \                                 In  segment BANKED_CODE, align 1, keep-with-next
   2190          ZStatus_t ZDO_UpdateDeviceIndication( byte *extAddr, byte status )
   \                     ZDO_UpdateDeviceIndication:
   2191          {
   \   000000                ; Saved register size: 0
   \   000000                ; Auto size: 0
   2192          
   2193          #if   ( SECURE != 0  )
   2194            // can implement a network access policy based on the
   2195            // IEEE address of newly joining devices...
   2196          #endif  // Trust Center
   2197          
   2198            return ZSuccess;
   \   000000                REQUIRE ?Subroutine17
   \   000000                ; // Fall through to label ?Subroutine17

   \                                 In  segment BANKED_CODE, align 1, keep-with-next
   \                     ?Subroutine17:
   \   000000   7900         MOV     R1,#0x0
   \   000002   02....       LJMP    ?BRET
   2199          }
   2200          #endif // ZDO
   2201          
   2202          /*********************************************************************
   2203           * @fn          ZDApp_InMsgCB
   2204           *
   2205           * @brief       This function is called to pass up any message that is
   2206           *              not yet supported.  This allows for the developer to
   2207           *              support features themselves..
   2208           *
   2209           * @return      none
   2210           */

   \                                 In  segment BANKED_CODE, align 1, keep-with-next
   2211          void ZDApp_InMsgCB( zdoIncomingMsg_t *inMsg )
   \                     ZDApp_InMsgCB:
   2212          {
   \   000000   74F6         MOV     A,#-0xa
   \   000002   12....       LCALL   ?BANKED_ENTER_XDATA
   \   000005                ; Saved register size: 10
   \   000005                ; Auto size: 0
   \   000005   EA           MOV     A,R2
   \   000006   FE           MOV     R6,A
   \   000007   EB           MOV     A,R3
   \   000008   FF           MOV     R7,A
   2213            if ( inMsg->clusterID & ZDO_RESPONSE_BIT )
   \   000009   12....       LCALL   ?Subroutine15 & 0xFFFF
   \                     ??CrossCallReturnLabel_44:
   \   00000C   A3           INC     DPTR
   \   00000D   E0           MOVX    A,@DPTR
   \   00000E   5480         ANL     A,#0x80
   \   000010   F9           MOV     R1,A
   \   000011   E4           CLR     A
   \   000012   7001         JNZ     ??ZDApp_InMsgCB_0
   \   000014   E9           MOV     A,R1
   \                     ??ZDApp_InMsgCB_0:
   \   000015   7048         JNZ     ??ZDApp_InMsgCB_1
   2214            {
   2215              // Handle the response message
   2216            }
   2217            else
   2218            {
   2219              // Handle the request message by sending a generic "not supported".
   2220              // End Device Announce doesn't have a response.
   2221              if ( !(inMsg->wasBroadcast) && inMsg->clusterID != End_Device_annce )
   \   000017   12....       LCALL   ?Subroutine11 & 0xFFFF
   \                     ??CrossCallReturnLabel_32:
   \   00001A   7043         JNZ     ??ZDApp_InMsgCB_1
   \   00001C   12....       LCALL   ?Subroutine10 & 0xFFFF
   \                     ??CrossCallReturnLabel_25:
   \   00001F   6413         XRL     A,#0x13
   \   000021   7002         JNZ     ??ZDApp_InMsgCB_2
   \   000023   A3           INC     DPTR
   \   000024   E0           MOVX    A,@DPTR
   \                     ??ZDApp_InMsgCB_2:
   \   000025   6038         JZ      ??ZDApp_InMsgCB_1
   2222              {
   2223                ZDP_GenericRsp( inMsg->TransSeq, &(inMsg->srcAddr), ZDP_NOT_SUPPORTED, 0,
   2224                                (uint16)(inMsg->clusterID | ZDO_RESPONSE_BIT), inMsg->SecurityUse );
   \   000027                ; Setup parameters for call to function ZDP_GenericRsp
   \   000027   12....       LCALL   ?Subroutine9 & 0xFFFF
   \                     ??CrossCallReturnLabel_21:
   \   00002A   4480         ORL     A,#0x80
   \   00002C   F5..         MOV     ?V0 + 1,A
   \   00002E   78..         MOV     R0,#?V0 + 0
   \   000030   12....       LCALL   ?PUSH_XSTACK_I_TWO
   \   000033   75..00       MOV     ?V0 + 0,#0x0
   \   000036   75..00       MOV     ?V0 + 1,#0x0
   \   000039   78..         MOV     R0,#?V0 + 0
   \   00003B   12....       LCALL   ?PUSH_XSTACK_I_TWO
   \   00003E   EE           MOV     A,R6
   \   00003F   240E         ADD     A,#0xe
   \   000041   12....       LCALL   ??Subroutine11_0 & 0xFFFF
   \                     ??CrossCallReturnLabel_33:
   \   000044   FD           MOV     R5,A
   \   000045   7C84         MOV     R4,#-0x7c
   \   000047   EE           MOV     A,R6
   \   000048   2402         ADD     A,#0x2
   \   00004A   0A           INC     R2
   \   00004B   0A           INC     R2
   \   00004C   EF           MOV     A,R7
   \   00004D   3400         ADDC    A,#0x0
   \   00004F   FB           MOV     R3,A
   \   000050   EE           MOV     A,R6
   \   000051   240F         ADD     A,#0xf
   \   000053   12....       LCALL   ??Subroutine11_0 & 0xFFFF
   \                     ??CrossCallReturnLabel_34:
   \   000056   F9           MOV     R1,A
   \   000057   12....       LCALL   ??ZDP_GenericRsp?relay
   \   00005A   7404         MOV     A,#0x4
   \   00005C   12....       LCALL   ?DEALLOC_XSTACK8
   2225              }
   2226            }
   2227          }
   \                     ??ZDApp_InMsgCB_1:
   \   00005F   02....       LJMP    ??Subroutine19_1 & 0xFFFF
   2228          
   2229          /*********************************************************************
   2230           * @fn      ZDApp_ChangeMatchDescRespPermission()
   2231           *
   2232           * @brief   Changes the Match Descriptor Response permission.
   2233           *
   2234           * @param   endpoint - endpoint to allow responses
   2235           * @param   action - true to allow responses, false to not
   2236           *
   2237           * @return  none
   2238           */

   \                                 In  segment BANKED_CODE, align 1, keep-with-next
   2239          void ZDApp_ChangeMatchDescRespPermission( uint8 endpoint, uint8 action )
   \                     ZDApp_ChangeMatchDescRespPermission:
   2240          {
   \   000000   C082         PUSH    DPL
   \   000002   C083         PUSH    DPH
   \   000004                ; Saved register size: 2
   \   000004                ; Auto size: 0
   2241            // Store the action
   2242            afSetMatch( endpoint, action );
   \   000004                ; Setup parameters for call to function afSetMatch
   \   000004   12....       LCALL   ??afSetMatch?relay
   2243          }
   \   000007   02....       LJMP    ??Subroutine16_0 & 0xFFFF
   2244          
   2245          /*********************************************************************
   2246           * @fn      ZDApp_NetworkInit()
   2247           *
   2248           * @brief   Used to start the network joining process
   2249           *
   2250           * @param   delay - mSec delay to wait before starting
   2251           *
   2252           * @return  none
   2253           */

   \                                 In  segment BANKED_CODE, align 1, keep-with-next
   2254          void ZDApp_NetworkInit( uint16 delay )
   \                     ZDApp_NetworkInit:
   2255          {
   \   000000   C082         PUSH    DPL
   \   000002   C083         PUSH    DPH
   \   000004                ; Saved register size: 2
   \   000004                ; Auto size: 0
   2256            if ( delay )
   \   000004   EA           MOV     A,R2
   \   000005   7001         JNZ     ??ZDApp_NetworkInit_0
   \   000007   EB           MOV     A,R3
   \                     ??ZDApp_NetworkInit_0:
   \   000008   600B         JZ      ??ZDApp_NetworkInit_1
   2257            {
   2258              // Wait awhile before starting the device
   2259              osal_start_timerEx( ZDAppTaskID, ZDO_NETWORK_INIT, delay );
   \   00000A                ; Setup parameters for call to function osal_start_timerEx
   \   00000A   EA           MOV     A,R2
   \   00000B   FC           MOV     R4,A
   \   00000C   EB           MOV     A,R3
   \   00000D   FD           MOV     R5,A
   \   00000E   7A01         MOV     R2,#0x1
   \   000010   12....       LCALL   ??Subroutine4_0 & 0xFFFF
   \                     ??CrossCallReturnLabel_10:
   \   000013   8005         SJMP    ??CrossCallReturnLabel_50
   2260            }
   2261            else
   2262            {
   2263              osal_set_event( ZDAppTaskID, ZDO_NETWORK_INIT );
   \                     ??ZDApp_NetworkInit_1:
   \   000015                ; Setup parameters for call to function osal_set_event
   \   000015   7A01         MOV     R2,#0x1
   \   000017   12....       LCALL   ??Subroutine2_0 & 0xFFFF
   2264            }
   2265          }
   \                     ??CrossCallReturnLabel_50:
   \   00001A   02....       LJMP    ??Subroutine16_0 & 0xFFFF
   2266          
   2267          /*********************************************************************
   2268           * @fn      ZDApp_StartUpFromApp()
   2269           *
   2270           * @brief   Start the device.  This function will only start a device
   2271           *          that is in the Holding state.
   2272           *
   2273           * @param   mode - ZDAPP_STARTUP_COORD - Start up as coordinator only
   2274           *                 ZDAPP_STARTUP_ROUTER - Start up as router only
   2275           *                 ZDAPP_STARTUP_AUTO - Startup in auto, look for coord,
   2276           *                                       if not found, become coord.
   2277           *
   2278           * @return  TRUE if started, FALSE if in the wrong mode
   2279           */

   \                                 In  segment BANKED_CODE, align 1, keep-with-next
   2280          ZStatus_t ZDApp_StartUpFromApp( uint8 mode )
   \                     ZDApp_StartUpFromApp:
   2281          {
   \   000000   C082         PUSH    DPL
   \   000002   C083         PUSH    DPH
   \   000004                ; Saved register size: 2
   \   000004                ; Auto size: 0
   2282            ZStatus_t ret = ZFailure;
   \   000004   7901         MOV     R1,#0x1
   2283          
   2284            if ( devState == DEV_HOLD )
   \   000006   90....       MOV     DPTR,#devState
   \   000009   E0           MOVX    A,@DPTR
   \   00000A   7009         JNZ     ??ZDApp_StartUpFromApp_0
   2285            {
   2286              // Start the device's joining process
   2287              if ( ZDOInitDevice( 0 ) == ZDO_INITDEV_NEW_NETWORK_STATE )
   \   00000C                ; Setup parameters for call to function ZDOInitDevice
   \   00000C   7A00         MOV     R2,#0x0
   \   00000E   7B00         MOV     R3,#0x0
   \   000010   12....       LCALL   ??ZDOInitDevice?relay
   2288              {
   2289          #if defined( SOFT_START )
   2290                if ( mode == ZDAPP_STARTUP_COORD )
   2291                {
   2292                  devStartMode = MODE_HARD;     // Start as a coordinator
   2293                  ZDO_Config_Node_Descriptor.LogicalType = NODETYPE_COORDINATOR;
   2294                }
   2295                else
   2296                {
   2297                  if ( mode == ZDAPP_STARTUP_ROUTER )
   2298                  {
   2299                    softStartAllowCoord = FALSE;  // Don't allow coord to start
   2300                    continueJoining = TRUE;
   2301                  }
   2302                  devStartMode = MODE_JOIN;     // Assume joining
   2303                }
   2304          #endif  // SOFT_START
   2305              }
   2306              ret = ZSuccess;
   \   000013   7900         MOV     R1,#0x0
   2307            }
   2308          
   2309            return ( ret );
   \                     ??ZDApp_StartUpFromApp_0:
   \   000015   02....       LJMP    ??Subroutine16_0 & 0xFFFF
   2310          }
   2311          
   2312          /*********************************************************************
   2313           * @fn      ZDApp_StopStartUp()
   2314           *
   2315           * @brief   Stops the joining process of a router.  This will only
   2316           *          work if the router is in the scanning process and
   2317           *          the SOFT_START feature is enabled.
   2318           *
   2319           * @param   none
   2320           *
   2321           * @return  TRUE if SOFT_START is enabled, FALSE if not possible
   2322           */

   \                                 In  segment BANKED_CODE, align 1, keep-with-next
   2323          uint8 ZDApp_StopStartUp( void )
   \                     ZDApp_StopStartUp:
   2324          {
   \   000000                ; Saved register size: 0
   \   000000                ; Auto size: 0
   2325            uint8 ret = FALSE;
   2326          
   2327          #if defined( SOFT_START )
   2328            continueJoining = FALSE;
   2329            ret = TRUE;
   2330          #endif  // SOFT_START
   2331          
   2332            return ( ret );
   \   000000   02....       LJMP    ?Subroutine17 & 0xFFFF
   2333          }
   2334          
   2335          /*********************************************************************
   2336           * @fn      ZDApp_StartJoiningCycle()
   2337           *
   2338           * @brief   Starts the joining cycle of a device.  This will only
   2339           *          continue an already started (or stopped) joining cycle.
   2340           *
   2341           * @param   none
   2342           *
   2343           * @return  TRUE if joining stopped, FALSE if joining or rejoining
   2344           */

   \                                 In  segment BANKED_CODE, align 1, keep-with-next
   2345          uint8 ZDApp_StartJoiningCycle( void )
   \                     ZDApp_StartJoiningCycle:
   2346          {
   \   000000   C082         PUSH    DPL
   \   000002   C083         PUSH    DPH
   \   000004                ; Saved register size: 2
   \   000004                ; Auto size: 0
   2347            if ( devState == DEV_INIT || devState == DEV_NWK_DISC )
   \   000004   90....       MOV     DPTR,#devState
   \   000007   E0           MOVX    A,@DPTR
   \   000008   6401         XRL     A,#0x1
   \   00000A   6005         JZ      ??ZDApp_StartJoiningCycle_0
   \   00000C   E0           MOVX    A,@DPTR
   \   00000D   6402         XRL     A,#0x2
   \   00000F   7011         JNZ     ??ZDApp_StartJoiningCycle_1
   2348            {
   2349              continueJoining = TRUE;
   \                     ??ZDApp_StartJoiningCycle_0:
   \   000011   7401         MOV     A,#0x1
   \   000013   90....       MOV     DPTR,#continueJoining
   \   000016   F0           MOVX    @DPTR,A
   2350              ZDApp_NetworkInit( 0 );
   \   000017                ; Setup parameters for call to function ZDApp_NetworkInit
   \   000017   7A00         MOV     R2,#0x0
   \   000019   7B00         MOV     R3,#0x0
   \   00001B   12....       LCALL   ??ZDApp_NetworkInit?relay
   2351          
   2352              return ( TRUE );
   \   00001E   7901         MOV     R1,#0x1
   \   000020   8002         SJMP    ??ZDApp_StartJoiningCycle_2
   2353            }
   2354            else
   2355              return ( FALSE );
   \                     ??ZDApp_StartJoiningCycle_1:
   \   000022   7900         MOV     R1,#0x0
   \                     ??ZDApp_StartJoiningCycle_2:
   \   000024   02....       LJMP    ??Subroutine16_0 & 0xFFFF
   2356          }
   2357          
   2358          /*********************************************************************
   2359           * @fn      ZDApp_StopJoiningCycle()
   2360           *
   2361           * @brief   Stops the joining or rejoining process of a device.
   2362           *
   2363           * @param   none
   2364           *
   2365           * @return  TRUE if joining stopped, FALSE if joining or rejoining
   2366           */

   \                                 In  segment BANKED_CODE, align 1, keep-with-next
   2367          uint8 ZDApp_StopJoiningCycle( void )
   \                     ZDApp_StopJoiningCycle:
   2368          {
   \   000000   C082         PUSH    DPL
   \   000002   C083         PUSH    DPH
   \   000004                ; Saved register size: 2
   \   000004                ; Auto size: 0
   2369            if ( devState == DEV_INIT || devState == DEV_NWK_DISC )
   \   000004   90....       MOV     DPTR,#devState
   \   000007   E0           MOVX    A,@DPTR
   \   000008   6401         XRL     A,#0x1
   \   00000A   6005         JZ      ??ZDApp_StopJoiningCycle_0
   \   00000C   E0           MOVX    A,@DPTR
   \   00000D   6402         XRL     A,#0x2
   \   00000F   7009         JNZ     ??ZDApp_StopJoiningCycle_1
   2370            {
   2371              continueJoining = FALSE;
   \                     ??ZDApp_StopJoiningCycle_0:
   \   000011   E4           CLR     A
   \   000012   90....       MOV     DPTR,#continueJoining
   \   000015   F0           MOVX    @DPTR,A
   2372              return ( TRUE );
   \   000016   7901         MOV     R1,#0x1
   \   000018   8002         SJMP    ??ZDApp_StopJoiningCycle_2
   2373            }
   2374            else
   2375              return ( FALSE );
   \                     ??ZDApp_StopJoiningCycle_1:
   \   00001A   7900         MOV     R1,#0x0
   \                     ??ZDApp_StopJoiningCycle_2:
   \   00001C   02....       LJMP    ??Subroutine16_0 & 0xFFFF
   2376          }
   2377          
   2378          #if !defined ( ZDO_COORDINATOR ) || defined ( SOFT_START )
   2379          /*********************************************************************
   2380           * @fn      ZDApp_NodeProfileSync()
   2381           *
   2382           * @brief   Sync node with stack profile.
   2383           *
   2384           * @param   cfm - ZDO_NetworkDiscoveryCfm_t
   2385           *
   2386           * @return  none
   2387           */
   2388          void ZDApp_NodeProfileSync( ZDO_NetworkDiscoveryCfm_t* cfm )
   2389          {
   2390            networkDesc_t* desc;
   2391            uint16         panID;
   2392          
   2393            if ( ZDO_Config_Node_Descriptor.CapabilityFlags & CAPINFO_DEVICETYPE_FFD  )
   2394            {
   2395              panID = BUILD_UINT16( cfm->panIdLSB, cfm->panIdMSB );
   2396          
   2397              desc = nwk_getNetworkDesc( cfm->extendedPANID, panID, cfm->logicalChannel );
   2398          
   2399              if (desc != NULL)
   2400              {
   2401                if ( desc->stackProfile != zgStackProfile )
   2402                {
   2403                  ZDO_Config_Node_Descriptor.LogicalType = NODETYPE_DEVICE;
   2404                  ZDO_Config_Node_Descriptor.CapabilityFlags = CAPINFO_DEVICETYPE_RFD | CAPINFO_POWER_AC | CAPINFO_RCVR_ON_IDLE;
   2405                }
   2406              }
   2407            }
   2408          }
   2409          #endif
   2410          
   2411          /*********************************************************************
   2412           * @fn      ZDApp_CoordStartPANIDConflictCB()
   2413           *
   2414           * @brief   Returns a PAN ID for the network layer to use during
   2415           *          a coordinator start and there is another network with
   2416           *          the intended PANID.
   2417           *
   2418           * @param   panid - the intended PAN ID
   2419           *
   2420           * @return  PANID to try
   2421           */

   \                                 In  segment BANKED_CODE, align 1, keep-with-next
   2422          uint16 ZDApp_CoordStartPANIDConflictCB( uint16 panid )
   \                     ZDApp_CoordStartPANIDConflictCB:
   2423          {
   \   000000                ; Saved register size: 0
   \   000000                ; Auto size: 0
   2424            return ( (panid + 1) & 0x3FFF );
   \   000000   7401         MOV     A,#0x1
   \   000002   2A           ADD     A,R2
   \   000003   E4           CLR     A
   \   000004   3B           ADDC    A,R3
   \   000005   F9           MOV     R1,A
   \   000006   0A           INC     R2
   \   000007   743F         MOV     A,#0x3f
   \   000009   59           ANL     A,R1
   \   00000A   FB           MOV     R3,A
   \   00000B   02....       LJMP    ?BRET
   2425          }
   2426          
   2427          
   2428          /*********************************************************************
   2429           * @fn          ZDApp_NVUpdate
   2430           *
   2431           * @brief       Set the NV Update Timer.
   2432           *
   2433           * @param       none
   2434           *
   2435           * @return      none
   2436           */

   \                                 In  segment BANKED_CODE, align 1, keep-with-next
   2437          void ZDApp_NVUpdate( void )
   \                     ZDApp_NVUpdate:
   2438          {
   \   000000   C082         PUSH    DPL
   \   000002   C083         PUSH    DPH
   \   000004                ; Saved register size: 2
   \   000004                ; Auto size: 0
   2439            osal_start_timerEx( ZDAppTaskID, ZDO_NWK_UPDATE_NV, ZDAPP_UPDATE_NWK_NV_TIME );
   \   000004                ; Setup parameters for call to function osal_start_timerEx
   \   000004   7CBC         MOV     R4,#-0x44
   \   000006   7D02         MOV     R5,#0x2
   \   000008   7A00         MOV     R2,#0x0
   \   00000A   7B02         MOV     R3,#0x2
   \   00000C   12....       LCALL   ??Subroutine4_1 & 0xFFFF
   2440          }
   \                     ??CrossCallReturnLabel_11:
   \   00000F   02....       LJMP    ??Subroutine16_0 & 0xFFFF

   \                                 In  segment XDATA_I, align 1, keep-with-next
   \                     __Constant_0:
   \   000000                DS 4
   \   000004                REQUIRE `?<Initializer for __Constant_0>`
   \   000004                REQUIRE __INIT_XDATA_I

   \                                 In  segment XDATA_I, align 1, keep-with-next
   \                     __Constant_1:
   \   000000                DS 4
   \   000004                REQUIRE `?<Initializer for __Constant_1>`
   \   000004                REQUIRE __INIT_XDATA_I

   \                                 In  segment XDATA_I, align 1, keep-with-next
   \                     __Constant_3e8:
   \   000000                DS 4
   \   000004                REQUIRE `?<Initializer for __Constant_3e8>`
   \   000004                REQUIRE __INIT_XDATA_I

   \                                 In  segment BANKED_CODE, align 1, keep-with-next
   \                     ?Subroutine3:
   \   000000   E0           MOVX    A,@DPTR
   \   000001   F9           MOV     R1,A
   \   000002   EE           MOV     A,R6
   \   000003   2402         ADD     A,#0x2
   \   000005   FA           MOV     R2,A
   \   000006   EF           MOV     A,R7
   \   000007   3400         ADDC    A,#0x0
   \   000009   FB           MOV     R3,A
   \   00000A   12....       LCALL   ??NLME_RemoveChild?relay
   \   00000D   22           RET

   \                                 In  segment XDATA_ID, align 1, keep-with-next
   \                     `?<Initializer for zdoDiscCounter>`:
   \   000000   01           DB 1

   \                                 In  segment XDATA_ID, align 1, keep-with-next
   \                     `?<Initializer for continueJoining>`:
   \   000000   01           DB 1

   \                                 In  segment XDATA_ID, align 1, keep-with-next
   \                     `?<Initializer for devState>`:
   \   000000   01           DB 1

   \                                 In  segment XDATA_ID, align 1, keep-with-next
   \                     `?<Initializer for devStartMode>`:
   \   000000   02           DB 2

   \                                 In  segment XDATA_ID, align 1, keep-with-next
   \                     `?<Initializer for ZDApp_epDesc>`:
   \   000000   00           DB 0
   \   000001   ....0000     DW ZDAppTaskID, 0H
   \   000005   00           DB 0

   \                                 In  segment XDATA_ID, align 1, keep-with-next
   \                     `?<Initializer for __Constant_0>`:
   \   000000   00000000     DD 0

   \                                 In  segment XDATA_ID, align 1, keep-with-next
   \                     `?<Initializer for __Constant_1>`:
   \   000000   01000000     DD 1

   \                                 In  segment XDATA_ID, align 1, keep-with-next
   \                     `?<Initializer for __Constant_3e8>`:
   \   000000   E8030000     DD 1000

   \                                 In  segment BANK_RELAYS, align 1
   \                     ??ZDApp_Init?relay:
   \   000000   12....       LCALL   ?BDISPATCH
   \   000003   ......       DC24    ZDApp_Init

   \                                 In  segment BANK_RELAYS, align 1
   \                     ??ZDApp_SecInit?relay:
   \   000000   12....       LCALL   ?BDISPATCH
   \   000003   ......       DC24    ZDApp_SecInit

   \                                 In  segment BANK_RELAYS, align 1
   \                     ??ZDApp_event_loop?relay:
   \   000000   12....       LCALL   ?BDISPATCH
   \   000003   ......       DC24    ZDApp_event_loop

   \                                 In  segment BANK_RELAYS, align 1
   \                     ??ZDOInitDevice?relay:
   \   000000   12....       LCALL   ?BDISPATCH
   \   000003   ......       DC24    ZDOInitDevice

   \                                 In  segment BANK_RELAYS, align 1
   \                     ??ZDApp_ReadNetworkRestoreState?relay:
   \   000000   12....       LCALL   ?BDISPATCH
   \   000003   ......       DC24    ZDApp_ReadNetworkRestoreState

   \                                 In  segment BANK_RELAYS, align 1
   \                     ??ZDAppDetermineDeviceType?relay:
   \   000000   12....       LCALL   ?BDISPATCH
   \   000003   ......       DC24    ZDAppDetermineDeviceType

   \                                 In  segment BANK_RELAYS, align 1
   \                     ??ZDApp_NetworkStartEvt?relay:
   \   000000   12....       LCALL   ?BDISPATCH
   \   000003   ......       DC24    ZDApp_NetworkStartEvt

   \                                 In  segment BANK_RELAYS, align 1
   \                     ??ZDApp_DeviceAuthEvt?relay:
   \   000000   12....       LCALL   ?BDISPATCH
   \   000003   ......       DC24    ZDApp_DeviceAuthEvt

   \                                 In  segment BANK_RELAYS, align 1
   \                     ??ZDApp_SaveNetworkStateEvt?relay:
   \   000000   12....       LCALL   ?BDISPATCH
   \   000003   ......       DC24    ZDApp_SaveNetworkStateEvt

   \                                 In  segment BANK_RELAYS, align 1
   \                     ??ZDApp_RestoreNetworkState?relay:
   \   000000   12....       LCALL   ?BDISPATCH
   \   000003   ......       DC24    ZDApp_RestoreNetworkState

   \                                 In  segment BANK_RELAYS, align 1
   \                     ??ZDApp_InitUserDesc?relay:
   \   000000   12....       LCALL   ?BDISPATCH
   \   000003   ......       DC24    ZDApp_InitUserDesc

   \                                 In  segment BANK_RELAYS, align 1
   \                     ??ZDAppCheckForHoldKey?relay:
   \   000000   12....       LCALL   ?BDISPATCH
   \   000003   ......       DC24    ZDAppCheckForHoldKey

   \                                 In  segment BANK_RELAYS, align 1
   \                     ??ZDApp_ProcessOSALMsg?relay:
   \   000000   12....       LCALL   ?BDISPATCH
   \   000003   ......       DC24    ZDApp_ProcessOSALMsg

   \                                 In  segment BANK_RELAYS, align 1
   \                     ??ZDApp_ProcessMsgCBs?relay:
   \   000000   12....       LCALL   ?BDISPATCH
   \   000003   ......       DC24    ZDApp_ProcessMsgCBs

   \                                 In  segment BANK_RELAYS, align 1
   \                     ??ZDApp_RegisterCBs?relay:
   \   000000   12....       LCALL   ?BDISPATCH
   \   000003   ......       DC24    ZDApp_RegisterCBs

   \                                 In  segment BANK_RELAYS, align 1
   \                     ??ZDApp_SaveNwkKey?relay:
   \   000000   12....       LCALL   ?BDISPATCH
   \   000003   ......       DC24    ZDApp_SaveNwkKey

   \                                 In  segment BANK_RELAYS, align 1
   \                     ??ZDApp_ResetNwkKey?relay:
   \   000000   12....       LCALL   ?BDISPATCH
   \   000003   ......       DC24    ZDApp_ResetNwkKey

   \                                 In  segment BANK_RELAYS, align 1
   \                     ??ZDApp_RestoreNwkKey?relay:
   \   000000   12....       LCALL   ?BDISPATCH
   \   000003   ......       DC24    ZDApp_RestoreNwkKey

   \                                 In  segment BANK_RELAYS, align 1
   \                     ??ZDApp_ResetTimerStart?relay:
   \   000000   12....       LCALL   ?BDISPATCH
   \   000003   ......       DC24    ZDApp_ResetTimerStart

   \                                 In  segment BANK_RELAYS, align 1
   \                     ??ZDApp_ResetTimerCancel?relay:
   \   000000   12....       LCALL   ?BDISPATCH
   \   000003   ......       DC24    ZDApp_ResetTimerCancel

   \                                 In  segment BANK_RELAYS, align 1
   \                     ??ZDApp_LeaveCtrlInit?relay:
   \   000000   12....       LCALL   ?BDISPATCH
   \   000003   ......       DC24    ZDApp_LeaveCtrlInit

   \                                 In  segment BANK_RELAYS, align 1
   \                     ??ZDApp_LeaveCtrlSet?relay:
   \   000000   12....       LCALL   ?BDISPATCH
   \   000003   ......       DC24    ZDApp_LeaveCtrlSet

   \                                 In  segment BANK_RELAYS, align 1
   \                     ??ZDApp_LeaveCtrlBypass?relay:
   \   000000   12....       LCALL   ?BDISPATCH
   \   000003   ......       DC24    ZDApp_LeaveCtrlBypass

   \                                 In  segment BANK_RELAYS, align 1
   \                     ??ZDApp_LeaveCtrlStartup?relay:
   \   000000   12....       LCALL   ?BDISPATCH
   \   000003   ......       DC24    ZDApp_LeaveCtrlStartup

   \                                 In  segment BANK_RELAYS, align 1
   \                     ??ZDApp_LeaveReset?relay:
   \   000000   12....       LCALL   ?BDISPATCH
   \   000003   ......       DC24    ZDApp_LeaveReset

   \                                 In  segment BANK_RELAYS, align 1
   \                     ??ZDApp_LeaveUpdate?relay:
   \   000000   12....       LCALL   ?BDISPATCH
   \   000003   ......       DC24    ZDApp_LeaveUpdate

   \                                 In  segment BANK_RELAYS, align 1
   \                     ??ZDApp_SendEventMsg?relay:
   \   000000   12....       LCALL   ?BDISPATCH
   \   000003   ......       DC24    ZDApp_SendEventMsg

   \                                 In  segment BANK_RELAYS, align 1
   \                     ??ZDApp_SendMsg?relay:
   \   000000   12....       LCALL   ?BDISPATCH
   \   000003   ......       DC24    ZDApp_SendMsg

   \                                 In  segment BANK_RELAYS, align 1
   \                     ??ZDO_NetworkDiscoveryConfirmCB?relay:
   \   000000   12....       LCALL   ?BDISPATCH
   \   000003   ......       DC24    ZDO_NetworkDiscoveryConfirmCB

   \                                 In  segment BANK_RELAYS, align 1
   \                     ??ZDO_NetworkFormationConfirmCB?relay:
   \   000000   12....       LCALL   ?BDISPATCH
   \   000003   ......       DC24    ZDO_NetworkFormationConfirmCB

   \                                 In  segment BANK_RELAYS, align 1
   \                     ??ZDO_StartRouterConfirmCB?relay:
   \   000000   12....       LCALL   ?BDISPATCH
   \   000003   ......       DC24    ZDO_StartRouterConfirmCB

   \                                 In  segment BANK_RELAYS, align 1
   \                     ??ZDO_JoinConfirmCB?relay:
   \   000000   12....       LCALL   ?BDISPATCH
   \   000003   ......       DC24    ZDO_JoinConfirmCB

   \                                 In  segment BANK_RELAYS, align 1
   \                     ??ZDO_JoinIndicationCB?relay:
   \   000000   12....       LCALL   ?BDISPATCH
   \   000003   ......       DC24    ZDO_JoinIndicationCB

   \                                 In  segment BANK_RELAYS, align 1
   \                     ??ZDO_LeaveCnf?relay:
   \   000000   12....       LCALL   ?BDISPATCH
   \   000003   ......       DC24    ZDO_LeaveCnf

   \                                 In  segment BANK_RELAYS, align 1
   \                     ??ZDO_LeaveInd?relay:
   \   000000   12....       LCALL   ?BDISPATCH
   \   000003   ......       DC24    ZDO_LeaveInd

   \                                 In  segment BANK_RELAYS, align 1
   \                     ??ZDO_SyncIndicationCB?relay:
   \   000000   12....       LCALL   ?BDISPATCH
   \   000003   ......       DC24    ZDO_SyncIndicationCB

   \                                 In  segment BANK_RELAYS, align 1
   \                     ??ZDO_PollConfirmCB?relay:
   \   000000   12....       LCALL   ?BDISPATCH
   \   000003   ......       DC24    ZDO_PollConfirmCB

   \                                 In  segment BANK_RELAYS, align 1
   \                     ??AddrMgrWriteNVRequest?relay:
   \   000000   12....       LCALL   ?BDISPATCH
   \   000003   ......       DC24    AddrMgrWriteNVRequest

   \                                 In  segment BANK_RELAYS, align 1
   \                     ??ZDO_UpdateDeviceIndication?relay:
   \   000000   12....       LCALL   ?BDISPATCH
   \   000003   ......       DC24    ZDO_UpdateDeviceIndication

   \                                 In  segment BANK_RELAYS, align 1
   \                     ??ZDApp_InMsgCB?relay:
   \   000000   12....       LCALL   ?BDISPATCH
   \   000003   ......       DC24    ZDApp_InMsgCB

   \                                 In  segment BANK_RELAYS, align 1
   \                     ??ZDApp_ChangeMatchDescRespPermission?relay:
   \   000000   12....       LCALL   ?BDISPATCH
   \   000003   ......       DC24    ZDApp_ChangeMatchDescRespPermission

   \                                 In  segment BANK_RELAYS, align 1
   \                     ??ZDApp_NetworkInit?relay:
   \   000000   12....       LCALL   ?BDISPATCH
   \   000003   ......       DC24    ZDApp_NetworkInit

   \                                 In  segment BANK_RELAYS, align 1
   \                     ??ZDApp_StartUpFromApp?relay:
   \   000000   12....       LCALL   ?BDISPATCH
   \   000003   ......       DC24    ZDApp_StartUpFromApp

   \                                 In  segment BANK_RELAYS, align 1
   \                     ??ZDApp_StopStartUp?relay:
   \   000000   12....       LCALL   ?BDISPATCH
   \   000003   ......       DC24    ZDApp_StopStartUp

   \                                 In  segment BANK_RELAYS, align 1
   \                     ??ZDApp_StartJoiningCycle?relay:
   \   000000   12....       LCALL   ?BDISPATCH
   \   000003   ......       DC24    ZDApp_StartJoiningCycle

   \                                 In  segment BANK_RELAYS, align 1
   \                     ??ZDApp_StopJoiningCycle?relay:
   \   000000   12....       LCALL   ?BDISPATCH
   \   000003   ......       DC24    ZDApp_StopJoiningCycle

   \                                 In  segment BANK_RELAYS, align 1
   \                     ??ZDApp_CoordStartPANIDConflictCB?relay:
   \   000000   12....       LCALL   ?BDISPATCH
   \   000003   ......       DC24    ZDApp_CoordStartPANIDConflictCB

   \                                 In  segment BANK_RELAYS, align 1
   \                     ??ZDApp_NVUpdate?relay:
   \   000000   12....       LCALL   ?BDISPATCH
   \   000003   ......       DC24    ZDApp_NVUpdate
   2441          
   2442          
   2443          /*********************************************************************
   2444          *********************************************************************/

   Maximum stack usage in bytes:

     Function                       ISTACK PSTACK XSTACK
     --------                       ------ ------ ------
     AddrMgrWriteNVRequest              0      0     10
       -> osal_get_timeoutEx            0      0     20
       -> ZDApp_NVUpdate                0      0     20
     ZDAppCheckForHoldKey               2      0      1
       -> HalKeyRead                    4      0      0
     ZDAppDetermineDeviceType           0      0      0
     ZDApp_ChangeMatchDescRespPermission
                                        2      0      0
       -> afSetMatch                    4      0      0
     ZDApp_CoordStartPANIDConflictCB
                                        0      0      0
     ZDApp_DeviceAuthEvt                2      0     10
       -> ZDApp_ResetTimerCancel        4      0      0
       -> osal_set_event                4      0      0
       -> NLME_StartRouterRequest       4      0      0
       -> ZDApp_NVUpdate                4      0      0
       -> ZDApp_SaveNwkKey              4      0      0
       -> ZDApp_NVUpdate                4      0      0
     ZDApp_InMsgCB                      0      0     14
       -> ZDP_GenericRsp                0      0     28
     ZDApp_Init                         2      0      1
       -> NLME_GetExtAddr               4      0      2
       -> ZDAppCheckForHoldKey          4      0      2
       -> ZDO_Init                      4      0      2
       -> afRegister                    4      0      2
       -> NLME_GetRequest               4      0      2
       -> NLME_SetBroadcastFilter       4      0      2
       -> ZDOInitDevice                 4      0      2
       -> HalLedBlink                   4      0      2
       -> ZDApp_RegisterCBs             4      0      2
     ZDApp_InitUserDesc                 0      0     31
       -> osal_memset                   0      0     54
       -> osal_nv_item_init             0      0     58
       -> osal_nv_read                  0      0     62
     ZDApp_LeaveCtrlBypass              2      0      0
     ZDApp_LeaveCtrlInit                0      0     26
       -> osal_nv_item_init             0      0     24
       -> osal_nv_read                  0      0     28
     ZDApp_LeaveCtrlSet                 0      0     14
       -> osal_nv_write                 0      0     28
     ZDApp_LeaveCtrlStartup             1      0     26
       -> osal_nv_write                 0      0     28
     ZDApp_LeaveReset                   2      0     12
       -> ZDApp_LeaveCtrlSet            4      0      0
       -> ZDApp_ResetTimerStart         4      0      0
     ZDApp_LeaveUpdate                  2      0      0
       -> NLME_RemoveChild              4      0      0
     ZDApp_NVUpdate                     2      0     10
       -> osal_start_timerEx            4      0      0
     ZDApp_NetworkInit                  2      0     12
       -> osal_start_timerEx            4      0      0
       -> osal_set_event                4      0      0
     ZDApp_NetworkStartEvt              2      0     10
       -> osal_pwrmgr_device            4      0      0
       -> osal_set_event                4      0      0
       -> NLME_GetEnergyThreshold       4      0      0
       -> NLME_GetEnergyThreshold       4      0      0
       -> NLME_SetEnergyThreshold       4      0      0
       -> osal_set_event                4      0      0
       -> osal_set_event                4      0      0
     ZDApp_ProcessMsgCBs                0      0     33
       -> ZDMatchSendState              0      0     66
       -> ZDO_ParseEndDeviceBindReq     0      0     66
       -> ZDO_MatchEndDeviceBind        0      0     66
       -> osal_mem_free                 0      0     66
       -> osal_mem_free                 0      0     66
     ZDApp_ProcessOSALMsg               2      0     10
       -> ZDP_IncomingData              4      0      0
       -> ZDApp_ProcessMsgCBs           4      0      0
       -> ZDSecMgrUpdateDeviceInd       4      0      0
     ZDApp_ReadNetworkRestoreState      0      0      9
       -> zgReadStartupOptions          0      0     18
     ZDApp_RegisterCBs                  2      0      1
       -> ZDO_RegisterForZDOMsg         4      0      0
       -> ZDO_RegisterForZDOMsg         4      0      0
       -> ZDO_RegisterForZDOMsg         4      0      0
     ZDApp_ResetNwkKey                  0      0     35
       -> osal_memset                   0      0     62
       -> osal_nv_write                 0      0     70
     ZDApp_ResetTimerCancel             2      0      0
       -> osal_stop_timerEx             4      0      0
     ZDApp_ResetTimerStart              2      0      0
       -> osal_start_timerEx            4      0      0
     ZDApp_RestoreNetworkState          0      0     33
       -> NLME_InitNV                   0      0     62
       -> NLME_RestoreFromNV            0      0     62
       -> NLME_GetShortAddr             0      0     62
       -> osal_memset                   0      0     62
       -> osal_nv_item_init             0      0     66
       -> ZDApp_RestoreNwkKey           0      0     62
     ZDApp_RestoreNwkKey                2      0     68
       -> osal_nv_read                  0      0     74
     ZDApp_SaveNetworkStateEvt          0      0      0
     ZDApp_SaveNwkKey                   0      0     47
       -> SSP_ReadNwkActiveKey          0      0     66
       -> osal_nv_write                 0      0     74
     ZDApp_SecInit                      0      0     24
       -> ZDSecMgrInit                  0      0     24
       -> SSP_UpdateNwkKey              0      0     24
       -> SSP_SwitchNwkKey              0      0     24
     ZDApp_SendEventMsg                 2      0      0
       -> ZDApp_SendMsg                 4      0      0
     ZDApp_SendMsg                      1      0     43
       -> osal_msg_allocate             0      0     32
       -> osal_memcpy                   0      0     38
       -> osal_msg_send                 0      0     32
     ZDApp_StartJoiningCycle            2      0      0
       -> ZDApp_NetworkInit             4      0      0
     ZDApp_StartUpFromApp               2      0      0
       -> ZDOInitDevice                 4      0      0
     ZDApp_StopJoiningCycle             2      0      0
     ZDApp_StopStartUp                  0      0      0
     ZDApp_event_loop                   0      0     10
       -> ZDO_UpdateNwkStatus           0      0     20
       -> ZDApp_ProcessOSALMsg          0      0     20
       -> osal_msg_deallocate           0      0     20
       -> osal_msg_receive              0      0     20
       -> ZDO_StartDevice               0      0     20
       -> ZDApp_NetworkStartEvt         0      0     20
       -> osal_pwrmgr_device            0      0     20
       -> osal_set_event                0      0     20
       -> ZDSecMgrNewDeviceEvent        0      0     20
       -> osal_start_timerEx            0      0     20
       -> ZDApp_DeviceAuthEvt           0      0     20
       -> ZDApp_SaveNwkKey              0      0     20
     ZDOInitDevice                      0      0     13
       -> ZDApp_LeaveCtrlInit           0      0     24
       -> ZDApp_LeaveCtrlStartup        0      0     24
       -> osal_rand                     0      0     24
       -> ZDApp_SecInit                 0      0     24
       -> ZDApp_NetworkInit             0      0     24
     ZDO_JoinConfirmCB                  2      0      0
       -> HalLedSet                     4      0      0
       -> HalLedSet                     4      0      0
       -> HalLedSet                     4      0      0
       -> ZDApp_SendMsg                 4      0      0
     ZDO_JoinIndicationCB               2      0      0
       -> ZDApp_NVUpdate                4      0      0
       -> osal_start_timerEx            4      0      0
     ZDO_LeaveCnf                       0      0      9
       -> NLME_GetExtAddr               0      0     18
       -> osal_ExtAddrEqual             0      0     18
       -> ZDApp_LeaveReset              0      0     18
       -> NLME_RemoveChild              0      0     18
     ZDO_LeaveInd                       1      0     12
       -> NLME_LeaveRsp                 0      0     24
       -> NLME_GetCoordShortAddr        0      0     24
       -> ZDApp_LeaveReset              0      0     24
       -> NLME_RemoveChild              0      0     24
     ZDO_NetworkDiscoveryConfirmCB      2      0     24
       -> osal_cpyExtAddr               0      0     48
       -> ZDApp_SendMsg                 0      0     48
     ZDO_NetworkFormationConfirmCB      2      0      0
       -> HalLedSet                     4      0      0
       -> HalLedSet                     4      0      0
       -> HalLedSet                     4      0      0
       -> osal_set_event                4      0      0
     ZDO_PollConfirmCB                  0      0      0
     ZDO_StartRouterConfirmCB           2      0      0
       -> HalLedSet                     4      0      0
       -> HalLedSet                     4      0      0
       -> HalLedSet                     4      0      0
       -> osal_set_event                4      0      0
     ZDO_SyncIndicationCB               0      0      0
     ZDO_UpdateDeviceIndication         0      0      0


   Segment part sizes:

     Function/Label                 Bytes
     --------------                 -----
     _A_IEN0                           1
     WDCTL                             1
     zdoDiscCounter                    1
     ZDAppNwkAddr                      9
     nwkFrameCounterChanges            2
     continueJoining                   1
     _tmpRejoinState                   1
     ZDAppTaskID                       1
     nwkStatus                         1
     ZDApp_AutoFindMode_epDesc         2
     ZDApp_LeaveCtrl                   1
     devState                          1
     devStartMode                      1
     ZDApp_epDesc                      6
     ZDApp_Init                      115
     ?Subroutine16                    10
     ZDApp_SecInit                    47
     ?Subroutine18                    10
     ZDApp_event_loop                293
     ?Subroutine19                    10
     ?Subroutine4                     13
     ?Subroutine2                     13
     ZDOInitDevice                   106
     ZDApp_ReadNetworkRestoreState    18
     ?Subroutine20                     5
     ZDAppDetermineDeviceType          3
     ZDApp_NetworkStartEvt            78
     ZDApp_DeviceAuthEvt              57
     ZDApp_SaveNetworkStateEvt         3
     ZDApp_RestoreNetworkState       109
     ?Subroutine22                     5
     ?Subroutine8                     32
     ZDApp_InitUserDesc               93
     ZDAppCheckForHoldKey             20
     ZDApp_ProcessOSALMsg             41
     ZDApp_ProcessMsgCBs             159
     ?Subroutine5                      9
     ?Subroutine10                     4
     ?Subroutine14                     5
     ?Subroutine15                    11
     ?Subroutine11                    12
     ?Subroutine9                      8
     ZDApp_RegisterCBs                24
     ?Subroutine6                     11
     ZDApp_SaveNwkKey                 82
     ?Subroutine13                    14
     ZDApp_ResetNwkKey                38
     ZDApp_RestoreNwkKey             136
     ZDApp_ResetTimerStart            16
     ZDApp_ResetTimerCancel           19
     ZDApp_LeaveCtrlInit              64
     ?Subroutine0                     14
     ZDApp_LeaveCtrlSet               50
     ZDApp_LeaveCtrlBypass            16
     ZDApp_LeaveCtrlStartup           74
     ZDApp_LeaveReset                 16
     ZDApp_LeaveUpdate                13
     ZDApp_SendEventMsg                8
     ?Subroutine21                     5
     ?Subroutine7                      9
     ZDApp_SendMsg                    91
     ZDO_NetworkDiscoveryConfirmCB   324
     ?Subroutine1                      7
     ZDO_NetworkFormationConfirmCB    33
     ?Subroutine12                    19
     ZDO_StartRouterConfirmCB         33
     ZDO_JoinConfirmCB                39
     ZDO_JoinIndicationCB             25
     ZDO_LeaveCnf                     61
     ZDO_LeaveInd                    131
     ZDO_SyncIndicationCB              3
     ZDO_PollConfirmCB                 3
     AddrMgrWriteNVRequest            29
     ZDO_UpdateDeviceIndication        0
     ?Subroutine17                     5
     ZDApp_InMsgCB                    98
     ZDApp_ChangeMatchDescRespPermission
                                      10
     ZDApp_NetworkInit                29
     ZDApp_StartUpFromApp             24
     ZDApp_StopStartUp                 3
     ZDApp_StartJoiningCycle          39
     ZDApp_StopJoiningCycle           31
     ZDApp_CoordStartPANIDConflictCB
                                      14
     ZDApp_NVUpdate                   18
     __Constant_0                      4
     __Constant_1                      4
     __Constant_3e8                    4
     ?Subroutine3                     14
     ?<Initializer for zdoDiscCounter>
                                       1
     ?<Initializer for continueJoining>
                                       1
     ?<Initializer for devState>       1
     ?<Initializer for devStartMode>
                                       1
     ?<Initializer for ZDApp_epDesc>
                                       6
     ?<Initializer for __Constant_0>
                                       4
     ?<Initializer for __Constant_1>
                                       4
     ?<Initializer for __Constant_3e8>
                                       4
     ??ZDApp_Init?relay                6
     ??ZDApp_SecInit?relay             6
     ??ZDApp_event_loop?relay          6
     ??ZDOInitDevice?relay             6
     ??ZDApp_ReadNetworkRestoreState?relay
                                       6
     ??ZDAppDetermineDeviceType?relay
                                       6
     ??ZDApp_NetworkStartEvt?relay     6
     ??ZDApp_DeviceAuthEvt?relay       6
     ??ZDApp_SaveNetworkStateEvt?relay
                                       6
     ??ZDApp_RestoreNetworkState?relay
                                       6
     ??ZDApp_InitUserDesc?relay        6
     ??ZDAppCheckForHoldKey?relay      6
     ??ZDApp_ProcessOSALMsg?relay      6
     ??ZDApp_ProcessMsgCBs?relay       6
     ??ZDApp_RegisterCBs?relay         6
     ??ZDApp_SaveNwkKey?relay          6
     ??ZDApp_ResetNwkKey?relay         6
     ??ZDApp_RestoreNwkKey?relay       6
     ??ZDApp_ResetTimerStart?relay     6
     ??ZDApp_ResetTimerCancel?relay    6
     ??ZDApp_LeaveCtrlInit?relay       6
     ??ZDApp_LeaveCtrlSet?relay        6
     ??ZDApp_LeaveCtrlBypass?relay     6
     ??ZDApp_LeaveCtrlStartup?relay    6
     ??ZDApp_LeaveReset?relay          6
     ??ZDApp_LeaveUpdate?relay         6
     ??ZDApp_SendEventMsg?relay        6
     ??ZDApp_SendMsg?relay             6
     ??ZDO_NetworkDiscoveryConfirmCB?relay
                                       6
     ??ZDO_NetworkFormationConfirmCB?relay
                                       6
     ??ZDO_StartRouterConfirmCB?relay
                                       6
     ??ZDO_JoinConfirmCB?relay         6
     ??ZDO_JoinIndicationCB?relay      6
     ??ZDO_LeaveCnf?relay              6
     ??ZDO_LeaveInd?relay              6
     ??ZDO_SyncIndicationCB?relay      6
     ??ZDO_PollConfirmCB?relay         6
     ??AddrMgrWriteNVRequest?relay     6
     ??ZDO_UpdateDeviceIndication?relay
                                       6
     ??ZDApp_InMsgCB?relay             6
     ??ZDApp_ChangeMatchDescRespPermission?relay
                                       6
     ??ZDApp_NetworkInit?relay         6
     ??ZDApp_StartUpFromApp?relay      6
     ??ZDApp_StopStartUp?relay         6
     ??ZDApp_StartJoiningCycle?relay
                                       6
     ??ZDApp_StopJoiningCycle?relay    6
     ??ZDApp_CoordStartPANIDConflictCB?relay
                                       6
     ??ZDApp_NVUpdate?relay            6

 
 2 981 bytes in segment BANKED_CODE
   288 bytes in segment BANK_RELAYS
     2 bytes in segment SFR_AN
    22 bytes in segment XDATA_I
    22 bytes in segment XDATA_ID
    17 bytes in segment XDATA_Z
 
 3 279 bytes of CODE  memory (+ 12 bytes shared)
     0 bytes of DATA  memory (+  2 bytes shared)
    27 bytes of XDATA memory (+ 12 bytes shared)

Errors: none
Warnings: none
