///////////////////////////////////////////////////////////////////////////////
//                                                                            /
// 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\Component /
//                          s\stack\sys\ZGlobals.c                            /
//    Command line       =  -f "C:\Texas Instruments\ZStack-1.4.3-1.2.1\Proje /
//                          cts\zstack\Project\Location\CC2430DB\..\..\..\Too /
//                          ls\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\ /
//                          CC2430DB\f8wConfig.cfg" (-DSECURE=1               /
//                          -DDEFAULT_CHANLIST=0x04000000                     /
//                          -DZDAPP_CONFIG_PAN_ID=0x00FF                      /
//                          -DNWK_START_DELAY=100 -DEXTENDED_JOINING_RANDOM_M /
//                          ASK=0x007F -DBEACON_REQUEST_DELAY=100             /
//                          -DBEACON_REQ_DELAY_MASK=0x00FF                    /
//                          -DROUTE_EXPIRY_TIME=30 -DAPSC_ACK_WAIT_DURATION_P /
//                          OLLED=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\Componen /
//                          ts\stack\sys\ZGlobals.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\Pr /
//                          oject\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 /
//                          \Projects\zstack\Project\Location\CC2430DB\LocDon /
//                          gle\Obj\" -e --require_prototypes -z9             /
//                          --no_code_motion --debug --core=plain             /
//                          --dptr=16,1 --data_model=large                    /
//                          --code_model=banked --calling_convention=xdata_re /
//                          entrant --place_constants=data --nr_virtual_regs  /
//                          8 -I "C:\Texas Instruments\ZStack-1.4.3-1.2.1\Pro /
//                          jects\zstack\Project\Location\CC2430DB\" -I       /
//                          "C:\Texas Instruments\ZStack-1.4.3-1.2.1\Projects /
//                          \zstack\Project\Location\CC2430DB\..\SOURCE\" -I  /
//                          "C:\Texas Instruments\ZStack-1.4.3-1.2.1\Projects /
//                          \zstack\Project\Location\CC2430DB\..\..\..\ZMAIN\ /
//                          TI2430DB\" -I "C:\Texas                           /
//                          Instruments\ZStack-1.4.3-1.2.1\Projects\zstack\Pr /
//                          oject\Location\CC2430DB\..\..\..\..\WXL\INCLUDE\" /
//                           -I "C:\Texas Instruments\ZStack-1.4.3-1.2.1\Proj /
//                          ects\zstack\Project\Location\CC2430DB\..\..\..\.. /
//                          \..\COMPONENTS\MT\" -I "C:\Texas                  /
//                          Instruments\ZStack-1.4.3-1.2.1\Projects\zstack\Pr /
//                          oject\Location\CC2430DB\..\..\..\..\..\COMPONENTS /
//                          \HAL\INCLUDE\" -I "C:\Texas                       /
//                          Instruments\ZStack-1.4.3-1.2.1\Projects\zstack\Pr /
//                          oject\Location\CC2430DB\..\..\..\..\..\COMPONENTS /
//                          \HAL\TARGET\CC2430EB\" -I "C:\Texas               /
//                          Instruments\ZStack-1.4.3-1.2.1\Projects\zstack\Pr /
//                          oject\Location\CC2430DB\..\..\..\..\..\COMPONENTS /
//                          \OSAL\MCU\CCSOC\" -I "C:\Texas                    /
//                          Instruments\ZStack-1.4.3-1.2.1\Projects\zstack\Pr /
//                          oject\Location\CC2430DB\..\..\..\..\..\COMPONENTS /
//                          \OSAL\INCLUDE\" -I "C:\Texas                      /
//                          Instruments\ZStack-1.4.3-1.2.1\Projects\zstack\Pr /
//                          oject\Location\CC2430DB\..\..\..\..\..\COMPONENTS /
//                          \STACK\AF\" -I "C:\Texas                          /
//                          Instruments\ZStack-1.4.3-1.2.1\Projects\zstack\Pr /
//                          oject\Location\CC2430DB\..\..\..\..\..\COMPONENTS /
//                          \STACK\NWK\" -I "C:\Texas                         /
//                          Instruments\ZStack-1.4.3-1.2.1\Projects\zstack\Pr /
//                          oject\Location\CC2430DB\..\..\..\..\..\COMPONENTS /
//                          \STACK\SEC\" -I "C:\Texas                         /
//                          Instruments\ZStack-1.4.3-1.2.1\Projects\zstack\Pr /
//                          oject\Location\CC2430DB\..\..\..\..\..\COMPONENTS /
//                          \STACK\SYS\" -I "C:\Texas                         /
//                          Instruments\ZStack-1.4.3-1.2.1\Projects\zstack\Pr /
//                          oject\Location\CC2430DB\..\..\..\..\..\COMPONENTS /
//                          \STACK\ZDO\" -I "C:\Texas                         /
//                          Instruments\ZStack-1.4.3-1.2.1\Projects\zstack\Pr /
//                          oject\Location\CC2430DB\..\..\..\..\..\COMPONENTS /
//                          \ZMAC\F8W\" -I "C:\Texas                          /
//                          Instruments\ZStack-1.4.3-1.2.1\Projects\zstack\Pr /
//                          oject\Location\CC2430DB\..\..\..\..\..\COMPONENTS /
//                          \ZMAC\" -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\Project\Location\CC2430DB\..\..\..\..\..\ /
//                          COMPONENTS\SERVICES\SDATA\" -I "C:\Texas          /
//                          Instruments\ZStack-1.4.3-1.2.1\Projects\zstack\Pr /
//                          oject\Location\CC2430DB\..\..\..\..\..\COMPONENTS /
//                          \MAC\INCLUDE\" -I "C:\Texas                       /
//                          Instruments\ZStack-1.4.3-1.2.1\Projects\zstack\Pr /
//                          oject\Location\CC2430DB\..\..\..\..\..\COMPONENTS /
//                          \MAC\HIGH_LEVEL\" -I "C:\Texas                    /
//                          Instruments\ZStack-1.4.3-1.2.1\Projects\zstack\Pr /
//                          oject\Location\CC2430DB\..\..\..\..\..\COMPONENTS /
//                          \MAC\LOW_LEVEL\SRF03\" -I "C:\Texas               /
//                          Instruments\ZStack-1.4.3-1.2.1\Projects\zstack\Pr /
//                          oject\Location\CC2430DB\..\..\..\..\..\COMPONENTS /
//                          \MAC\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\ /
//                          zstack\Project\Location\CC2430DB\LocDongle\List\Z /
//                          Globals.s51                                       /
//                                                                            /
//                                                                            /
///////////////////////////////////////////////////////////////////////////////

        NAME ZGlobals

        RTMODEL "__calling_convention", "xdata_reentrant"
        RTMODEL "__code_model", "banked"
        RTMODEL "__core", "plain"
        RTMODEL "__data_model", "large"
        RTMODEL "__dptr_size", "16"
        RTMODEL "__extended_stack", "disabled"
        RTMODEL "__location_for_constants", "data"
        RTMODEL "__number_of_dptrs", "1"
        RTMODEL "__rt_version", "1"

        RSEG DOVERLAY:DATA:NOROOT(0)
        RSEG IOVERLAY:IDATA:NOROOT(0)
        RSEG ISTACK:IDATA:NOROOT(0)
        RSEG PSTACK:XDATA:NOROOT(0)
        RSEG XSTACK:XDATA:NOROOT(0)

        EXTERN ??zgReadStartupOptions?relay
        EXTERN ??zgWriteStartupOptions?relay
        EXTERN ?ALLOC_XSTACK8
        EXTERN ?BANKED_ENTER_XDATA
        EXTERN ?BANKED_LEAVE_XDATA
        EXTERN ?BDISPATCH
        EXTERN ?DEALLOC_XSTACK8
        EXTERN ?PUSH_XSTACK_I_THREE
        EXTERN ?PUSH_XSTACK_I_TWO
        EXTERN ?V0
        EXTERN ?XSP
        EXTERN __INIT_XDATA_I
        EXTERN __INIT_XDATA_Z

        PUBLIC ??zgInit?relay
        FUNCTION ??zgInit?relay,0203H
        PUBLIC ??zgReadStartupOptions?relay
        FUNCTION ??zgReadStartupOptions?relay,0203H
        PUBLIC ??zgWriteStartupOptions?relay
        FUNCTION ??zgWriteStartupOptions?relay,0203H
        PUBLIC zgApsAckWaitMultiplier
        PUBLIC zgApsDefaultMaxBindingTime
        PUBLIC zgApscAckWaitDurationPolled
        PUBLIC zgApscMaxFrameRetries
        PUBLIC zgBcastDeliveryTime
        PUBLIC zgConcentratorDiscoveryTime
        PUBLIC zgConcentratorEnable
        PUBLIC zgConcentratorRadius
        PUBLIC zgConfigPANID
        PUBLIC zgDefaultChannelList
        PUBLIC zgDefaultStartingScanDuration
        PUBLIC zgDeviceLogicalType
        PUBLIC zgExtendedPANID
        PUBLIC zgIndirectMsgTimeout
        PUBLIC zgInit
        FUNCTION zgInit,021203H
        ARGFRAME XSTACK, 0, STACK
        LOCFRAME XSTACK, 19, STACK
        PUBLIC zgMaxBcastRetires
        PUBLIC zgMaxDataRetries
        PUBLIC zgMaxPollFailureRetries
        PUBLIC zgMaxSourceRoute
        PUBLIC zgNwkMode
        PUBLIC zgPassiveAckTimeout
        PUBLIC zgPollRate
        PUBLIC zgPreConfigKey
        PUBLIC zgPreConfigKeys
        PUBLIC zgQueuedPollRate
        PUBLIC zgReadStartupOptions
        FUNCTION zgReadStartupOptions,021203H
        ARGFRAME XSTACK, 15, STACK
        ARGFRAME IOVERLAY, 0, STATIC
        ARGFRAME DOVERLAY, 0, STATIC
        LOCFRAME ISTACK, 1, STACK
        LOCFRAME XSTACK, 15, STACK
        PUBLIC zgRejoinPollRate
        PUBLIC zgResponsePollRate
        PUBLIC zgRouteExpiryTime
        PUBLIC zgSapiEndpoint
        PUBLIC zgSecurityLevel
        PUBLIC zgStackProfile
        PUBLIC zgStartDelay
        PUBLIC zgWriteStartupOptions
        FUNCTION zgWriteStartupOptions,021203H
        ARGFRAME XSTACK, 15, STACK
        ARGFRAME IOVERLAY, 0, STATIC
        ARGFRAME DOVERLAY, 0, STATIC
        LOCFRAME ISTACK, 1, STACK
        LOCFRAME XSTACK, 15, STACK
        
        CFI Names cfiNames0
        CFI StackFrame CFA_SP SP DATA
        CFI StackFrame CFA_PSP16 PSP16 XDATA
        CFI StackFrame CFA_XSP16 XSP16 XDATA
        CFI StaticOverlayFrame CFA_IOVERLAY IOVERLAY
        CFI StaticOverlayFrame CFA_DOVERLAY DOVERLAY
        CFI Resource `PSW.CY`:1, `B.BR0`:1, `B.BR1`:1, `B.BR2`:1, `B.BR3`:1
        CFI Resource `B.BR4`:1, `B.BR5`:1, `B.BR6`:1, `B.BR7`:1, `VB.BR8`:1
        CFI Resource `VB.BR9`:1, `VB.BR10`:1, `VB.BR11`:1, `VB.BR12`:1
        CFI Resource `VB.BR13`:1, `VB.BR14`:1, `VB.BR15`:1, VB:8, B:8, A:8
        CFI Resource PSW:8, DPL0:8, DPH0:8, R0:8, R1:8, R2:8, R3:8, R4:8, R5:8
        CFI Resource R6:8, R7:8, V0:8, V1:8, V2:8, V3:8, V4:8, V5:8, V6:8, V7:8
        CFI Resource SP:8, PSPH:8, PSPL:8, PSP16:16, XSPH:8, XSPL:8, XSP16:16
        CFI VirtualResource ?RET:24
        CFI Resource ?BRET_EXT:8
        CFI VirtualResource ?RET_HIGH:8, ?RET_LOW:8
        CFI ResourceParts PSP16 PSPH, PSPL
        CFI ResourceParts XSP16 XSPH, XSPL
        CFI ResourceParts ?RET ?BRET_EXT, ?RET_HIGH, ?RET_LOW
        CFI EndNames cfiNames0
        
        CFI Common cfiCommon0 Using cfiNames0
        CFI CodeAlign 1
        CFI DataAlign -1
        CFI ReturnAddress ?RET CODE
        CFI CFA_DOVERLAY Used
        CFI CFA_IOVERLAY Used
        CFI CFA_SP SP+-3
        CFI CFA_PSP16 PSP16+0
        CFI CFA_XSP16 XSP16+0
        CFI `PSW.CY` SameValue
        CFI `B.BR0` SameValue
        CFI `B.BR1` SameValue
        CFI `B.BR2` SameValue
        CFI `B.BR3` SameValue
        CFI `B.BR4` SameValue
        CFI `B.BR5` SameValue
        CFI `B.BR6` SameValue
        CFI `B.BR7` SameValue
        CFI `VB.BR8` SameValue
        CFI `VB.BR9` SameValue
        CFI `VB.BR10` SameValue
        CFI `VB.BR11` SameValue
        CFI `VB.BR12` SameValue
        CFI `VB.BR13` SameValue
        CFI `VB.BR14` SameValue
        CFI `VB.BR15` SameValue
        CFI VB SameValue
        CFI B Undefined
        CFI A Undefined
        CFI PSW SameValue
        CFI DPL0 SameValue
        CFI DPH0 SameValue
        CFI R0 Undefined
        CFI R1 Undefined
        CFI R2 Undefined
        CFI R3 Undefined
        CFI R4 Undefined
        CFI R5 Undefined
        CFI R6 SameValue
        CFI R7 SameValue
        CFI V0 SameValue
        CFI V1 SameValue
        CFI V2 SameValue
        CFI V3 SameValue
        CFI V4 SameValue
        CFI V5 SameValue
        CFI V6 SameValue
        CFI V7 SameValue
        CFI PSPH Undefined
        CFI PSPL Undefined
        CFI XSPH Undefined
        CFI XSPL Undefined
        CFI ?RET Concat
        CFI ?BRET_EXT Frame(CFA_SP, 3)
        CFI ?RET_HIGH Frame(CFA_SP, 2)
        CFI ?RET_LOW Frame(CFA_SP, 1)
        CFI EndCommon cfiCommon0
        
        
        CFI Common cfiCommon1 Using cfiNames0
        CFI CodeAlign 1
        CFI DataAlign -1
        CFI ReturnAddress ?RET CODE
        CFI CFA_DOVERLAY Used
        CFI CFA_IOVERLAY Used
        CFI CFA_SP SP+-2
        CFI CFA_PSP16 PSP16+0
        CFI CFA_XSP16 XSP16+0
        CFI `PSW.CY` SameValue
        CFI `B.BR0` SameValue
        CFI `B.BR1` SameValue
        CFI `B.BR2` SameValue
        CFI `B.BR3` SameValue
        CFI `B.BR4` SameValue
        CFI `B.BR5` SameValue
        CFI `B.BR6` SameValue
        CFI `B.BR7` SameValue
        CFI `VB.BR8` SameValue
        CFI `VB.BR9` SameValue
        CFI `VB.BR10` SameValue
        CFI `VB.BR11` SameValue
        CFI `VB.BR12` SameValue
        CFI `VB.BR13` SameValue
        CFI `VB.BR14` SameValue
        CFI `VB.BR15` SameValue
        CFI VB SameValue
        CFI B SameValue
        CFI A SameValue
        CFI PSW SameValue
        CFI DPL0 SameValue
        CFI DPH0 SameValue
        CFI R0 SameValue
        CFI R1 SameValue
        CFI R2 SameValue
        CFI R3 SameValue
        CFI R4 SameValue
        CFI R5 SameValue
        CFI R6 SameValue
        CFI R7 SameValue
        CFI V0 SameValue
        CFI V1 SameValue
        CFI V2 SameValue
        CFI V3 SameValue
        CFI V4 SameValue
        CFI V5 SameValue
        CFI V6 SameValue
        CFI V7 SameValue
        CFI PSPH Undefined
        CFI PSPL Undefined
        CFI XSPH Undefined
        CFI XSPL Undefined
        CFI ?RET Concat
        CFI ?BRET_EXT SameValue
        CFI ?RET_HIGH Frame(CFA_SP, 2)
        CFI ?RET_LOW Frame(CFA_SP, 1)
        CFI EndCommon cfiCommon1
        
osal_memcpy         SYMBOL "osal_memcpy"
osal_nv_read        SYMBOL "osal_nv_read"
osal_nv_item_init   SYMBOL "osal_nv_item_init"
osal_nv_write       SYMBOL "osal_nv_write"
??osal_memcpy?relay SYMBOL "?relay", osal_memcpy
??osal_nv_item_init?relay SYMBOL "?relay", osal_nv_item_init
??osal_nv_read?relay SYMBOL "?relay", osal_nv_read
??osal_nv_write?relay SYMBOL "?relay", osal_nv_write
zgInit              SYMBOL "zgInit"
??zgInit?relay      SYMBOL "?relay", zgInit
zgReadStartupOptions SYMBOL "zgReadStartupOptions"
??zgReadStartupOptions?relay SYMBOL "?relay", zgReadStartupOptions
zgWriteStartupOptions SYMBOL "zgWriteStartupOptions"
??zgWriteStartupOptions?relay SYMBOL "?relay", zgWriteStartupOptions

        EXTERN ZMacGetReq
        FUNCTION ZMacGetReq,0202H
        ARGFRAME ISTACK, 0, STACK
        ARGFRAME PSTACK, 0, STACK
        ARGFRAME XSTACK, 15, STACK
        ARGFRAME IOVERLAY, 0, STATIC
        ARGFRAME DOVERLAY, 0, STATIC
        EXTERN osal_memcpy
        FUNCTION osal_memcpy,0202H
        ARGFRAME ISTACK, 0, STACK
        ARGFRAME PSTACK, 0, STACK
        ARGFRAME XSTACK, 18, STACK
        ARGFRAME IOVERLAY, 0, STATIC
        ARGFRAME DOVERLAY, 0, STATIC
        EXTERN osal_nv_read
        FUNCTION osal_nv_read,0202H
        ARGFRAME ISTACK, 0, STACK
        ARGFRAME PSTACK, 0, STACK
        ARGFRAME XSTACK, 19, STACK
        ARGFRAME IOVERLAY, 0, STATIC
        ARGFRAME DOVERLAY, 0, STATIC
        EXTERN osal_nv_item_init
        FUNCTION osal_nv_item_init,0202H
        ARGFRAME ISTACK, 0, STACK
        ARGFRAME PSTACK, 0, STACK
        ARGFRAME XSTACK, 17, STACK
        ARGFRAME IOVERLAY, 0, STATIC
        ARGFRAME DOVERLAY, 0, STATIC
        EXTERN osal_nv_write
        FUNCTION osal_nv_write,0202H
        ARGFRAME ISTACK, 0, STACK
        ARGFRAME PSTACK, 0, STACK
        ARGFRAME XSTACK, 19, STACK
        ARGFRAME IOVERLAY, 0, STATIC
        ARGFRAME DOVERLAY, 0, STATIC
        EXTERN ??osal_memcpy?relay
        FUNCTION ??osal_memcpy?relay,00H
        EXTERN ??osal_nv_item_init?relay
        FUNCTION ??osal_nv_item_init?relay,00H
        EXTERN ??osal_nv_read?relay
        FUNCTION ??osal_nv_read?relay,00H
        EXTERN ??osal_nv_write?relay
        FUNCTION ??osal_nv_write?relay,00H
        EXTERN defaultKey

// C:\Texas Instruments\ZStack-1.4.3-1.2.1\Components\stack\sys\ZGlobals.c
//    1 /**************************************************************************************************
//    2   Filename:       ZGlobals.c
//    3   Revised:        $Date: 2007-01-08 12:56:09 -0800 (Mon, 08 Jan 2007) $
//    4   Revision:       $Revision: 13236 $
//    5 
//    6   Description:    User definable Z-Stack parameters.
//    7 
//    8 
//    9   Copyright 2007 Texas Instruments Incorporated. All rights reserved.
//   10 
//   11   IMPORTANT: Your use of this Software is limited to those specific rights
//   12   granted under the terms of a software license agreement between the user
//   13   who downloaded the software, his/her employer (which must be your employer)
//   14   and Texas Instruments Incorporated (the "License").  You may not use this
//   15   Software unless you agree to abide by the terms of the License. The License
//   16   limits your use, and you acknowledge, that the Software may not be modified,
//   17   copied or distributed unless embedded on a Texas Instruments microcontroller
//   18   or used solely and exclusively in conjunction with a Texas Instruments radio
//   19   frequency transceiver, which is integrated into your product.  Other than for
//   20   the foregoing purpose, you may not use, reproduce, copy, prepare derivative
//   21   works of, modify, distribute, perform, display or sell this Software and/or
//   22   its documentation for any purpose.
//   23 
//   24   YOU FURTHER ACKNOWLEDGE AND AGREE THAT THE SOFTWARE AND DOCUMENTATION ARE
//   25   PROVIDED “AS IS?WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED,
//   26   INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY, TITLE,
//   27   NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL
//   28   TEXAS INSTRUMENTS OR ITS LICENSORS BE LIABLE OR OBLIGATED UNDER CONTRACT,
//   29   NEGLIGENCE, STRICT LIABILITY, CONTRIBUTION, BREACH OF WARRANTY, OR OTHER
//   30   LEGAL EQUITABLE THEORY ANY DIRECT OR INDIRECT DAMAGES OR EXPENSES
//   31   INCLUDING BUT NOT LIMITED TO ANY INCIDENTAL, SPECIAL, INDIRECT, PUNITIVE
//   32   OR CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, COST OF PROCUREMENT
//   33   OF SUBSTITUTE GOODS, TECHNOLOGY, SERVICES, OR ANY CLAIMS BY THIRD PARTIES
//   34   (INCLUDING BUT NOT LIMITED TO ANY DEFENSE THEREOF), OR OTHER SIMILAR COSTS.
//   35 
//   36   Should you have any questions regarding your right to use this Software,
//   37   contact Texas Instruments Incorporated at www.TI.com.
//   38 **************************************************************************************************/
//   39 
//   40 /*********************************************************************
//   41  * INCLUDES
//   42  */
//   43 
//   44 #include "ZComDef.h"
//   45 #include "OSAL_Nv.h"
//   46 #include "ZDObject.h"
//   47 #include "ZGlobals.h"
//   48 
//   49 #include "OnBoard.h"
//   50 
//   51 /*********************************************************************
//   52  * MACROS
//   53  */
//   54 
//   55 /*********************************************************************
//   56  * CONSTANTS
//   57  */
//   58 
//   59 /*********************************************************************
//   60  * TYPEDEFS
//   61  */
//   62 
//   63 typedef struct zgItem
//   64 {
//   65   uint16 id;
//   66   uint16 len;
//   67   void *buf;
//   68 } zgItem_t;
//   69 
//   70 /*********************************************************************
//   71  * NWK GLOBAL VARIABLES
//   72  */
//   73 
//   74 // Polling values

        RSEG XDATA_I:XDATA:NOROOT(0)
        DATA
//   75 uint16 zgPollRate = POLL_RATE;
zgPollRate:
        DS 2
        REQUIRE `?<Initializer for zgPollRate>`
        REQUIRE __INIT_XDATA_I

        RSEG XDATA_I:XDATA:NOROOT(0)
        DATA
//   76 uint16 zgQueuedPollRate = QUEUED_POLL_RATE;
zgQueuedPollRate:
        DS 2
        REQUIRE `?<Initializer for zgQueuedPollRate>`
        REQUIRE __INIT_XDATA_I

        RSEG XDATA_I:XDATA:NOROOT(0)
        DATA
//   77 uint16 zgResponsePollRate = RESPONSE_POLL_RATE;
zgResponsePollRate:
        DS 2
        REQUIRE `?<Initializer for zgResponsePollRate>`
        REQUIRE __INIT_XDATA_I

        RSEG XDATA_I:XDATA:NOROOT(0)
        DATA
//   78 uint16 zgRejoinPollRate = REJOIN_POLL_RATE;
zgRejoinPollRate:
        DS 2
        REQUIRE `?<Initializer for zgRejoinPollRate>`
        REQUIRE __INIT_XDATA_I
//   79 
//   80 // Transmission retries numbers

        RSEG XDATA_I:XDATA:NOROOT(0)
        DATA
//   81 uint8 zgMaxDataRetries = NWK_MAX_DATA_RETRIES;
zgMaxDataRetries:
        DS 1
        REQUIRE `?<Initializer for zgMaxDataRetries>`
        REQUIRE __INIT_XDATA_I

        RSEG XDATA_I:XDATA:NOROOT(0)
        DATA
//   82 uint8 zgMaxPollFailureRetries = MAX_POLL_FAILURE_RETRIES;
zgMaxPollFailureRetries:
        DS 1
        REQUIRE `?<Initializer for zgMaxPollFailureRetries>`
        REQUIRE __INIT_XDATA_I
//   83 
//   84 // Default channel list

        RSEG XDATA_I:XDATA:NOROOT(0)
        DATA
//   85 uint32 zgDefaultChannelList = DEFAULT_CHANLIST;
zgDefaultChannelList:
        DS 4
        REQUIRE `?<Initializer for zgDefaultChannelList>`
        REQUIRE __INIT_XDATA_I
//   86 
//   87 // Default starting scan duration

        RSEG XDATA_I:XDATA:NOROOT(0)
        DATA
//   88 uint8 zgDefaultStartingScanDuration = STARTING_SCAN_DURATION;
zgDefaultStartingScanDuration:
        DS 1
        REQUIRE `?<Initializer for zgDefaultStartingScanDuratio`
        REQUIRE __INIT_XDATA_I
//   89 
//   90 // Stack profile Id

        RSEG XDATA_I:XDATA:NOROOT(0)
        DATA
//   91 uint8 zgStackProfile = STACK_PROFILE_ID;
zgStackProfile:
        DS 1
        REQUIRE `?<Initializer for zgStackProfile>`
        REQUIRE __INIT_XDATA_I
//   92 
//   93 // Default indirect message holding timeout

        RSEG XDATA_I:XDATA:NOROOT(0)
        DATA
//   94 uint8 zgIndirectMsgTimeout = NWK_INDIRECT_MSG_TIMEOUT;
zgIndirectMsgTimeout:
        DS 1
        REQUIRE `?<Initializer for zgIndirectMsgTimeout>`
        REQUIRE __INIT_XDATA_I
//   95 
//   96 // Security level

        RSEG XDATA_I:XDATA:NOROOT(0)
        DATA
//   97 uint8 zgSecurityLevel = SECURITY_LEVEL;
zgSecurityLevel:
        DS 1
        REQUIRE `?<Initializer for zgSecurityLevel>`
        REQUIRE __INIT_XDATA_I
//   98 
//   99 // Route expiry

        RSEG XDATA_I:XDATA:NOROOT(0)
        DATA
//  100 uint8 zgRouteExpiryTime = ROUTE_EXPIRY_TIME;
zgRouteExpiryTime:
        DS 1
        REQUIRE `?<Initializer for zgRouteExpiryTime>`
        REQUIRE __INIT_XDATA_I
//  101 
//  102 // Extended PAN Id

        RSEG XDATA_Z:XDATA:NOROOT(0)
//  103 uint8 zgExtendedPANID[Z_EXTADDR_LEN];
zgExtendedPANID:
        DS 8
        REQUIRE __INIT_XDATA_Z
//  104 
//  105 // Broadcast parameters

        RSEG XDATA_I:XDATA:NOROOT(0)
        DATA
//  106 uint8 zgMaxBcastRetires   = MAX_BCAST_RETRIES;
zgMaxBcastRetires:
        DS 1
        REQUIRE `?<Initializer for zgMaxBcastRetires>`
        REQUIRE __INIT_XDATA_I

        RSEG XDATA_I:XDATA:NOROOT(0)
        DATA
//  107 uint8 zgPassiveAckTimeout = PASSIVE_ACK_TIMEOUT;
zgPassiveAckTimeout:
        DS 1
        REQUIRE `?<Initializer for zgPassiveAckTimeout>`
        REQUIRE __INIT_XDATA_I

        RSEG XDATA_I:XDATA:NOROOT(0)
        DATA
//  108 uint8 zgBcastDeliveryTime = BCAST_DELIVERY_TIME;
zgBcastDeliveryTime:
        DS 1
        REQUIRE `?<Initializer for zgBcastDeliveryTime>`
        REQUIRE __INIT_XDATA_I
//  109 
//  110 // Network mode

        RSEG XDATA_Z:XDATA:NOROOT(0)
//  111 uint8 zgNwkMode = NWK_MODE;
zgNwkMode:
        DS 1
        REQUIRE __INIT_XDATA_Z
//  112 
//  113 // Many-to-one values

        RSEG XDATA_Z:XDATA:NOROOT(0)
//  114 uint8 zgConcentratorEnable = CONCENTRATOR_ENABLE;
zgConcentratorEnable:
        DS 1
        REQUIRE __INIT_XDATA_Z

        RSEG XDATA_Z:XDATA:NOROOT(0)
//  115 uint8 zgConcentratorDiscoveryTime = CONCENTRATOR_DISCOVERY_TIME;
zgConcentratorDiscoveryTime:
        DS 1
        REQUIRE __INIT_XDATA_Z

        RSEG XDATA_I:XDATA:NOROOT(0)
        DATA
//  116 uint8 zgConcentratorRadius = CONCENTRATOR_RADIUS;
zgConcentratorRadius:
        DS 1
        REQUIRE `?<Initializer for zgConcentratorRadius>`
        REQUIRE __INIT_XDATA_I

        RSEG XDATA_I:XDATA:NOROOT(0)
        DATA
//  117 uint8 zgMaxSourceRoute = MAX_SOURCE_ROUTE;
zgMaxSourceRoute:
        DS 1
        REQUIRE `?<Initializer for zgMaxSourceRoute>`
        REQUIRE __INIT_XDATA_I
//  118 
//  119 
//  120 /*********************************************************************
//  121  * APS GLOBAL VARIABLES
//  122  */
//  123 
//  124 // The maximum number of retries allowed after a transmission failure

        RSEG XDATA_I:XDATA:NOROOT(0)
        DATA
//  125 uint8 zgApscMaxFrameRetries = APSC_MAX_FRAME_RETRIES;
zgApscMaxFrameRetries:
        DS 1
        REQUIRE `?<Initializer for zgApscMaxFrameRetries>`
        REQUIRE __INIT_XDATA_I
//  126 
//  127 // The maximum number of seconds (milliseconds) to wait for an
//  128 // acknowledgement to a transmitted frame.
//  129 
//  130 // This number is used by polled devices.

        RSEG XDATA_I:XDATA:NOROOT(0)
        DATA
//  131 uint16 zgApscAckWaitDurationPolled = APSC_ACK_WAIT_DURATION_POLLED;
zgApscAckWaitDurationPolled:
        DS 2
        REQUIRE `?<Initializer for zgApscAckWaitDurationPolled>`
        REQUIRE __INIT_XDATA_I
//  132 
//  133 // This number is used by non-polled devices in the following formula:
//  134 //   (100 mSec) * (_NIB.MaxDepth * zgApsAckWaitMultiplier)

        RSEG XDATA_I:XDATA:NOROOT(0)
        DATA
//  135 uint8 zgApsAckWaitMultiplier = 2;
zgApsAckWaitMultiplier:
        DS 1
        REQUIRE `?<Initializer for zgApsAckWaitMultiplier>`
        REQUIRE __INIT_XDATA_I
//  136 
//  137 // The maximum number of milliseconds for the end device binding

        RSEG XDATA_I:XDATA:NOROOT(0)
        DATA
//  138 uint16 zgApsDefaultMaxBindingTime = APS_DEFAULT_MAXBINDING_TIME;
zgApsDefaultMaxBindingTime:
        DS 2
        REQUIRE `?<Initializer for zgApsDefaultMaxBindingTime>`
        REQUIRE __INIT_XDATA_I
//  139 
//  140 /*********************************************************************
//  141  * SECURITY GLOBAL VARIABLES
//  142  */
//  143 
//  144 // This is the pre-configured key in use (from NV memory)

        RSEG XDATA_Z:XDATA:NOROOT(0)
//  145 uint8 zgPreConfigKey[SEC_KEY_LEN];
zgPreConfigKey:
        DS 16
        REQUIRE __INIT_XDATA_Z
//  146 
//  147 // If true, preConfigKey should be configured on all devices on the network
//  148 // If false, it is configured only on the coordinator and sent to other
//  149 // devices upon joining.

        RSEG XDATA_I:XDATA:NOROOT(0)
        DATA
//  150 uint8 zgPreConfigKeys = TRUE; //  TRUE;
zgPreConfigKeys:
        DS 1
        REQUIRE `?<Initializer for zgPreConfigKeys>`
        REQUIRE __INIT_XDATA_I
//  151 
//  152 
//  153 /*********************************************************************
//  154  * ZDO GLOBAL VARIABLES
//  155  */
//  156 
//  157 // Configured PAN ID
//  158 //uint16 zgConfigPANID = ZDAPP_CONFIG_PAN_ID;

        RSEG XDATA_I:XDATA:NOROOT(0)
        DATA
//  159 uint16 zgConfigPANID = 0x00ff;
zgConfigPANID:
        DS 2
        REQUIRE `?<Initializer for zgConfigPANID>`
        REQUIRE __INIT_XDATA_I
//  160 // Device Logical Type

        RSEG XDATA_Z:XDATA:NOROOT(0)
//  161 uint8 zgDeviceLogicalType = DEVICE_LOGICAL_TYPE;
zgDeviceLogicalType:
        DS 1
        REQUIRE __INIT_XDATA_Z
//  162 
//  163 // Startup Delay

        RSEG XDATA_I:XDATA:NOROOT(0)
        DATA
//  164 uint8 zgStartDelay = START_DELAY;
zgStartDelay:
        DS 1
        REQUIRE `?<Initializer for zgStartDelay>`
        REQUIRE __INIT_XDATA_I
//  165 
//  166 /*********************************************************************
//  167  * NON-STANDARD GLOBAL VARIABLES
//  168  */
//  169 
//  170 // Simple API Endpoint

        RSEG XDATA_I:XDATA:NOROOT(0)
        DATA
//  171 uint8 zgSapiEndpoint = SAPI_ENDPOINT;
zgSapiEndpoint:
        DS 1
        REQUIRE `?<Initializer for zgSapiEndpoint>`
        REQUIRE __INIT_XDATA_I
//  172 
//  173 /*********************************************************************
//  174  * LOCAl VARIABLES
//  175  */
//  176 
//  177 /*********************************************************************
//  178  * ZGlobal Item Table
//  179  */

        RSEG CODE_C:CODE:REORDER:NOROOT(0)
        DATA
//  180 static CONST zgItem_t zgItemTable[] =
zgItemTable:
        DW 0, 0, 0H
//  181 {
//  182 #if defined ( NV_INIT )
//  183   {
//  184     ZCD_NV_LOGICAL_TYPE, sizeof(zgDeviceLogicalType), &zgDeviceLogicalType
//  185   },
//  186   {
//  187     ZCD_NV_POLL_RATE, sizeof(zgPollRate), &zgPollRate
//  188   },
//  189   {
//  190    ZCD_NV_QUEUED_POLL_RATE, sizeof(zgQueuedPollRate), &zgQueuedPollRate
//  191   },
//  192   {
//  193     ZCD_NV_RESPONSE_POLL_RATE, sizeof(zgResponsePollRate), &zgResponsePollRate
//  194   },
//  195   {
//  196     ZCD_NV_REJOIN_POLL_RATE, sizeof(zgRejoinPollRate), &zgRejoinPollRate
//  197   },
//  198   {
//  199    ZCD_NV_DATA_RETRIES, sizeof(zgMaxDataRetries), &zgMaxDataRetries
//  200   },
//  201   {
//  202      ZCD_NV_POLL_FAILURE_RETRIES, sizeof(zgMaxPollFailureRetries), &zgMaxPollFailureRetries
//  203   },
//  204   {
//  205     ZCD_NV_CHANLIST, sizeof(zgDefaultChannelList), &zgDefaultChannelList
//  206   }
//  207   ,
//  208   {
//  209     ZCD_NV_SCAN_DURATION, sizeof(zgDefaultStartingScanDuration), &zgDefaultStartingScanDuration
//  210   },
//  211   {
//  212     ZCD_NV_STACK_PROFILE, sizeof(zgStackProfile), &zgStackProfile
//  213   },
//  214   {
//  215     ZCD_NV_INDIRECT_MSG_TIMEOUT, sizeof(zgIndirectMsgTimeout), &zgIndirectMsgTimeout
//  216   },
//  217   {
//  218     ZCD_NV_ROUTE_EXPIRY_TIME, sizeof(zgRouteExpiryTime), &zgRouteExpiryTime
//  219   },
//  220   {
//  221     ZCD_NV_EXTENDED_PAN_ID, Z_EXTADDR_LEN, &zgExtendedPANID
//  222   },
//  223   {
//  224     ZCD_NV_BCAST_RETRIES, sizeof(zgMaxBcastRetires), &zgMaxBcastRetires
//  225   },
//  226   {
//  227     ZCD_NV_PASSIVE_ACK_TIMEOUT, sizeof(zgPassiveAckTimeout), &zgPassiveAckTimeout
//  228   },
//  229   {
//  230     ZCD_NV_BCAST_DELIVERY_TIME, sizeof(zgBcastDeliveryTime), &zgBcastDeliveryTime
//  231   },
//  232   {
//  233     ZCD_NV_NWK_MODE, sizeof(zgNwkMode), &zgNwkMode
//  234   },
//  235   {
//  236     ZCD_NV_CONCENTRATOR_ENABLE, sizeof(zgConcentratorEnable), &zgConcentratorEnable
//  237   },
//  238   {
//  239     ZCD_NV_CONCENTRATOR_DISCOVERY, sizeof(zgConcentratorDiscoveryTime), &zgConcentratorDiscoveryTime
//  240   },
//  241   {
//  242     ZCD_NV_CONCENTRATOR_RADIUS, sizeof(zgConcentratorRadius), &zgConcentratorRadius
//  243   },
//  244   {
//  245     ZCD_NV_MAX_SOURCE_ROUTE, sizeof(zgMaxSourceRoute), &zgMaxSourceRoute
//  246   },
//  247 #ifndef NONWK
//  248   {
//  249     ZCD_NV_PANID, sizeof(zgConfigPANID), &zgConfigPANID
//  250   },
//  251   {
//  252     ZCD_NV_PRECFGKEY, SEC_KEY_LEN, &zgPreConfigKey
//  253   },
//  254   {
//  255     ZCD_NV_PRECFGKEYS_ENABLE, sizeof(zgPreConfigKeys), &zgPreConfigKeys
//  256   },
//  257   {
//  258     ZCD_NV_SECURITY_LEVEL, sizeof(zgSecurityLevel), &zgSecurityLevel
//  259   },
//  260 #endif // NONWK
//  261   {
//  262     ZCD_NV_APS_FRAME_RETRIES, sizeof(zgApscMaxFrameRetries), &zgApscMaxFrameRetries
//  263   },
//  264   {
//  265     ZCD_NV_APS_ACK_WAIT_DURATION, sizeof(zgApscAckWaitDurationPolled), &zgApscAckWaitDurationPolled
//  266   },
//  267   {
//  268     ZCD_NV_APS_ACK_WAIT_MULTIPLIER, sizeof(zgApsAckWaitMultiplier), &zgApsAckWaitMultiplier
//  269   },
//  270   {
//  271     ZCD_NV_BINDING_TIME, sizeof(zgApsDefaultMaxBindingTime), &zgApsDefaultMaxBindingTime
//  272   },
//  273   {
//  274     ZCD_NV_START_DELAY, sizeof(zgStartDelay), &zgStartDelay
//  275   },
//  276   {
//  277     ZCD_NV_SAPI_ENDPOINT, sizeof(zgSapiEndpoint), &zgSapiEndpoint
//  278   },
//  279 #endif // NV_INIT
//  280   // Last item -- DO NOT MOVE IT!
//  281   {
//  282     0x00, 0, NULL
//  283   }
//  284 };
//  285 
//  286 /*********************************************************************
//  287  * LOCAL FUNCTIONS
//  288  */
//  289 
//  290 static uint8 zgItemInit( uint16 id, uint16 len, void *buf, uint8 setDefault );
//  291 
//  292 
//  293 /*********************************************************************
//  294  * @fn       zgItemInit()
//  295  *
//  296  * @brief
//  297  *
//  298  *   Initialize a global item. If the item doesn't exist in NV memory,
//  299  *   write the system default (value passed in) into NV memory. But if
//  300  *   it exists, set the item to the value stored in NV memory.
//  301  *
//  302  *   Also, if setDefault is TRUE and the item exists, we will write
//  303  *   the default value to NV space.
//  304  *
//  305  * @param   id - item id
//  306  * @param   len - item len
//  307  * @param   buf - pointer to the item
//  308  * @param   setDefault - TRUE to set default, not read
//  309  *
//  310  * @return  ZSUCCESS if successful, NV_ITEM_UNINIT if item did not
//  311  *          exist in NV, NV_OPER_FAILED if failure.
//  312  */
//  313 static uint8 zgItemInit( uint16 id, uint16 len, void *buf, uint8 setDefault )
//  314 {
//  315 
//  316   uint8 status;
//  317 
//  318   // If the item doesn't exist in NV memory, create and initialize
//  319   // it with the value passed in.
//  320   status = osal_nv_item_init( id, len, buf );
//  321   if ( status == ZSUCCESS )
//  322   {
//  323     if ( setDefault )
//  324     {
//  325       // Write the default value back to NV
//  326       status =  osal_nv_write( id, 0, len, buf );
//  327     }
//  328     else
//  329     {
//  330       // The item exists in NV memory, read it from NV memory
//  331       status = osal_nv_read( id, 0, len, buf );
//  332     }
//  333   }
//  334 
//  335   return (status);
//  336 }
//  337 
//  338 /*********************************************************************
//  339  * API FUNCTIONS
//  340  */
//  341 
//  342 
//  343 /*********************************************************************
//  344  * @fn          zgInit
//  345  *
//  346  * @brief
//  347  *
//  348  *   Initialize the Z-Stack Globals. If an item doesn't exist in
//  349  *   NV memory, write the system default into NV memory. But if
//  350  *   it exists, set the item to the value stored in NV memory.
//  351  *
//  352  * NOTE: The Startup Options (ZCD_NV_STARTUP_OPTION) indicate
//  353  *       that the Config state items (zgItemTable) need to be
//  354  *       set to defaults (ZCD_STARTOPT_DEFAULT_CONFIG_STATE). The
//  355  *
//  356  *
//  357  * @param       none
//  358  *
//  359  * @return      ZSUCCESS if successful, NV_ITEM_UNINIT if item did not
//  360  *              exist in NV, NV_OPER_FAILED if failure.
//  361  */

        RSEG BANKED_CODE:CODE:NOROOT(0)
//  362 uint8 zgInit( void )
zgInit:
        CFI Block cfiBlock0 Using cfiCommon0
        CFI Function zgInit
//  363 {
        FUNCALL zgInit, zgReadStartupOptions
        LOCFRAME ISTACK, 0, STACK
        LOCFRAME PSTACK, 0, STACK
        LOCFRAME XSTACK, 15, STACK
        LOCFRAME IOVERLAY, 0, STATIC
        LOCFRAME DOVERLAY, 0, STATIC
        ARGFRAME ISTACK, 0, STACK
        ARGFRAME PSTACK, 0, STACK
        ARGFRAME XSTACK, 15, STACK
        ARGFRAME IOVERLAY, 0, STATIC
        ARGFRAME DOVERLAY, 0, STATIC
        FUNCALL zgInit, ZMacGetReq
        LOCFRAME ISTACK, 0, STACK
        LOCFRAME PSTACK, 0, STACK
        LOCFRAME XSTACK, 15, STACK
        LOCFRAME IOVERLAY, 0, STATIC
        LOCFRAME DOVERLAY, 0, STATIC
        ARGFRAME ISTACK, 0, STACK
        ARGFRAME PSTACK, 0, STACK
        ARGFRAME XSTACK, 15, STACK
        ARGFRAME IOVERLAY, 0, STATIC
        ARGFRAME DOVERLAY, 0, STATIC
        FUNCALL zgInit, osal_memcpy
        LOCFRAME ISTACK, 0, STACK
        LOCFRAME PSTACK, 0, STACK
        LOCFRAME XSTACK, 18, STACK
        LOCFRAME IOVERLAY, 0, STATIC
        LOCFRAME DOVERLAY, 0, STATIC
        ARGFRAME ISTACK, 0, STACK
        ARGFRAME PSTACK, 0, STACK
        ARGFRAME XSTACK, 18, STACK
        ARGFRAME IOVERLAY, 0, STATIC
        ARGFRAME DOVERLAY, 0, STATIC
        FUNCALL zgInit, osal_nv_read
        LOCFRAME ISTACK, 0, STACK
        LOCFRAME PSTACK, 0, STACK
        LOCFRAME XSTACK, 19, STACK
        LOCFRAME IOVERLAY, 0, STATIC
        LOCFRAME DOVERLAY, 0, STATIC
        ARGFRAME ISTACK, 0, STACK
        ARGFRAME PSTACK, 0, STACK
        ARGFRAME XSTACK, 19, STACK
        ARGFRAME IOVERLAY, 0, STATIC
        ARGFRAME DOVERLAY, 0, STATIC
        FUNCALL zgInit, osal_nv_item_init
        LOCFRAME ISTACK, 0, STACK
        LOCFRAME PSTACK, 0, STACK
        LOCFRAME XSTACK, 17, STACK
        LOCFRAME IOVERLAY, 0, STATIC
        LOCFRAME DOVERLAY, 0, STATIC
        ARGFRAME ISTACK, 0, STACK
        ARGFRAME PSTACK, 0, STACK
        ARGFRAME XSTACK, 17, STACK
        ARGFRAME IOVERLAY, 0, STATIC
        ARGFRAME DOVERLAY, 0, STATIC
        FUNCALL zgInit, osal_nv_write
        LOCFRAME ISTACK, 0, STACK
        LOCFRAME PSTACK, 0, STACK
        LOCFRAME XSTACK, 19, STACK
        LOCFRAME IOVERLAY, 0, STATIC
        LOCFRAME DOVERLAY, 0, STATIC
        ARGFRAME ISTACK, 0, STACK
        ARGFRAME PSTACK, 0, STACK
        ARGFRAME XSTACK, 19, STACK
        ARGFRAME IOVERLAY, 0, STATIC
        ARGFRAME DOVERLAY, 0, STATIC
        FUNCALL zgInit, zgWriteStartupOptions
        LOCFRAME ISTACK, 0, STACK
        LOCFRAME PSTACK, 0, STACK
        LOCFRAME XSTACK, 15, STACK
        LOCFRAME IOVERLAY, 0, STATIC
        LOCFRAME DOVERLAY, 0, STATIC
        ARGFRAME ISTACK, 0, STACK
        ARGFRAME PSTACK, 0, STACK
        ARGFRAME XSTACK, 15, STACK
        ARGFRAME IOVERLAY, 0, STATIC
        ARGFRAME DOVERLAY, 0, STATIC
        MOV     A,#-0xf
        LCALL   ?BANKED_ENTER_XDATA
        CFI DPH0 load(1, XDATA, add(CFA_XSP16, literal(-1)))
        CFI DPL0 load(1, XDATA, add(CFA_XSP16, literal(-2)))
        CFI ?BRET_EXT load(1, XDATA, add(CFA_XSP16, literal(-3)))
        CFI ?RET_HIGH load(1, XDATA, add(CFA_XSP16, literal(-4)))
        CFI ?RET_LOW load(1, XDATA, add(CFA_XSP16, literal(-5)))
        CFI R7 load(1, XDATA, add(CFA_XSP16, literal(-6)))
        CFI V6 load(1, XDATA, add(CFA_XSP16, literal(-7)))
        CFI V5 load(1, XDATA, add(CFA_XSP16, literal(-8)))
        CFI V4 load(1, XDATA, add(CFA_XSP16, literal(-9)))
        CFI V3 load(1, XDATA, add(CFA_XSP16, literal(-10)))
        CFI V2 load(1, XDATA, add(CFA_XSP16, literal(-11)))
        CFI V1 load(1, XDATA, add(CFA_XSP16, literal(-12)))
        CFI V0 load(1, XDATA, add(CFA_XSP16, literal(-13)))
        CFI VB load(1, XDATA, add(CFA_XSP16, literal(-14)))
        CFI R6 load(1, XDATA, add(CFA_XSP16, literal(-15)))
        CFI CFA_SP SP+0
        CFI CFA_XSP16 add(XSP16, 15)
        ; Saved register size: 15
        ; Auto size: 0
//  364   uint8  i = 0;
        MOV     ?V0 + 3,#0x0
//  365   uint8  setDefault = FALSE;
        MOV     ?V0 + 2,#0x0
//  366 
//  367   // Do we want to default the Config state values
//  368   if ( zgReadStartupOptions() & ZCD_STARTOPT_DEFAULT_CONFIG_STATE )
        ; Setup parameters for call to function zgReadStartupOptions
        LCALL   ??zgReadStartupOptions?relay
        MOV     A,R1
        MOV     C,0xE0 /* A   */.0
        JNC     ??zgInit_0
//  369   {
//  370     setDefault = TRUE;
        MOV     ?V0 + 2,#0x1
//  371   }
//  372 
//  373 #if 0
//  374   // Enable this section if you need to track the number of resets
//  375   // This section is normally disabled to minimize "wear" on NV memory
//  376   uint16 bootCnt = 0;
//  377 
//  378   // Update the Boot Counter
//  379   if ( osal_nv_item_init( ZCD_NV_BOOTCOUNTER, sizeof(bootCnt), &bootCnt ) == ZSUCCESS )
//  380   {
//  381     // Get the old value from NV memory
//  382     osal_nv_read( ZCD_NV_BOOTCOUNTER, 0, sizeof(bootCnt), &bootCnt );
//  383   }
//  384 
//  385   // Increment the Boot Counter and store it into NV memory
//  386   if ( setDefault )
//  387     bootCnt = 0;
//  388   else
//  389     bootCnt++;
//  390   osal_nv_write( ZCD_NV_BOOTCOUNTER, 0, sizeof(bootCnt), &bootCnt );
//  391 #endif
//  392 
//  393   // Initialize the Extended PAN ID as my own extended address
//  394   ZMacGetReq( ZMacExtAddr, zgExtendedPANID );
??zgInit_0:
        ; Setup parameters for call to function ZMacGetReq
        MOV     R2,#(zgExtendedPANID & 0xff)
        MOV     R3,#((zgExtendedPANID >> 8) & 0xff)
        MOV     R1,#-0x1e
        LCALL   ZMacGetReq & 0xFFFF
//  395 
//  396 #ifndef NONWK
//  397   // Initialize the Pre-Configured Key to the default key
//  398   osal_memcpy( zgPreConfigKey, defaultKey, SEC_KEY_LEN );  // Do NOT Change!!!
        ; Setup parameters for call to function osal_memcpy
        MOV     ?V0 + 4,#(defaultKey & 0xff)
        MOV     ?V0 + 5,#((defaultKey >> 8) & 0xff)
        MOV     ?V0 + 6,#-0x80
        MOV     R0,#?V0 + 4
        LCALL   ?PUSH_XSTACK_I_THREE
        CFI CFA_XSP16 add(XSP16, 18)
        MOV     R4,#0x10
        MOV     R5,#0x0
        MOV     R2,#(zgPreConfigKey & 0xff)
        MOV     R3,#((zgPreConfigKey >> 8) & 0xff)
        LCALL   ??osal_memcpy?relay
        MOV     A,#0x3
        LCALL   ?DEALLOC_XSTACK8
        CFI CFA_XSP16 add(XSP16, 15)
        SJMP    ??zgInit_1
//  399 #endif // NONWK
//  400 
//  401   while ( zgItemTable[i].id != 0x00 )
//  402   {
??zgInit_2:
        ; Setup parameters for call to function osal_nv_read
        LCALL   ?PUSH_XSTACK_I_TWO
        CFI CFA_XSP16 add(XSP16, 17)
        MOV     R0,#?V0 + 0
        LCALL   ?PUSH_XSTACK_I_TWO
        CFI CFA_XSP16 add(XSP16, 19)
        MOV     R4,#0x0
        MOV     R5,#0x0
        MOV     A,R6
        MOV     R2,A
        MOV     A,R7
        MOV     R3,A
        LCALL   ??osal_nv_read?relay
??zgInit_3:
        MOV     A,#0x4
        LCALL   ?DEALLOC_XSTACK8
        CFI CFA_XSP16 add(XSP16, 15)
//  403     // Initialize the item
//  404     zgItemInit( zgItemTable[i].id, zgItemTable[i].len, zgItemTable[i].buf, setDefault  );
//  405 
//  406     // Move on to the next item
//  407     i++;
??zgInit_4:
        INC     ?V0 + 3
??zgInit_1:
        MOV     A,?V0 + 3
        MOV     B,#0x6
        MUL     AB
        MOV     R0,A
        MOV     R2,B
        MOV     A,R2
        MOV     R1,A
        MOV     A,R0
        ADD     A,#(zgItemTable & 0xff)
        MOV     DPL,A
        MOV     A,R1
        ADDC    A,#((zgItemTable >> 8) & 0xff)
        MOV     DPH,A
        CLR     A
        MOVC    A,@A+DPTR
        MOV     R0,A
        MOV     A,#0x1
        MOVC    A,@A+DPTR
        MOV     R1,A
        MOV     A,R0
        JNZ     ??zgInit_5
        MOV     A,R1
??zgInit_5:
        JNZ     $+5
        LJMP    ??zgInit_6 & 0xFFFF
        MOV     A,?V0 + 3
        MOV     B,#0x6
        MUL     AB
        MOV     R0,A
        MOV     A,R2
        MOV     R1,A
        MOV     A,R0
        ADD     A,#(zgItemTable & 0xff)
        MOV     R0,A
        MOV     A,R1
        ADDC    A,#((zgItemTable >> 8) & 0xff)
        MOV     R1,A
        INC     DPTR
        INC     DPTR
        INC     DPTR
        INC     DPTR
        CLR     A
        MOVC    A,@A+DPTR
        MOV     ?V0 + 4,A
        MOV     A,#0x1
        MOVC    A,@A+DPTR
        MOV     ?V0 + 5,A
        MOV     DPL,R0
        MOV     DPH,R1
        INC     DPTR
        INC     DPTR
        CLR     A
        MOVC    A,@A+DPTR
        PUSH    A
        MOV     A,#0x1
        MOVC    A,@A+DPTR
        MOV     DPH,A
        POP     DPL
        MOV     ?V0 + 0,DPL
        MOV     ?V0 + 1,DPH
        MOV     DPL,R0
        MOV     DPH,R1
        CLR     A
        MOVC    A,@A+DPTR
        PUSH    A
        MOV     A,#0x1
        MOVC    A,@A+DPTR
        MOV     DPH,A
        POP     DPL
        MOV     R6,DPL
        MOV     R7,DPH
        ; Setup parameters for call to function osal_nv_item_init
        MOV     R0,#?V0 + 4
        LCALL   ?PUSH_XSTACK_I_TWO
        CFI CFA_XSP16 add(XSP16, 17)
        MOV     R4,?V0 + 0
        MOV     R5,?V0 + 1
        MOV     A,R6
        MOV     R2,A
        MOV     A,R7
        MOV     R3,A
        LCALL   ??osal_nv_item_init?relay
        MOV     A,#0x2
        LCALL   ?DEALLOC_XSTACK8
        CFI CFA_XSP16 add(XSP16, 15)
        MOV     A,R1
        JZ      $+5
        LJMP    ??zgInit_4 & 0xFFFF
        MOV     A,?V0 + 2
        MOV     R0,#?V0 + 4
        JNZ     $+5
        LJMP    ??zgInit_2 & 0xFFFF
        ; Setup parameters for call to function osal_nv_write
        LCALL   ?PUSH_XSTACK_I_TWO
        CFI CFA_XSP16 add(XSP16, 17)
        MOV     R0,#?V0 + 0
        LCALL   ?PUSH_XSTACK_I_TWO
        CFI CFA_XSP16 add(XSP16, 19)
        MOV     R4,#0x0
        MOV     R5,#0x0
        MOV     A,R6
        MOV     R2,A
        MOV     A,R7
        MOV     R3,A
        LCALL   ??osal_nv_write?relay
        LJMP    ??zgInit_3 & 0xFFFF
        CFI CFA_XSP16 add(XSP16, 15)
//  408   }
//  409 
//  410   // Clear the Config State default
//  411   if ( setDefault )
??zgInit_6:
        MOV     A,?V0 + 2
        JZ      ??zgInit_7
//  412   {
//  413     zgWriteStartupOptions( ZG_STARTUP_CLEAR, ZCD_STARTOPT_DEFAULT_CONFIG_STATE );
        ; Setup parameters for call to function zgWriteStartupOptions
        MOV     R2,#0x1
        MOV     R1,#0x0
        LCALL   ??zgWriteStartupOptions?relay
//  414   }
//  415 
//  416   return ( ZSUCCESS );
??zgInit_7:
        MOV     R1,#0x0
        MOV     R7,#0x7
        LJMP    ?BANKED_LEAVE_XDATA
        CFI EndBlock cfiBlock0
//  417 }
//  418 
//  419 /*********************************************************************
//  420  * @fn          zgReadStartupOptions
//  421  *
//  422  * @brief       Reads the ZCD_NV_STARTUP_OPTION NV Item.
//  423  *
//  424  * @param       none
//  425  *
//  426  * @return      the ZCD_NV_STARTUP_OPTION NV item
//  427  */

        RSEG BANKED_CODE:CODE:NOROOT(0)
//  428 uint8 zgReadStartupOptions( void )
zgReadStartupOptions:
        CFI Block cfiBlock1 Using cfiCommon0
        CFI Function zgReadStartupOptions
//  429 {
        FUNCALL zgReadStartupOptions, osal_nv_item_init
        LOCFRAME ISTACK, 0, STACK
        LOCFRAME PSTACK, 0, STACK
        LOCFRAME XSTACK, 13, STACK
        LOCFRAME IOVERLAY, 0, STATIC
        LOCFRAME DOVERLAY, 0, STATIC
        ARGFRAME ISTACK, 0, STACK
        ARGFRAME PSTACK, 0, STACK
        ARGFRAME XSTACK, 13, STACK
        ARGFRAME IOVERLAY, 0, STATIC
        ARGFRAME DOVERLAY, 0, STATIC
        FUNCALL zgReadStartupOptions, osal_nv_read
        LOCFRAME ISTACK, 0, STACK
        LOCFRAME PSTACK, 0, STACK
        LOCFRAME XSTACK, 15, STACK
        LOCFRAME IOVERLAY, 0, STATIC
        LOCFRAME DOVERLAY, 0, STATIC
        ARGFRAME ISTACK, 0, STACK
        ARGFRAME PSTACK, 0, STACK
        ARGFRAME XSTACK, 15, STACK
        ARGFRAME IOVERLAY, 0, STATIC
        ARGFRAME DOVERLAY, 0, STATIC
        MOV     A,#-0xa
        LCALL   ?BANKED_ENTER_XDATA
        CFI DPH0 load(1, XDATA, add(CFA_XSP16, literal(-1)))
        CFI DPL0 load(1, XDATA, add(CFA_XSP16, literal(-2)))
        CFI ?BRET_EXT load(1, XDATA, add(CFA_XSP16, literal(-3)))
        CFI ?RET_HIGH load(1, XDATA, add(CFA_XSP16, literal(-4)))
        CFI ?RET_LOW load(1, XDATA, add(CFA_XSP16, literal(-5)))
        CFI R7 load(1, XDATA, add(CFA_XSP16, literal(-6)))
        CFI V1 load(1, XDATA, add(CFA_XSP16, literal(-7)))
        CFI V0 load(1, XDATA, add(CFA_XSP16, literal(-8)))
        CFI VB load(1, XDATA, add(CFA_XSP16, literal(-9)))
        CFI R6 load(1, XDATA, add(CFA_XSP16, literal(-10)))
        CFI CFA_SP SP+0
        CFI CFA_XSP16 add(XSP16, 10)
        ; Saved register size: 10
        ; Auto size: 1
        MOV     A,#-0x1
        LCALL   ?ALLOC_XSTACK8
        CFI CFA_XSP16 add(XSP16, 11)
//  430   // Default to Use Config State and Use Network State
//  431   uint8 startupOption = 0;
        LCALL   ?Subroutine0 & 0xFFFF
//  432 
//  433   // This should have been done in ZMain.c, but just in case.
//  434   if ( osal_nv_item_init( ZCD_NV_STARTUP_OPTION,
//  435                               sizeof(startupOption),
//  436                               &startupOption ) == ZSUCCESS )
??CrossCallReturnLabel_0:
        LCALL   ?PUSH_XSTACK_I_TWO
        CFI CFA_XSP16 add(XSP16, 13)
        MOV     R4,#0x1
        MOV     R5,#0x0
        MOV     R2,#0x3
        MOV     R3,#0x0
        LCALL   ??osal_nv_item_init?relay
        MOV     A,#0x2
        LCALL   ?DEALLOC_XSTACK8
        CFI CFA_XSP16 add(XSP16, 11)
        MOV     A,R1
        JNZ     ??zgReadStartupOptions_0
//  437   {
//  438     // Read saved startup control
//  439     osal_nv_read( ZCD_NV_STARTUP_OPTION,
//  440                   0,
//  441                   sizeof( startupOption ),
//  442                   &startupOption);
        ; Setup parameters for call to function osal_nv_read
        MOV     R0,#?V0 + 0
        LCALL   ?PUSH_XSTACK_I_TWO
        CFI CFA_XSP16 add(XSP16, 13)
        MOV     ?V0 + 0,#0x1
        MOV     ?V0 + 1,#0x0
        MOV     R0,#?V0 + 0
        LCALL   ?PUSH_XSTACK_I_TWO
        CFI CFA_XSP16 add(XSP16, 15)
        MOV     R4,#0x0
        MOV     R5,#0x0
        MOV     R2,#0x3
        MOV     R3,#0x0
        LCALL   ??osal_nv_read?relay
        MOV     A,#0x4
        LCALL   ?DEALLOC_XSTACK8
        CFI CFA_XSP16 add(XSP16, 11)
//  443   }
//  444   return ( startupOption );
??zgReadStartupOptions_0:
        MOV     DPL,?XSP + 0
        MOV     DPH,?XSP + 1
        MOVX    A,@DPTR
        MOV     R1,A
        CFI EndBlock cfiBlock1
        REQUIRE ?Subroutine1
        ; // Fall through to label ?Subroutine1
//  445 }

        RSEG BANKED_CODE:CODE:NOROOT(0)
?Subroutine1:
        CFI Block cfiBlock2 Using cfiCommon0
        CFI NoFunction
        CFI CFA_SP SP+0
        CFI CFA_XSP16 add(XSP16, 11)
        CFI VB load(1, XDATA, add(CFA_XSP16, literal(-9)))
        CFI DPL0 load(1, XDATA, add(CFA_XSP16, literal(-2)))
        CFI DPH0 load(1, XDATA, add(CFA_XSP16, literal(-1)))
        CFI R6 load(1, XDATA, add(CFA_XSP16, literal(-10)))
        CFI R7 load(1, XDATA, add(CFA_XSP16, literal(-6)))
        CFI V0 load(1, XDATA, add(CFA_XSP16, literal(-8)))
        CFI V1 load(1, XDATA, add(CFA_XSP16, literal(-7)))
        CFI ?BRET_EXT load(1, XDATA, add(CFA_XSP16, literal(-3)))
        CFI ?RET_HIGH load(1, XDATA, add(CFA_XSP16, literal(-4)))
        CFI ?RET_LOW load(1, XDATA, add(CFA_XSP16, literal(-5)))
        MOV     A,#0x1
        LCALL   ?DEALLOC_XSTACK8
        CFI CFA_XSP16 add(XSP16, 10)
        MOV     R7,#0x2
        LJMP    ?BANKED_LEAVE_XDATA
        CFI EndBlock cfiBlock2

        RSEG BANKED_CODE:CODE:NOROOT(0)
?Subroutine0:
        CFI Block cfiCond3 Using cfiCommon0
        CFI NoFunction
        CFI Conditional ??CrossCallReturnLabel_0
        CFI R6 load(1, XDATA, add(CFA_XSP16, literal(-10)))
        CFI VB load(1, XDATA, add(CFA_XSP16, literal(-9)))
        CFI V0 load(1, XDATA, add(CFA_XSP16, literal(-8)))
        CFI V1 load(1, XDATA, add(CFA_XSP16, literal(-7)))
        CFI R7 load(1, XDATA, add(CFA_XSP16, literal(-6)))
        CFI ?RET_LOW load(1, XDATA, add(CFA_XSP16, literal(-5)))
        CFI ?RET_HIGH load(1, XDATA, add(CFA_XSP16, literal(-4)))
        CFI ?BRET_EXT load(1, XDATA, add(CFA_XSP16, literal(-3)))
        CFI DPL0 load(1, XDATA, add(CFA_XSP16, literal(-2)))
        CFI DPH0 load(1, XDATA, add(CFA_XSP16, literal(-1)))
        CFI CFA_SP SP+0
        CFI CFA_XSP16 add(XSP16, 11)
        CFI Block cfiCond4 Using cfiCommon0
        CFI (cfiCond4) NoFunction
        CFI (cfiCond4) Conditional ??CrossCallReturnLabel_1
        CFI (cfiCond4) R6 load(1, XDATA, add(CFA_XSP16, literal(-10)))
        CFI (cfiCond4) VB load(1, XDATA, add(CFA_XSP16, literal(-9)))
        CFI (cfiCond4) V0 load(1, XDATA, add(CFA_XSP16, literal(-8)))
        CFI (cfiCond4) V1 load(1, XDATA, add(CFA_XSP16, literal(-7)))
        CFI (cfiCond4) R7 load(1, XDATA, add(CFA_XSP16, literal(-6)))
        CFI (cfiCond4) ?RET_LOW load(1, XDATA, add(CFA_XSP16, literal(-5)))
        CFI (cfiCond4) ?RET_HIGH load(1, XDATA, add(CFA_XSP16, literal(-4)))
        CFI (cfiCond4) ?BRET_EXT load(1, XDATA, add(CFA_XSP16, literal(-3)))
        CFI (cfiCond4) DPL0 load(1, XDATA, add(CFA_XSP16, literal(-2)))
        CFI (cfiCond4) DPH0 load(1, XDATA, add(CFA_XSP16, literal(-1)))
        CFI (cfiCond4) CFA_SP SP+0
        CFI (cfiCond4) CFA_XSP16 add(XSP16, 11)
        CFI Block cfiPicker5 Using cfiCommon1
        CFI (cfiPicker5) NoFunction
        CFI (cfiPicker5) Picker
        CLR     A
        MOV     DPL,?XSP + 0
        MOV     DPH,?XSP + 1
        CFI Block cfiCond6 Using cfiCommon0
        CFI (cfiCond6) NoFunction
        CFI (cfiCond6) Conditional ??CrossCallReturnLabel_2
        CFI (cfiCond6) R6 load(1, XDATA, add(CFA_XSP16, literal(-10)))
        CFI (cfiCond6) VB load(1, XDATA, add(CFA_XSP16, literal(-9)))
        CFI (cfiCond6) V0 load(1, XDATA, add(CFA_XSP16, literal(-8)))
        CFI (cfiCond6) V1 load(1, XDATA, add(CFA_XSP16, literal(-7)))
        CFI (cfiCond6) R7 load(1, XDATA, add(CFA_XSP16, literal(-6)))
        CFI (cfiCond6) ?RET_LOW load(1, XDATA, add(CFA_XSP16, literal(-5)))
        CFI (cfiCond6) ?RET_HIGH load(1, XDATA, add(CFA_XSP16, literal(-4)))
        CFI (cfiCond6) ?BRET_EXT load(1, XDATA, add(CFA_XSP16, literal(-3)))
        CFI (cfiCond6) DPL0 load(1, XDATA, add(CFA_XSP16, literal(-2)))
        CFI (cfiCond6) DPH0 load(1, XDATA, add(CFA_XSP16, literal(-1)))
        CFI (cfiCond6) CFA_SP SP+0
        CFI (cfiCond6) CFA_XSP16 add(XSP16, 11)
??Subroutine0_0:
        MOVX    @DPTR,A
        ; Setup parameters for call to function osal_nv_item_init
        ; Setup parameters for call to function osal_nv_read
        ; Setup parameters for call to function osal_nv_write
        MOV     ?V0 + 0,DPL
        MOV     ?V0 + 1,DPH
        MOV     R0,#?V0 + 0
        RET
        CFI EndBlock cfiCond3
        CFI EndBlock cfiCond4
        CFI EndBlock cfiPicker5
        CFI EndBlock cfiCond6
//  446 
//  447 /*********************************************************************
//  448  * @fn          zgWriteStartupOptions
//  449  *
//  450  * @brief       Writes bits into the ZCD_NV_STARTUP_OPTION NV Item.
//  451  *
//  452  * @param       action - ZG_STARTUP_SET set bit, ZG_STARTUP_CLEAR to
//  453  *               clear bit. The set bit is an OR operation, and the
//  454  *               clear bit is an AND ~(bitOptions) operation.
//  455  *
//  456  * @param       bitOptions - which bits to perform action on:
//  457  *                      ZCD_STARTOPT_DEFAULT_CONFIG_STATE
//  458  *                      ZCD_STARTOPT_DEFAULT_NETWORK_STATE
//  459  *
//  460  * @return      ZSUCCESS if successful
//  461  */

        RSEG BANKED_CODE:CODE:NOROOT(0)
//  462 uint8 zgWriteStartupOptions( uint8 action, uint8 bitOptions )
zgWriteStartupOptions:
        CFI Block cfiBlock7 Using cfiCommon0
        CFI Function zgWriteStartupOptions
//  463 {
        FUNCALL zgWriteStartupOptions, osal_nv_read
        LOCFRAME ISTACK, 0, STACK
        LOCFRAME PSTACK, 0, STACK
        LOCFRAME XSTACK, 15, STACK
        LOCFRAME IOVERLAY, 0, STATIC
        LOCFRAME DOVERLAY, 0, STATIC
        ARGFRAME ISTACK, 0, STACK
        ARGFRAME PSTACK, 0, STACK
        ARGFRAME XSTACK, 15, STACK
        ARGFRAME IOVERLAY, 0, STATIC
        ARGFRAME DOVERLAY, 0, STATIC
        FUNCALL zgWriteStartupOptions, osal_nv_write
        LOCFRAME ISTACK, 0, STACK
        LOCFRAME PSTACK, 0, STACK
        LOCFRAME XSTACK, 15, STACK
        LOCFRAME IOVERLAY, 0, STATIC
        LOCFRAME DOVERLAY, 0, STATIC
        ARGFRAME ISTACK, 0, STACK
        ARGFRAME PSTACK, 0, STACK
        ARGFRAME XSTACK, 15, STACK
        ARGFRAME IOVERLAY, 0, STATIC
        ARGFRAME DOVERLAY, 0, STATIC
        MOV     A,#-0xa
        LCALL   ?BANKED_ENTER_XDATA
        CFI DPH0 load(1, XDATA, add(CFA_XSP16, literal(-1)))
        CFI DPL0 load(1, XDATA, add(CFA_XSP16, literal(-2)))
        CFI ?BRET_EXT load(1, XDATA, add(CFA_XSP16, literal(-3)))
        CFI ?RET_HIGH load(1, XDATA, add(CFA_XSP16, literal(-4)))
        CFI ?RET_LOW load(1, XDATA, add(CFA_XSP16, literal(-5)))
        CFI R7 load(1, XDATA, add(CFA_XSP16, literal(-6)))
        CFI V1 load(1, XDATA, add(CFA_XSP16, literal(-7)))
        CFI V0 load(1, XDATA, add(CFA_XSP16, literal(-8)))
        CFI VB load(1, XDATA, add(CFA_XSP16, literal(-9)))
        CFI R6 load(1, XDATA, add(CFA_XSP16, literal(-10)))
        CFI CFA_SP SP+0
        CFI CFA_XSP16 add(XSP16, 10)
        ; Saved register size: 10
        ; Auto size: 1
        MOV     A,#-0x1
        LCALL   ?ALLOC_XSTACK8
        CFI CFA_XSP16 add(XSP16, 11)
        MOV     A,R1
        MOV     R6,A
        MOV     A,R2
        MOV     R7,A
//  464   uint8 status;
//  465   uint8 startupOptions = 0;
        LCALL   ?Subroutine0 & 0xFFFF
//  466 
//  467   status = osal_nv_read( ZCD_NV_STARTUP_OPTION,
//  468                 0,
//  469                 sizeof( startupOptions ),
//  470                 &startupOptions );
??CrossCallReturnLabel_1:
        LCALL   ?PUSH_XSTACK_I_TWO
        CFI CFA_XSP16 add(XSP16, 13)
        MOV     ?V0 + 0,#0x1
        MOV     ?V0 + 1,#0x0
        MOV     R0,#?V0 + 0
        LCALL   ?PUSH_XSTACK_I_TWO
        CFI CFA_XSP16 add(XSP16, 15)
        MOV     R4,#0x0
        MOV     R5,#0x0
        MOV     R2,#0x3
        MOV     R3,#0x0
        LCALL   ??osal_nv_read?relay
        MOV     A,#0x4
        LCALL   ?DEALLOC_XSTACK8
        CFI CFA_XSP16 add(XSP16, 11)
        MOV     A,R1
//  471 
//  472   if ( status == ZSUCCESS )
        JNZ     ??zgWriteStartupOptions_0
//  473   {
//  474     if ( action == ZG_STARTUP_SET )
        MOV     A,#-0x1
        XRL     A,R6
        JNZ     ??zgWriteStartupOptions_1
//  475     {
//  476       // Set bits
//  477       startupOptions |= bitOptions;
        MOV     DPL,?XSP + 0
        MOV     DPH,?XSP + 1
        MOVX    A,@DPTR
        ORL     A,R7
        SJMP    ??zgWriteStartupOptions_2
//  478     }
//  479     else
//  480     {
//  481       // Clear bits
//  482       startupOptions &= (0xff ^ bitOptions);
??zgWriteStartupOptions_1:
        MOV     A,#-0x1
        XRL     A,R7
        MOV     R2,A
        MOV     DPL,?XSP + 0
        MOV     DPH,?XSP + 1
        MOVX    A,@DPTR
        ANL     A,R2
??zgWriteStartupOptions_2:
        LCALL   ??Subroutine0_0 & 0xFFFF
//  483     }
//  484 
//  485     // Changed?
//  486     status = osal_nv_write( ZCD_NV_STARTUP_OPTION,
//  487                  0,
//  488                  sizeof( startupOptions ),
//  489                  &startupOptions );
??CrossCallReturnLabel_2:
        LCALL   ?PUSH_XSTACK_I_TWO
        CFI CFA_XSP16 add(XSP16, 13)
        MOV     ?V0 + 0,#0x1
        MOV     ?V0 + 1,#0x0
        MOV     R0,#?V0 + 0
        LCALL   ?PUSH_XSTACK_I_TWO
        CFI CFA_XSP16 add(XSP16, 15)
        MOV     R4,#0x0
        MOV     R5,#0x0
        MOV     R2,#0x3
        MOV     R3,#0x0
        LCALL   ??osal_nv_write?relay
        MOV     A,#0x4
        LCALL   ?DEALLOC_XSTACK8
        CFI CFA_XSP16 add(XSP16, 11)
//  490   }
//  491 
//  492   return ( status );
??zgWriteStartupOptions_0:
        LJMP    ?Subroutine1 & 0xFFFF
        CFI EndBlock cfiBlock7
//  493 }

        RSEG XDATA_ID:CODE:NOROOT(0)
        DATA
`?<Initializer for zgPollRate>`:
        DW 1000

        RSEG XDATA_ID:CODE:NOROOT(0)
        DATA
`?<Initializer for zgQueuedPollRate>`:
        DW 100

        RSEG XDATA_ID:CODE:NOROOT(0)
        DATA
`?<Initializer for zgResponsePollRate>`:
        DW 100

        RSEG XDATA_ID:CODE:NOROOT(0)
        DATA
`?<Initializer for zgRejoinPollRate>`:
        DW 440

        RSEG XDATA_ID:CODE:NOROOT(0)
        DATA
`?<Initializer for zgMaxDataRetries>`:
        DB 2

        RSEG XDATA_ID:CODE:NOROOT(0)
        DATA
`?<Initializer for zgMaxPollFailureRetries>`:
        DB 2

        RSEG XDATA_ID:CODE:NOROOT(0)
        DATA
`?<Initializer for zgDefaultChannelList>`:
        DD 67108864

        RSEG XDATA_ID:CODE:NOROOT(0)
        DATA
`?<Initializer for zgDefaultStartingScanDuratio`:
        DB 5

        RSEG XDATA_ID:CODE:NOROOT(0)
        DATA
`?<Initializer for zgStackProfile>`:
        DB 3

        RSEG XDATA_ID:CODE:NOROOT(0)
        DATA
`?<Initializer for zgIndirectMsgTimeout>`:
        DB 7

        RSEG XDATA_ID:CODE:NOROOT(0)
        DATA
`?<Initializer for zgSecurityLevel>`:
        DB 5

        RSEG XDATA_ID:CODE:NOROOT(0)
        DATA
`?<Initializer for zgRouteExpiryTime>`:
        DB 30

        RSEG XDATA_ID:CODE:NOROOT(0)
        DATA
`?<Initializer for zgMaxBcastRetires>`:
        DB 2

        RSEG XDATA_ID:CODE:NOROOT(0)
        DATA
`?<Initializer for zgPassiveAckTimeout>`:
        DB 5

        RSEG XDATA_ID:CODE:NOROOT(0)
        DATA
`?<Initializer for zgBcastDeliveryTime>`:
        DB 30

        RSEG XDATA_ID:CODE:NOROOT(0)
        DATA
`?<Initializer for zgConcentratorRadius>`:
        DB 10

        RSEG XDATA_ID:CODE:NOROOT(0)
        DATA
`?<Initializer for zgMaxSourceRoute>`:
        DB 12

        RSEG XDATA_ID:CODE:NOROOT(0)
        DATA
`?<Initializer for zgApscMaxFrameRetries>`:
        DB 3

        RSEG XDATA_ID:CODE:NOROOT(0)
        DATA
`?<Initializer for zgApscAckWaitDurationPolled>`:
        DW 3000

        RSEG XDATA_ID:CODE:NOROOT(0)
        DATA
`?<Initializer for zgApsAckWaitMultiplier>`:
        DB 2

        RSEG XDATA_ID:CODE:NOROOT(0)
        DATA
`?<Initializer for zgApsDefaultMaxBindingTime>`:
        DW 16000

        RSEG XDATA_ID:CODE:NOROOT(0)
        DATA
`?<Initializer for zgPreConfigKeys>`:
        DB 1

        RSEG XDATA_ID:CODE:NOROOT(0)
        DATA
`?<Initializer for zgConfigPANID>`:
        DW 255

        RSEG XDATA_ID:CODE:NOROOT(0)
        DATA
`?<Initializer for zgStartDelay>`:
        DB 10

        RSEG XDATA_ID:CODE:NOROOT(0)
        DATA
`?<Initializer for zgSapiEndpoint>`:
        DB 224

        RSEG BANK_RELAYS:CODE:REORDER:NOROOT(0)
??zgInit?relay:
        LCALL   ?BDISPATCH
        DATA
        DC24    zgInit

        RSEG BANK_RELAYS:CODE:REORDER:NOROOT(0)
??zgReadStartupOptions?relay:
        LCALL   ?BDISPATCH
        DATA
        DC24    zgReadStartupOptions

        RSEG BANK_RELAYS:CODE:REORDER:NOROOT(0)
??zgWriteStartupOptions?relay:
        LCALL   ?BDISPATCH
        DATA
        DC24    zgWriteStartupOptions

        END
//  494 
//  495 /*********************************************************************
//  496 *********************************************************************/
// 
// 489 bytes in segment BANKED_CODE
//  18 bytes in segment BANK_RELAYS
//   6 bytes in segment CODE_C
//  35 bytes in segment XDATA_I
//  35 bytes in segment XDATA_ID
//  28 bytes in segment XDATA_Z
// 
// 548 bytes of CODE  memory
//  63 bytes of XDATA memory
//
//Errors: none
//Warnings: none
