###############################################################################
#                                                                             #
# IAR 8051 C/C++ Compiler V7.30B/W32                    12/Sep/2010  21:57:36 #
# 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 33\ZStack-1.4.3-1.2.1\Project #
#                          s\zstack\ZMain\TI2430DB\ZMain.c                    #
#    Command line       =  -f "C:\Texas Instruments                           #
#                          33\ZStack-1.4.3-1.2.1\Projects\zstack\Project\Loca #
#                          tion\CC2430DB\..\..\..\Tools\CC2430DB\f8wRouter.cf #
#                          g" (-DCPU32MHZ -DFORCE_MAC_NEAR                    #
#                          -DROOT=__near_func -DMAC_CFG_APP_PENDING_QUEUE=TRU #
#                          E -DRTR_NWK -DBLINK_LEDS "-DCONST=const __code"    #
#                          -DGENERIC=__generic) -f "C:\Texas Instruments      #
#                          33\ZStack-1.4.3-1.2.1\Projects\zstack\Project\Loca #
#                          tion\CC2430DB\..\..\..\Tools\CC2430DB\f8wConfig.cf #
#                          g" (-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       #
#                          33\ZStack-1.4.3-1.2.1\Projects\zstack\ZMain\TI2430 #
#                          DB\ZMain.c" -D CC2430EB -D LOCATION_REFNODE -D     #
#                          xNV_RESTORE -D ZTOOL_P1 -D MT_TASK -D              #
#                          POWER_SAVING -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 33\ZStack-1.4.3-1.2.1\Projects\zstack\ #
#                          Project\Location\CC2430DB\RefNode\List\" -lA       #
#                          "C:\Texas Instruments 33\ZStack-1.4.3-1.2.1\Projec #
#                          ts\zstack\Project\Location\CC2430DB\RefNode\List\" #
#                           --diag_suppress Pe001,Pa010 --diag_remark pe550   #
#                          -o "C:\Texas Instruments                           #
#                          33\ZStack-1.4.3-1.2.1\Projects\zstack\Project\Loca #
#                          tion\CC2430DB\RefNode\Obj\" -e                     #
#                          --require_prototypes -z9 --no_code_motion --debug  #
#                          --core=plain --dptr=16,1 --data_model=large        #
#                          --code_model=banked --calling_convention=xdata_ree #
#                          ntrant --place_constants=data --nr_virtual_regs 8  #
#                          -I "C:\Texas Instruments                           #
#                          33\ZStack-1.4.3-1.2.1\Projects\zstack\Project\Loca #
#                          tion\CC2430DB\" -I "C:\Texas Instruments           #
#                          33\ZStack-1.4.3-1.2.1\Projects\zstack\Project\Loca #
#                          tion\CC2430DB\..\SOURCE\" -I "C:\Texas             #
#                          Instruments 33\ZStack-1.4.3-1.2.1\Projects\zstack\ #
#                          Project\Location\CC2430DB\..\..\..\ZMAIN\TI2430DB\ #
#                          " -I "C:\Texas Instruments                         #
#                          33\ZStack-1.4.3-1.2.1\Projects\zstack\Project\Loca #
#                          tion\CC2430DB\..\..\..\..\..\COMPONENTS\MT\" -I    #
#                          "C:\Texas Instruments 33\ZStack-1.4.3-1.2.1\Projec #
#                          ts\zstack\Project\Location\CC2430DB\..\..\..\..\.. #
#                          \COMPONENTS\HAL\INCLUDE\" -I "C:\Texas             #
#                          Instruments 33\ZStack-1.4.3-1.2.1\Projects\zstack\ #
#                          Project\Location\CC2430DB\..\..\..\..\..\COMPONENT #
#                          S\HAL\TARGET\CC2430BB\" -I "C:\Texas Instruments   #
#                          33\ZStack-1.4.3-1.2.1\Projects\zstack\Project\Loca #
#                          tion\CC2430DB\..\..\..\..\..\COMPONENTS\OSAL\MCU\C #
#                          CSOC\" -I "C:\Texas Instruments                    #
#                          33\ZStack-1.4.3-1.2.1\Projects\zstack\Project\Loca #
#                          tion\CC2430DB\..\..\..\..\..\COMPONENTS\OSAL\INCLU #
#                          DE\" -I "C:\Texas Instruments                      #
#                          33\ZStack-1.4.3-1.2.1\Projects\zstack\Project\Loca #
#                          tion\CC2430DB\..\..\..\..\..\COMPONENTS\STACK\AF\" #
#                           -I "C:\Texas Instruments                          #
#                          33\ZStack-1.4.3-1.2.1\Projects\zstack\Project\Loca #
#                          tion\CC2430DB\..\..\..\..\..\COMPONENTS\STACK\NWK\ #
#                          " -I "C:\Texas Instruments                         #
#                          33\ZStack-1.4.3-1.2.1\Projects\zstack\Project\Loca #
#                          tion\CC2430DB\..\..\..\..\..\COMPONENTS\STACK\SEC\ #
#                          " -I "C:\Texas Instruments                         #
#                          33\ZStack-1.4.3-1.2.1\Projects\zstack\Project\Loca #
#                          tion\CC2430DB\..\..\..\..\..\COMPONENTS\STACK\SYS\ #
#                          " -I "C:\Texas Instruments                         #
#                          33\ZStack-1.4.3-1.2.1\Projects\zstack\Project\Loca #
#                          tion\CC2430DB\..\..\..\..\..\COMPONENTS\STACK\ZDO\ #
#                          " -I "C:\Texas Instruments                         #
#                          33\ZStack-1.4.3-1.2.1\Projects\zstack\Project\Loca #
#                          tion\CC2430DB\..\..\..\..\..\COMPONENTS\ZMAC\F8W\" #
#                           -I "C:\Texas Instruments                          #
#                          33\ZStack-1.4.3-1.2.1\Projects\zstack\Project\Loca #
#                          tion\CC2430DB\..\..\..\..\..\COMPONENTS\ZMAC\" -I  #
#                          "C:\Texas Instruments 33\ZStack-1.4.3-1.2.1\Projec #
#                          ts\zstack\Project\Location\CC2430DB\..\..\..\..\.. #
#                          \COMPONENTS\SERVICES\SADDR\" -I "C:\Texas          #
#                          Instruments 33\ZStack-1.4.3-1.2.1\Projects\zstack\ #
#                          Project\Location\CC2430DB\..\..\..\..\..\COMPONENT #
#                          S\SERVICES\SDATA\" -I "C:\Texas Instruments        #
#                          33\ZStack-1.4.3-1.2.1\Projects\zstack\Project\Loca #
#                          tion\CC2430DB\..\..\..\..\..\COMPONENTS\MAC\INCLUD #
#                          E\" -I "C:\Texas Instruments                       #
#                          33\ZStack-1.4.3-1.2.1\Projects\zstack\Project\Loca #
#                          tion\CC2430DB\..\..\..\..\..\COMPONENTS\MAC\HIGH_L #
#                          EVEL\" -I "C:\Texas Instruments                    #
#                          33\ZStack-1.4.3-1.2.1\Projects\zstack\Project\Loca #
#                          tion\CC2430DB\..\..\..\..\..\COMPONENTS\MAC\LOW_LE #
#                          VEL\SRF03\" -I "C:\Texas Instruments               #
#                          33\ZStack-1.4.3-1.2.1\Projects\zstack\Project\Loca #
#                          tion\CC2430DB\..\..\..\..\..\COMPONENTS\MAC\LOW_LE #
#                          VEL\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 33\ZStack-1.4.3-1.2.1\Project #
#                          s\zstack\Project\Location\CC2430DB\RefNode\List\ZM #
#                          ain.lst                                            #
#    Object file        =  C:\Texas Instruments 33\ZStack-1.4.3-1.2.1\Project #
#                          s\zstack\Project\Location\CC2430DB\RefNode\Obj\ZMa #
#                          in.r51                                             #
#                                                                             #
#                                                                             #
###############################################################################

C:\Texas Instruments 33\ZStack-1.4.3-1.2.1\Projects\zstack\ZMain\TI2430DB\ZMain.c
      1          /**************************************************************************************************
      2            Filename:       ZMain.c
      3            Revised:        $Date: 2007-10-27 17:16:54 -0700 (Sat, 27 Oct 2007) $
      4            Revision:       $Revision: 15793 $
      5          
      6            Description:    Startup and shutdown code for ZStack
      7            Notes:          This version targets the Chipcon CC2430DB/CC2430EB
      8          
      9          
     10            Copyright 2005-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          
     45          #include "ZComDef.h"
     46          #include "OSAL.h"
     47          #include "OSAL_Memory.h"
     48          #include "OSAL_Nv.h"
     49          #include "OnBoard.h"

   \                                 In  segment SFR_AN, at 0x81
   \   unsigned char volatile __sfr SP
   \                     `SP`:
   \   000000                DS 1

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

   \                                 In  segment SFR_AN, at 0xbe
   \   unsigned char volatile __sfr SLEEP
   \                     SLEEP:
   \   000000                DS 1

   \                                 In  segment SFR_AN, at 0xc6
   \   unsigned char volatile __sfr CLKCON
   \                     CLKCON:
   \   000000                DS 1

   \                                 In  segment SFR_AN, at 0xfe
   \   unsigned char volatile __sfr P1DIR
   \                     P1DIR:
   \   000000                DS 1
     50          #include "ZMAC.h"
     51          #include "MTEL.h"
     52          
     53          #include "nwk_globals.h"
     54          #include "ZDApp.h"
     55          #include "ssp.h"
     56          #include "ZGlobals.h"
     57          
     58          #ifndef NONWK
     59            #include "AF.h"
     60          #endif
     61          
     62          /* Hal */
     63          //#include "hal_lcd.h"
     64          #if defined ( LCD_SUPPORTED )
     65            #include "lcd128_64.h"
     66          #endif
     67          #include "hal_key.h"
     68          #include "hal_led.h"
     69          #include "hal_adc.h"
     70          #include "hal_drivers.h"
     71          #include "hal_assert.h"
     72          
     73          /*********************************************************************
     74           * MACROS
     75           */
     76          
     77          /*********************************************************************
     78           * CONSTANTS
     79           */
     80          
     81          // LED Flash counter, waiting for default 64-bit address
     82          #define FLASH_COUNT 20000
     83          
     84          // Maximun number of Vdd samples checked before go on
     85          #define MAX_VDD_SAMPLES  3
     86          #define ZMAIN_VDD_LIMIT  HAL_ADC_VDD_LIMIT_4
     87          
     88          /*********************************************************************
     89           * TYPEDEFS
     90           */
     91          
     92          /*********************************************************************
     93           * GLOBAL VARIABLES
     94           */
     95          
     96          /*********************************************************************
     97           * EXTERNAL VARIABLES
     98           */
     99          
    100          /*********************************************************************
    101           * EXTERNAL FUNCTIONS
    102           */
    103          
    104          extern __near_func uint8 GetCodeByte(uint32);
    105          
    106          extern bool HalAdcCheckVdd (uint8 limit);
    107          //extern void halWait(BYTE wait);
    108          
    109          /*********************************************************************
    110           * LOCAL VARIABLES
    111           */
    112          
    113          /*********************************************************************
    114           * ZMAIN API JUMP FUNCTIONS
    115           *
    116           * If the MINIMIZE_ROOT compile flag is defined, ZMAIN API functions
    117           * are implemented as "jump functions" located in the ROOT segment,
    118           * as expected by the NWK object libraries. This allows the actual
    119           * ZMAIN function bodies to locate outside ROOT memory, increasing
    120           * space for user defined constants, strings, etc in ROOT memory.
    121           *
    122           * If the MINIMIZE_ROOT compile flag in not defined, the ZMAIN API
    123           * functions are aliased to the similarly-named function bodies and
    124           * located in the ROOT segment with no "jump function" overhead.
    125           * This is the default behavior which produces smaller overall code
    126           * size and maximizes available code space in BANK1...BANK3.
    127           *
    128           */
    129          
    130          #ifdef MINIMIZE_ROOT
    131            // ZMAIN functions are not forced into ROOT segment
    132            #define ZSEG
    133          #else
    134            // ZMAIN functions are forced into ROOT segment
    135            #define ZSEG ROOT
    136          #endif
    137          
    138          /*********************************************************************
    139           * LOCAL FUNCTIONS
    140           */
    141          
    142          static ZSEG void zmain_dev_info( void );
    143          static ZSEG void zmain_ext_addr( void );
    144          static ZSEG void zmain_ram_init( void );
    145          static ZSEG void zmain_vdd_check( void );
    146          
    147          #ifdef LCD_SUPPORTED
    148          static ZSEG void zmain_lcd_init( void );
    149          #endif
    150          
    151          /*********************************************************************
    152           * @fn      main
    153           * @brief   First function called after startup.
    154           * @return  don't care
    155           *********************************************************************/

   \                                 In  segment NEAR_CODE, align 1, keep-with-next
    156          ZSEG int main( void )
   \                     main:
    157          {
   \   000000                ; Auto size: 0
    158            // Turn off interrupts
    159            osal_int_disable( INTS_ALL );
   \   000000                ; Setup parameters for call to function osal_int_disable
   \   000000   79FF         MOV     R1,#-0x1
   \   000002   12....       LCALL   ??osal_int_disable?relay
    160          
    161            // Initialize HAL
    162            HAL_BOARD_INIT();
   \   000005   53BEFB       ANL     0xbe,#0xfb
   \                     ??main_0:
   \   000008   E5BE         MOV     A,0xbe
   \   00000A   A2E6         MOV     C,0xE0 /* A   */.6
   \   00000C   50FA         JNC     ??main_0
   \   00000E   00           NOP
   \   00000F   78F8         MOV     R0,#-0x8
   \   000011   7901         MOV     R1,#0x1
   \                     ??main_1:
   \   000013   00           NOP
   \   000014   E8           MOV     A,R0
   \   000015   24FF         ADD     A,#-0x1
   \   000017   18           DEC     R0
   \   000018   E9           MOV     A,R1
   \   000019   34FF         ADDC    A,#-0x1
   \   00001B   F9           MOV     R1,A
   \   00001C   E8           MOV     A,R0
   \   00001D   7001         JNZ     ??main_2
   \   00001F   E9           MOV     A,R1
   \                     ??main_2:
   \   000020   70F1         JNZ     ??main_1
   \   000022   75C600       MOV     0xc6,#0x0
   \                     ??main_3:
   \   000025   E5C6         MOV     A,0xc6
   \   000027   70FC         JNZ     ??main_3
   \   000029   43BE04       ORL     0xbe,#0x4
   \   00002C   43FE01       ORL     0xfe,#0x1
    163          
    164            // Make sure supply voltage is high enough to run
    165            zmain_vdd_check();
   \   00002F   7E00         MOV     R6,#0x0
   \   000031   7F00         MOV     R7,#0x0
   \                     ??main_4:
   \   000033                ; Setup parameters for call to function HalAdcCheckVdd
   \   000033   7904         MOV     R1,#0x4
   \   000035   12....       LCALL   ??HalAdcCheckVdd?relay
   \   000038   E9           MOV     A,R1
   \   000039   601B         JZ      ??main_5
   \   00003B   0E           INC     R6
   \   00003C                ; Setup parameters for call to function Onboard_wait
   \   00003C   7A10         MOV     R2,#0x10
   \   00003E   7B27         MOV     R3,#0x27
   \   000040   12....       LCALL   ??Onboard_wait?relay
   \   000043   EE           MOV     A,R6
   \   000044   6020         JZ      ??main_6
   \   000046   C3           CLR     C
   \   000047   9403         SUBB    A,#0x3
   \   000049   40E8         JC      ??main_4
   \   00004B   D290         SETB    0x90.0
    166          
    167            // Initialize stack memory
    168            zmain_ram_init();
   \   00004D   78..         MOV     R0,#(SFB(XSP) & 0xff)
   \   00004F   8682         MOV     DPL,@R0
   \   000051   08           INC     R0
   \   000052   8683         MOV     DPH,@R0
   \   000054   802C         SJMP    ??main_7
   \                     ??main_5:
   \   000056   7E00         MOV     R6,#0x0
   \   000058                ; Setup parameters for call to function Onboard_wait
   \   000058   7A50         MOV     R2,#0x50
   \   00005A   7BC3         MOV     R3,#-0x3d
   \   00005C   12....       LCALL   ??Onboard_wait?relay
   \   00005F                ; Setup parameters for call to function Onboard_wait
   \   00005F   7A50         MOV     R2,#0x50
   \   000061   7BC3         MOV     R3,#-0x3d
   \   000063   12....       LCALL   ??Onboard_wait?relay
   \                     ??main_6:
   \   000066   EF           MOV     A,R7
   \   000067   7004         JNZ     ??main_8
   \   000069   7A01         MOV     R2,#0x1
   \   00006B   8002         SJMP    ??main_9
   \                     ??main_8:
   \   00006D   7A00         MOV     R2,#0x0
   \                     ??main_9:
   \   00006F   EA           MOV     A,R2
   \   000070   FF           MOV     R7,A
   \   000071   60C0         JZ      ??main_4
   \   000073   A290         MOV     C,0x90.0
   \   000075   5004         JNC     ??main_10
   \   000077   C290         CLR     0x90.0
   \   000079   80B8         SJMP    ??main_4
   \                     ??main_10:
   \   00007B   D290         SETB    0x90.0
   \   00007D   80B4         SJMP    ??main_4
   \                     ??main_11:
   \   00007F   74CD         MOV     A,#-0x33
   \   000081   F0           MOVX    @DPTR,A
   \                     ??main_7:
   \   000082   12....       LCALL   ?Subroutine0
   \                     ??CrossCallReturnLabel_0:
   \   000085   C3           CLR     C
   \   000086   74..         MOV     A,#(SFB(XSTACK) & 0xff)
   \   000088   9582         SUBB    A,DPL
   \   00008A   74..         MOV     A,#((SFB(XSTACK) >> 8) & 0xff)
   \   00008C   9583         SUBB    A,DPH
   \   00008E   40EF         JC      ??main_11
   \   000090   7582..       MOV     DPL,#((SFE(ISTACK) + 255) & 0xff)
   \   000093   7583..       MOV     DPH,#(((SFE(ISTACK) - 1) >> 8) & 0xff)
   \   000096   8004         SJMP    ??main_12
   \                     ??main_13:
   \   000098   A882         MOV     R0,DPL
   \   00009A   76CD         MOV     @R0,#-0x33
   \                     ??main_12:
   \   00009C   E581         MOV     A,0x81
   \   00009E   F5..         MOV     ?V0 + 0,A
   \   0000A0   12....       LCALL   ?Subroutine0
   \                     ??CrossCallReturnLabel_1:
   \   0000A3   75..00       MOV     ?V0 + 1,#0x0
   \   0000A6   C3           CLR     C
   \   0000A7   E5..         MOV     A,?V0 + 0
   \   0000A9   9582         SUBB    A,DPL
   \   0000AB   E4           CLR     A
   \   0000AC   9583         SUBB    A,DPH
   \   0000AE   40E8         JC      ??main_13
    169          
    170            // Initialize board I/O
    171            InitBoard( OB_COLD );
   \   0000B0                ; Setup parameters for call to function InitBoard
   \   0000B0   7900         MOV     R1,#0x0
   \   0000B2   12....       LCALL   ??InitBoard?relay
    172          
    173            // Initialze HAL drivers
    174            HalDriverInit();
   \   0000B5                ; Setup parameters for call to function HalDriverInit
   \   0000B5   12....       LCALL   ??HalDriverInit?relay
    175          
    176            // Initialize NV System
    177            osal_nv_init( NULL );
   \   0000B8                ; Setup parameters for call to function osal_nv_init
   \   0000B8   7A00         MOV     R2,#0x0
   \   0000BA   7B00         MOV     R3,#0x0
   \   0000BC   12....       LCALL   ??osal_nv_init?relay
    178          
    179            // Determine the extended address
    180            zmain_ext_addr();
   \   0000BF                ; Setup parameters for call to function zmain_ext_addr
   \   0000BF   12....       LCALL   zmain_ext_addr
    181          
    182            // Initialize basic NV items
    183            zgInit();
   \   0000C2                ; Setup parameters for call to function zgInit
   \   0000C2   12....       LCALL   ??zgInit?relay
    184          
    185            // Initialize the MAC
    186            ZMacInit();
   \   0000C5                ; Setup parameters for call to function ZMacInit
   \   0000C5   12....       LCALL   ZMacInit
    187          
    188          #ifndef NONWK
    189            // Since the AF isn't a task, call it's initialization routine
    190            afInit();
   \   0000C8                ; Setup parameters for call to function afInit
   \   0000C8   12....       LCALL   ??afInit?relay
    191          #endif
    192          
    193          #ifdef LCD_SUPPORTED
    194            HalLcdInit();
    195          #endif
    196              // Initialize the operating system
    197            osal_init_system();
   \   0000CB                ; Setup parameters for call to function osal_init_system
   \   0000CB   12....       LCALL   ??osal_init_system?relay
    198          
    199            // Allow interrupts
    200            osal_int_enable( INTS_ALL );
   \   0000CE                ; Setup parameters for call to function osal_int_enable
   \   0000CE   79FF         MOV     R1,#-0x1
   \   0000D0   12....       LCALL   ??osal_int_enable?relay
    201          
    202            // Final board initialization
    203            InitBoard( OB_READY );
   \   0000D3                ; Setup parameters for call to function InitBoard
   \   0000D3   7902         MOV     R1,#0x2
   \   0000D5   12....       LCALL   ??InitBoard?relay
    204            //HalLcdInit();
    205            // Display information about this device
    206            zmain_dev_info();
    207            /* Display the device info on the LCD */
    208          #ifdef LCD_SUPPORTED
    209            zmain_lcd_init();
    210          #endif
    211          
    212            osal_start_system(); // No Return from here
   \   0000D8                ; Setup parameters for call to function osal_start_system
   \   0000D8   12....       LCALL   ??osal_start_system?relay
    213          } // main()
   \   0000DB   7A00         MOV     R2,#0x0
   \   0000DD   7B00         MOV     R3,#0x0
   \   0000DF   22           RET
   \   0000E0                REQUIRE P1DIR
   \   0000E0                REQUIRE SLEEP
   \   0000E0                REQUIRE CLKCON
   \   0000E0                REQUIRE `SP`
   \   0000E0                REQUIRE _A_P1
    214          
    215          /*********************************************************************
    216           * @fn      zmain_vdd_check
    217           * @brief   Check if the Vdd is OK to run the processor.
    218           * @return  Return if Vdd is ok; otherwise, flash LED, then reset
    219           *********************************************************************/
    220          static ZSEG void zmain_vdd_check( void )
    221          {
    222            uint8 vdd_passed_count = 0;
    223            bool toggle = 0;
    224          
    225            // Repeat getting the sample until number of failures or successes hits MAX
    226            // then based on the count value, determine if the device is ready or not
    227            while ( vdd_passed_count < MAX_VDD_SAMPLES )
    228            {
    229              if ( HalAdcCheckVdd (ZMAIN_VDD_LIMIT) )
    230              {
    231                vdd_passed_count++;    // Keep track # times Vdd passes in a row
    232                MicroWait (10000);     // Wait 10ms to try again
    233              }
    234              else
    235              {
    236                vdd_passed_count = 0;  // Reset passed counter
    237                MicroWait (50000);     // Wait 50ms
    238                MicroWait (50000);     // Wait another 50ms to try again
    239              }
    240          
    241              /* toggle LED1 and LED2 */
    242              if (vdd_passed_count == 0)
    243              {
    244                if ((toggle = !(toggle)))
    245                  HAL_TOGGLE_LED1();
    246                else
    247                  HAL_TOGGLE_LED2();
    248              }
    249            }
    250          
    251            /* turn off LED1 */
    252            HAL_TURN_OFF_LED1();
    253            HAL_TURN_OFF_LED2();
    254          }
    255          
    256          /*********************************************************************
    257           * @fn      zmain_ext_addr
    258           * @brief   Makes extended address if none exists.
    259           * @return  none
    260           *********************************************************************/

   \                                 In  segment NEAR_CODE, align 1, keep-with-next
    261          static ZSEG void zmain_ext_addr( void )
   \                     zmain_ext_addr:
    262          {
   \   000000   74F7         MOV     A,#-0x9
   \   000002   12....       LCALL   ?FUNC_ENTER_XDATA
   \   000005                ; Saved register size: 9
   \   000005                ; Auto size: 0
    263            uint8 i;
    264            uint8 led;
    265            uint8 tmp;
    266            uint8 *xad;
    267            uint16 AtoD;
    268          
    269            // Initialize extended address in NV
    270            osal_nv_item_init( ZCD_NV_EXTADDR, Z_EXTADDR_LEN, NULL );
   \   000005                ; Setup parameters for call to function osal_nv_item_init
   \   000005   75..00       MOV     ?V0 + 0,#0x0
   \   000008   75..00       MOV     ?V0 + 1,#0x0
   \   00000B   78..         MOV     R0,#?V0 + 0
   \   00000D   12....       LCALL   ?PUSH_XSTACK_I_TWO
   \   000010   7C08         MOV     R4,#0x8
   \   000012   7D00         MOV     R5,#0x0
   \   000014   7A01         MOV     R2,#0x1
   \   000016   7B00         MOV     R3,#0x0
   \   000018   12....       LCALL   ??osal_nv_item_init?relay
   \   00001B   7402         MOV     A,#0x2
   \   00001D   12....       LCALL   ?DEALLOC_XSTACK8
    271            osal_nv_read( ZCD_NV_EXTADDR, 0, Z_EXTADDR_LEN, &aExtendedAddress );
   \   000020                ; Setup parameters for call to function osal_nv_read
   \   000020   75....       MOV     ?V0 + 0,#(aExtendedAddress & 0xff)
   \   000023   75....       MOV     ?V0 + 1,#((aExtendedAddress >> 8) & 0xff)
   \   000026   78..         MOV     R0,#?V0 + 0
   \   000028   12....       LCALL   ?PUSH_XSTACK_I_TWO
   \   00002B   75..08       MOV     ?V0 + 0,#0x8
   \   00002E   75..00       MOV     ?V0 + 1,#0x0
   \   000031   78..         MOV     R0,#?V0 + 0
   \   000033   12....       LCALL   ?PUSH_XSTACK_I_TWO
   \   000036   7C00         MOV     R4,#0x0
   \   000038   7D00         MOV     R5,#0x0
   \   00003A   7A01         MOV     R2,#0x1
   \   00003C   7B00         MOV     R3,#0x0
   \   00003E   12....       LCALL   ??osal_nv_read?relay
   \   000041   7404         MOV     A,#0x4
   \   000043   12....       LCALL   ?DEALLOC_XSTACK8
    272          
    273            // Check for uninitialized value (erased EEPROM = 0xFF)
    274            xad = (uint8*)&aExtendedAddress;
   \   000046   78..         MOV     R0,#(aExtendedAddress & 0xff)
   \   000048   79..         MOV     R1,#((aExtendedAddress >> 8) & 0xff)
    275            for ( i = 0; i < Z_EXTADDR_LEN; i++ )
   \   00004A   7C00         MOV     R4,#0x0
    276              if ( *xad++ != 0xFF ) return;
   \                     ??zmain_ext_addr_0:
   \   00004C   E8           MOV     A,R0
   \   00004D   FA           MOV     R2,A
   \   00004E   E9           MOV     A,R1
   \   00004F   FB           MOV     R3,A
   \   000050   8A82         MOV     DPL,R2
   \   000052   8B83         MOV     DPH,R3
   \   000054   A3           INC     DPTR
   \   000055   A882         MOV     R0,DPL
   \   000057   A983         MOV     R1,DPH
   \   000059   8A82         MOV     DPL,R2
   \   00005B   8B83         MOV     DPH,R3
   \   00005D   E0           MOVX    A,@DPTR
   \   00005E   64FF         XRL     A,#0xff
   \   000060   705C         JNZ     ??zmain_ext_addr_1
   \   000062   0C           INC     R4
   \   000063   EC           MOV     A,R4
   \   000064   C3           CLR     C
   \   000065   9408         SUBB    A,#0x8
   \   000067   40E3         JC      ??zmain_ext_addr_0
    277          
    278          #ifdef ZDO_COORDINATOR
    279            tmp = 0x10;
    280          #else
    281            tmp = 0x20;
   \   000069   7B20         MOV     R3,#0x20
    282          #endif
    283            // Initialize with a simple pattern
    284            xad = (uint8*)&aExtendedAddress;
   \   00006B   78..         MOV     R0,#(aExtendedAddress & 0xff)
   \   00006D   79..         MOV     R1,#((aExtendedAddress >> 8) & 0xff)
    285            for ( i = 0; i < Z_EXTADDR_LEN; i++ )
   \   00006F   7A08         MOV     R2,#0x8
    286              *xad++ = tmp++;
   \                     ??zmain_ext_addr_2:
   \   000071   EB           MOV     A,R3
   \   000072   8882         MOV     DPL,R0
   \   000074   8983         MOV     DPH,R1
   \   000076   F0           MOVX    @DPTR,A
   \   000077   0B           INC     R3
   \   000078   A3           INC     DPTR
   \   000079   A882         MOV     R0,DPL
   \   00007B   A983         MOV     R1,DPH
   \   00007D   1A           DEC     R2
   \   00007E   EA           MOV     A,R2
   \   00007F   70F0         JNZ     ??zmain_ext_addr_2
    287          
    288            // Flash LED1 until user hits SW5
    289            led = HAL_LED_MODE_OFF;
   \   000081   75..00       MOV     ?V0 + 0,#0x0
   \   000084   8018         SJMP    ??zmain_ext_addr_3
    290            while ( HAL_KEY_SW_5 != HalKeyRead() )
    291            {
    292              MicroWait( 62500 );
   \                     ??zmain_ext_addr_4:
   \   000086                ; Setup parameters for call to function Onboard_wait
   \   000086   7A24         MOV     R2,#0x24
   \   000088   7BF4         MOV     R3,#-0xc
   \   00008A   12....       LCALL   ??Onboard_wait?relay
    293              HalLedSet( HAL_LED_1, led^=HAL_LED_MODE_ON );  // Toggle the LED
   \   00008D   63..01       XRL     ?V0 + 0,#0x1
   \   000090                ; Setup parameters for call to function HalLedSet
   \   000090   AA..         MOV     R2,?V0 + 0
   \   000092   7901         MOV     R1,#0x1
   \   000094   12....       LCALL   ??HalLedSet?relay
    294              MicroWait( 62500 );
   \   000097                ; Setup parameters for call to function Onboard_wait
   \   000097   7A24         MOV     R2,#0x24
   \   000099   7BF4         MOV     R3,#-0xc
   \   00009B   12....       LCALL   ??Onboard_wait?relay
    295            }
   \                     ??zmain_ext_addr_3:
   \   00009E                ; Setup parameters for call to function HalKeyRead
   \   00009E   12....       LCALL   ??HalKeyRead?relay
   \   0000A1   E9           MOV     A,R1
   \   0000A2   6404         XRL     A,#0x4
   \   0000A4   70E0         JNZ     ??zmain_ext_addr_4
    296            HalLedSet( HAL_LED_1, HAL_LED_MODE_OFF );
   \   0000A6                ; Setup parameters for call to function HalLedSet
   \   0000A6   7A00         MOV     R2,#0x0
   \   0000A8   7901         MOV     R1,#0x1
   \   0000AA   12....       LCALL   ??HalLedSet?relay
    297          
    298            // Plug AtoD data into lower bytes
    299            AtoD = HalAdcRead (HAL_ADC_CHANNEL_7, HAL_ADC_RESOLUTION_10);
   \   0000AD                ; Setup parameters for call to function HalAdcRead
   \   0000AD   7A02         MOV     R2,#0x2
   \   0000AF   7907         MOV     R1,#0x7
   \   0000B1   12....       LCALL   ??HalAdcRead?relay
    300            xad = (uint8*)&aExtendedAddress;
    301            *xad++ = LO_UINT16( AtoD );
   \   0000B4   EA           MOV     A,R2
   \   0000B5   90....       MOV     DPTR,#aExtendedAddress
   \   0000B8   F0           MOVX    @DPTR,A
    302            *xad = HI_UINT16( AtoD );
   \   0000B9   EB           MOV     A,R3
   \   0000BA   90....       MOV     DPTR,#(aExtendedAddress + 1)
   \   0000BD   F0           MOVX    @DPTR,A
    303          
    304          #if !defined( ZTOOL_PORT ) || defined( ZPORT ) || defined( NV_RESTORE )
    305            // If no support for Z-Tool serial I/O,
    306            // Write temporary 64-bit address to NV
    307            osal_nv_write( ZCD_NV_EXTADDR, 0, Z_EXTADDR_LEN, &aExtendedAddress );
    308          #endif
    309          }
   \                     ??zmain_ext_addr_1:
   \   0000BE   7F02         MOV     R7,#0x2
   \   0000C0   02....       LJMP    ?FUNC_LEAVE_XDATA

   \                                 In  segment NEAR_CODE, align 1, keep-with-next
   \                     ?Subroutine0:
   \   000000   E582         MOV     A,DPL
   \   000002   24FF         ADD     A,#-0x1
   \   000004   F582         MOV     DPL,A
   \   000006   E583         MOV     A,DPH
   \   000008   34FF         ADDC    A,#-0x1
   \   00000A   F583         MOV     DPH,A
   \   00000C   22           RET

   \                                 In  segment XSP, align 1
    310          
    311          /*********************************************************************
    312           * @fn      zmain_dev_info
    313           * @brief   Gets or makes extended address.
    314           * @return  none
    315           *********************************************************************/
    316          static ZSEG void zmain_dev_info ( void )
    317          {
    318          #ifdef LCD_SUPPORTED
    319            uint8 i;
    320            uint8 ch;
    321            uint8 *xad;
    322            unsigned char lcd_buf[18];
    323          
    324            // Display the extended address
    325            xad = (uint8*)&aExtendedAddress + Z_EXTADDR_LEN - 1;
    326            for ( i = 0; i < Z_EXTADDR_LEN*2; xad-- ) {
    327              ch = (*xad >> 4) & 0x0F;
    328              lcd_buf[i++] = ch + (( ch < 10 ) ? '0' : '7');
    329              ch = *xad & 0x0F;
    330              lcd_buf[i++] = ch + (( ch < 10 ) ? '0' : '7');
    331            }
    332            lcd_buf[Z_EXTADDR_LEN*2] = '\0';
    333            //HalLcdWriteString( "IEEE Address:", HAL_LCD_LINE_1 );
    334            //HalLcdWriteString( (char*)lcd_buf, HAL_LCD_LINE_2 );
    335             Print8(HAL_LCD_LINE_3 ,0,"IEEE Address:",1);
    336             Print8(HAL_LCD_LINE_4,0,lcd_buf,1);
    337          #endif // LCD
    338          }
    339          
    340          /*********************************************************************
    341           * @fn      zmain_ram_init
    342           * @brief   Initialize ram for stack "high-water-mark" observations.
    343           * @return  none
    344           *********************************************************************/
    345          static ZSEG void zmain_ram_init( void )
    346          {
    347            uint8 *end;
    348            uint8 *ptr;
    349          
    350            // Initialize the call (parameter) stack
    351            end = (uint8*)CSTK_BEG;  // Lower end
    352            ptr = (uint8*)(*( __idata uint16*)(CSTK_PTR));  // Upper end
    353            while ( --ptr > end )
    354              *ptr = STACK_INIT_VALUE;
    355          
    356            // Initialize the return (address) stack
    357            ptr = (uint8*)RSTK_END - 1;  // Upper end
    358            while ( --ptr > (uint8*)SP )
    359              *(__idata uint8*)ptr = STACK_INIT_VALUE;
    360          }
    361          
    362          #ifdef LCD_SUPPORTED
    363          /*********************************************************************
    364           * @fn      zmain_lcd_init
    365           * @brief   Initialize LCD at start up.
    366           * @return  none
    367           *********************************************************************/
    368          static ZSEG void zmain_lcd_init ( void )
    369          {
    370          #ifdef LCD_SUPPORTED
    371           // if ( LcdLine1 == NULL )
    372            {
    373              //HalLcdWriteString( "Figure8 Wireless", HAL_LCD_LINE_1 );
    374              Print8(HAL_LCD_LINE_1,20,"WXL ZigBee",1);
    375          
    376          #if defined( MT_MAC_FUNC )
    377          #if defined( ZDO_COORDINATOR )
    378                //HalLcdWriteString( "MAC-MT Coord", HAL_LCD_LINE_2 );
    379              Print8(HAL_LCD_LINE_2,0,"MAC-MT Coord",1);
    380          #else
    381                //HalLcdWriteString( "MAC-MT Device", HAL_LCD_LINE_2 );
    382              Print8(HAL_LCD_LINE_2,0,"MAC-MT Device"",1);
    383          #endif // ZDO
    384          #elif defined( MT_NWK_FUNC )
    385          #if defined( ZDO_COORDINATOR )
    386               // HalLcdWriteString( "NWK Coordinator", HAL_LCD_LINE_2 );
    387               Print8(HAL_LCD_LINE_2,0,"NWK Coordinator",1);
    388          #else
    389                //HalLcdWriteString( "NWK Device", HAL_LCD_LINE_2 );
    390                Print8(HAL_LCD_LINE_2,0,"NWK Device",1);
    391          #endif // ZDO
    392          #endif // MT_FUNC
    393            }
    394          #endif // LCD_SD
    395          }
    396          #endif
    397          
    398          /*********************************************************************
    399          *********************************************************************/

   Maximum stack usage in bytes:

     Function               ISTACK PSTACK XSTACK
     --------               ------ ------ ------
     main                       1      0      0
       -> osal_int_disable      0      0      0
       -> HalAdcCheckVdd        0      0      0
       -> Onboard_wait          0      0      0
       -> Onboard_wait          0      0      0
       -> Onboard_wait          0      0      0
       -> InitBoard             0      0      0
       -> HalDriverInit         0      0      0
       -> osal_nv_init          0      0      0
       -> zmain_ext_addr        0      0      0
       -> zgInit                0      0      0
       -> ZMacInit              0      0      0
       -> afInit                0      0      0
       -> osal_init_system      0      0      0
       -> osal_int_enable       0      0      0
       -> InitBoard             0      0      0
       -> osal_start_system     0      0      0
     zmain_ext_addr             1      0     13
       -> osal_nv_item_init     0      0     22
       -> osal_nv_read          0      0     26
       -> Onboard_wait          0      0     18
       -> HalLedSet             0      0     18
       -> Onboard_wait          0      0     18
       -> HalKeyRead            0      0     18
       -> HalLedSet             0      0     18
       -> HalAdcRead            0      0     18


   Segment part sizes:

     Function/Label Bytes
     -------------- -----
     SP                1
     _A_P1             1
     SLEEP             1
     CLKCON            1
     P1DIR             1
     main            224
     zmain_ext_addr  195
     ?Subroutine0     13

 
 432 bytes in segment NEAR_CODE
   5 bytes in segment SFR_AN
 
 432 bytes of CODE memory
   0 bytes of DATA memory (+ 5 bytes shared)

Errors: none
Warnings: none
