###############################################################################
#                                                                             #
# IAR 8051 C/C++ Compiler V7.30B/W32                    12/Sep/2010  21:57:33 #
# 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\Compone #
#                          nts\mac\low_level\srf03\mac_radio.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\Components\mac\low_level\srf #
#                          03\mac_radio.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\ma #
#                          c_radio.lst                                        #
#    Object file        =  C:\Texas Instruments 33\ZStack-1.4.3-1.2.1\Project #
#                          s\zstack\Project\Location\CC2430DB\RefNode\Obj\mac #
#                          _radio.r51                                         #
#                                                                             #
#                                                                             #
###############################################################################

C:\Texas Instruments 33\ZStack-1.4.3-1.2.1\Components\mac\low_level\srf03\mac_radio.c
      1          /**************************************************************************************************
      2            Filename:       mac_radio.c
      3            Revised:        $Date: 2007-10-29 22:38:47 -0700 (Mon, 29 Oct 2007) $
      4            Revision:       $Revision: 15812 $
      5          
      6            Description:    Describe the purpose and contents of the file.
      7          
      8          
      9            Copyright 2006-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          
     45          /* hal */
     46          #include "hal_types.h"
     47          
     48          /* high-level */
     49          #include "mac_pib.h"
     50          
     51          /* exported low-level */
     52          #include "mac_low_level.h"
     53          
     54          /* low-level specific */
     55          #include "mac_radio.h"
     56          #include "mac_tx.h"
     57          #include "mac_rx.h"
     58          #include "mac_rx_onoff.h"
     59          #include "mac_sleep.h"
     60          #include "mac_backoff_timer.h"
     61          
     62          /* target specific */
     63          #include "mac_radio_defs.h"

   \                                 In  segment SFR_AN, at 0xa8
   \   union <unnamed> volatile __sfr _A_IEN0
   \                     _A_IEN0:
   \   000000                DS 1
     64          
     65          /* debug */
     66          #include "mac_assert.h"
     67          
     68          
     69          /* ------------------------------------------------------------------------------------------------
     70           *                                          Includes
     71           * ------------------------------------------------------------------------------------------------
     72           */
     73          #define ED_RF_POWER_MIN_DBM   (MAC_RADIO_RECEIVER_SENSITIVITY_DBM + MAC_SPEC_ED_MIN_DBM_ABOVE_RECEIVER_SENSITIVITY)
     74          #define ED_RF_POWER_MAX_DBM   MAC_RADIO_RECEIVER_SATURATION_DBM
     75          
     76          
     77          /* ------------------------------------------------------------------------------------------------
     78           *                                        Global Variables
     79           * ------------------------------------------------------------------------------------------------
     80           */

   \                                 In  segment XDATA_Z, align 1, keep-with-next
     81          uint8 macPhyTxPower;
   \                     macPhyTxPower:
   \   000000                DS 1
   \   000001                REQUIRE __INIT_XDATA_Z

   \                                 In  segment XDATA_Z, align 1, keep-with-next
     82          uint8 macPhyChannel;
   \                     macPhyChannel:
   \   000000                DS 1
   \   000001                REQUIRE __INIT_XDATA_Z
     83          
     84          
     85          /* ------------------------------------------------------------------------------------------------
     86           *                                        Local Variables
     87           * ------------------------------------------------------------------------------------------------
     88           */

   \                                 In  segment XDATA_Z, align 1, keep-with-next
     89          static uint8 reqChannel;
   \                     reqChannel:
   \   000000                DS 1
   \   000001                REQUIRE __INIT_XDATA_Z

   \                                 In  segment XDATA_Z, align 1, keep-with-next
     90          static uint8 reqTxPower;
   \                     reqTxPower:
   \   000000                DS 1
   \   000001                REQUIRE __INIT_XDATA_Z
     91          
     92          
     93          /* ------------------------------------------------------------------------------------------------
     94           *                                        Local Functions
     95           * ------------------------------------------------------------------------------------------------
     96           */
     97          static uint8 radioComputeED(int8 rssiDbm);
     98          
     99          
    100          /**************************************************************************************************
    101           * @fn          macRadioInit
    102           *
    103           * @brief       Initialize radio software.
    104           *
    105           * @param       none
    106           *
    107           * @return      none
    108           **************************************************************************************************
    109           */

   \                                 In  segment BANKED_CODE, align 1, keep-with-next
    110          void macRadioInit(void)
   \                     macRadioInit:
    111          {
   \   000000   C082         PUSH    DPL
   \   000002   C083         PUSH    DPH
   \   000004                ; Saved register size: 2
   \   000004                ; Auto size: 0
    112            /* variable initialization for this module */
    113            reqChannel    = MAC_RADIO_CHANNEL_DEFAULT;
   \   000004   740B         MOV     A,#0xb
   \   000006   90....       MOV     DPTR,#reqChannel
   \   000009   F0           MOVX    @DPTR,A
    114            macPhyChannel = MAC_RADIO_CHANNEL_DEFAULT;
   \   00000A   90....       MOV     DPTR,#macPhyChannel
   \   00000D   F0           MOVX    @DPTR,A
    115            reqTxPower    = MAC_RADIO_TX_POWER_DEFAULT;
   \   00000E   741F         MOV     A,#0x1f
   \   000010   90....       MOV     DPTR,#reqTxPower
   \   000013   F0           MOVX    @DPTR,A
    116            macPhyTxPower = MAC_RADIO_TX_POWER_DEFAULT;
   \   000014   90....       MOV     DPTR,#macPhyTxPower
   \   000017   80..         SJMP    ??Subroutine0_0
    117          }

   \                                 In  segment BANKED_CODE, align 1, keep-with-next
   \                     ?Subroutine0:
   \   000000   90DF4B       MOV     DPTR,#-0x20b5
   \                     ??Subroutine0_0:
   \   000003   F0           MOVX    @DPTR,A
   \                     ??Subroutine0_1:
   \   000004   D083         POP     DPH
   \   000006   D082         POP     DPL
   \   000008   02....       LJMP    ?BRET
    118          
    119          
    120          /**************************************************************************************************
    121           * @fn          macRadioReset
    122           *
    123           * @brief       Resets the radio module.
    124           *
    125           * @param       none
    126           *
    127           * @return      none
    128           **************************************************************************************************
    129           */

   \                                 In  segment BANKED_CODE, align 1, keep-with-next
    130          void macRadioReset(void)
   \                     macRadioReset:
    131          {
   \   000000   C082         PUSH    DPL
   \   000002   C083         PUSH    DPH
   \   000004                ; Saved register size: 2
   \   000004                ; Auto size: 0
    132            macRadioStopScan();
   \   000004                ; Setup parameters for call to function macRadioStopScan
   \   000004   12....       LCALL   ??macRadioStopScan?relay
    133            macRadioEnergyDetectStop();
   \   000007                ; Setup parameters for call to function macRadioEnergyDetectStop
   \   000007   12....       LCALL   ??macRadioEnergyDetectStop?relay
    134          }
   \   00000A   80..         SJMP    ??Subroutine0_1
    135          
    136          
    137          /**************************************************************************************************
    138           * @fn          macRadioRandomByte
    139           *
    140           * @brief       Return a random byte derived from previously set random seed.
    141           *
    142           * @param       none
    143           *
    144           * @return      a random byte
    145           **************************************************************************************************
    146           */

   \                                 In  segment BANKED_CODE, align 1, keep-with-next
    147          uint8 macRadioRandomByte(void)
   \                     macRadioRandomByte:
    148          {
   \   000000   C082         PUSH    DPL
   \   000002   C083         PUSH    DPH
   \   000004                ; Saved register size: 2
   \   000004                ; Auto size: 0
    149            return(MAC_RADIO_RANDOM_BYTE());
   \   000004                ; Setup parameters for call to function macMcuRandomByte
   \   000004   12....       LCALL   ??macMcuRandomByte?relay
   \   000007   80..         SJMP    ??Subroutine0_1
    150          }
    151          
    152          
    153          /**************************************************************************************************
    154           * @fn          macRadioSetPanCoordinator
    155           *
    156           * @brief       Configure the pan coordinator status of the radio
    157           *
    158           * @param       panCoordFlag - non-zero to configure radio to be pan coordinator
    159           *                             zero to configure radio as NON pan coordinator
    160           *
    161           * @return      none
    162           **************************************************************************************************
    163           */

   \                                 In  segment BANKED_CODE, align 1, keep-with-next
    164          void macRadioSetPanCoordinator(uint8 panCoordFlag)
   \                     macRadioSetPanCoordinator:
    165          {
   \   000000   C082         PUSH    DPL
   \   000002   C083         PUSH    DPH
   \   000004                ; Saved register size: 2
   \   000004                ; Auto size: 0
    166            /* abstracted radio configuration */
    167            MAC_RADIO_SET_PAN_COORDINATOR(panCoordFlag);
   \   000004   90DF02       MOV     DPTR,#-0x20fe
   \   000007   E0           MOVX    A,@DPTR
   \   000008   FA           MOV     R2,A
   \   000009   E9           MOV     A,R1
   \   00000A   6004         JZ      ??macRadioSetPanCoordinator_0
   \   00000C   D2F0         SETB    B.0
   \   00000E   8002         SJMP    ??macRadioSetPanCoordinator_1
   \                     ??macRadioSetPanCoordinator_0:
   \   000010   C2F0         CLR     B.0
   \                     ??macRadioSetPanCoordinator_1:
   \   000012   A2F0         MOV     C,B.0
   \   000014   E4           CLR     A
   \   000015   92E0         MOV     0xE0 /* A   */.0,C
   \   000017   C4           SWAP    A
   \   000018   C0E0         PUSH    A
   \   00001A   74EF         MOV     A,#-0x11
   \   00001C   5A           ANL     A,R2
   \   00001D   FA           MOV     R2,A
   \   00001E   D0E0         POP     A
   \   000020   4A           ORL     A,R2
   \   000021   80..         SJMP    ??Subroutine0_0
    168          }
    169          
    170          
    171          /**************************************************************************************************
    172           * @fn          macRadioSetPanID
    173           *
    174           * @brief       Set the pan ID on the radio.
    175           *
    176           * @param       panID - 16 bit PAN identifier
    177           *
    178           * @return      none
    179           **************************************************************************************************
    180           */

   \                                 In  segment BANKED_CODE, align 1, keep-with-next
    181          void macRadioSetPanID(uint16 panID)
   \                     macRadioSetPanID:
    182          {
   \   000000   C082         PUSH    DPL
   \   000002   C083         PUSH    DPH
   \   000004                ; Saved register size: 2
   \   000004                ; Auto size: 0
    183            /* abstracted radio configuration */
    184            MAC_RADIO_SET_PAN_ID(panID);
   \   000004   EA           MOV     A,R2
   \   000005   90DF4C       MOV     DPTR,#-0x20b4
   \   000008   F0           MOVX    @DPTR,A
   \   000009   EB           MOV     A,R3
   \   00000A   80..         SJMP    ?Subroutine0
    185          }
    186          
    187          
    188          /**************************************************************************************************
    189           * @fn          macRadioSetShortAddr
    190           *
    191           * @brief       Set the short addrss on the radio.
    192           *
    193           * @param       shortAddr - 16 bit short address
    194           *
    195           * @return      none
    196           **************************************************************************************************
    197           */

   \                                 In  segment BANKED_CODE, align 1, keep-with-next
    198          void macRadioSetShortAddr(uint16 shortAddr)
   \                     macRadioSetShortAddr:
    199          {
   \   000000   C082         PUSH    DPL
   \   000002   C083         PUSH    DPH
   \   000004                ; Saved register size: 2
   \   000004                ; Auto size: 0
    200            /* abstracted radio configuration */
    201            MAC_RADIO_SET_SHORT_ADDR(shortAddr);
   \   000004   EA           MOV     A,R2
   \   000005   90DF4E       MOV     DPTR,#-0x20b2
   \   000008   F0           MOVX    @DPTR,A
   \   000009   EB           MOV     A,R3
   \   00000A   90DF4D       MOV     DPTR,#-0x20b3
   \   00000D   80..         SJMP    ??Subroutine0_0
    202          }
    203          
    204          
    205          /**************************************************************************************************
    206           * @fn          macRadioSetIEEEAddr
    207           *
    208           * @brief       Set the IEEE address on the radio.
    209           *
    210           * @param       pIEEEAddr - pointer to array holding 64 bit IEEE address; array must be little
    211           *                          endian format (starts with lowest signficant byte)
    212           *
    213           * @return      none
    214           **************************************************************************************************
    215           */

   \                                 In  segment BANKED_CODE, align 1, keep-with-next
    216          void macRadioSetIEEEAddr(uint8 * pIEEEAddr)
   \                     macRadioSetIEEEAddr:
    217          {
   \   000000   C082         PUSH    DPL
   \   000002   C083         PUSH    DPH
   \   000004                ; Saved register size: 2
   \   000004                ; Auto size: 0
   \   000004   EA           MOV     A,R2
   \   000005   FC           MOV     R4,A
   \   000006   EB           MOV     A,R3
   \   000007   FD           MOV     R5,A
    218            /* abstracted radio configuration */
    219            MAC_RADIO_SET_IEEE_ADDR(pIEEEAddr);
   \   000008                ; Setup parameters for call to function macMemWriteRam
   \   000008   7908         MOV     R1,#0x8
   \   00000A   7A43         MOV     R2,#0x43
   \   00000C   7BDF         MOV     R3,#-0x21
   \   00000E   12....       LCALL   ??macMemWriteRam?relay
    220          }
   \   000011   80..         SJMP    ??Subroutine0_1
    221          
    222          
    223          /**************************************************************************************************
    224           * @fn          macRadioSetTxPower
    225           *
    226           * @brief       Set transmitter power of the radio.
    227           *
    228           * @param       txPower - the minus dBm for power but as a postive integer (or if configured
    229           *                        for it, txPower is the raw register value).
    230           *
    231           * @return      none
    232           **************************************************************************************************
    233           */
    234          #ifndef HAL_MAC_USE_REGISTER_POWER_VALUES
    235          /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
    236          

   \                                 In  segment BANKED_CODE, align 1, keep-with-next
    237          void macRadioSetTxPower(uint8 txPower)
   \                     macRadioSetTxPower:
    238          {
   \   000000   74F6         MOV     A,#-0xa
   \   000002   12....       LCALL   ?BANKED_ENTER_XDATA
   \   000005                ; Saved register size: 10
   \   000005                ; Auto size: 0
    239            halIntState_t  s;
    240          
    241            /* if the selected dBm is out of range, use the closest available */
    242            if (txPower > MAC_RADIO_TX_POWER_MAX_MINUS_DBM)
   \   000005   E9           MOV     A,R1
   \   000006   C3           CLR     C
   \   000007   941A         SUBB    A,#0x1a
   \   000009   4002         JC      ??macRadioSetTxPower_0
    243            {
    244              txPower = MAC_RADIO_TX_POWER_MAX_MINUS_DBM;
   \   00000B   7919         MOV     R1,#0x19
    245            }
    246          
    247            /*
    248             *  Set the global variable reqTxPower.  This variable is referenced
    249             *  by the function macRadioUpdateTxPower() to write the radio register.
    250             *
    251             *  A lookup table is used to translate the power level to the register
    252             *  value.
    253             */
    254            HAL_ENTER_CRITICAL_SECTION(s);
   \                     ??macRadioSetTxPower_0:
   \   00000D   A2AF         MOV     C,0xa8.7
   \   00000F   E4           CLR     A
   \   000010   92E0         MOV     0xE0 /* A   */.0,C
   \   000012   FA           MOV     R2,A
   \   000013   C2AF         CLR     0xa8.7
    255            reqTxPower = macRadioDefsTxPowerTable[txPower];
   \   000015   89..         MOV     ?V0 + 0,R1
   \   000017   E5..         MOV     A,?V0 + 0
   \   000019   24..         ADD     A,#(macRadioDefsTxPowerTable & 0xff)
   \   00001B   F582         MOV     DPL,A
   \   00001D   E4           CLR     A
   \   00001E   34..         ADDC    A,#((macRadioDefsTxPowerTable >> 8) & 0xff)
   \   000020   F583         MOV     DPH,A
   \   000022   E4           CLR     A
   \   000023   93           MOVC    A,@A+DPTR
   \   000024   90....       MOV     DPTR,#reqTxPower
   \   000027   F0           MOVX    @DPTR,A
    256            HAL_EXIT_CRITICAL_SECTION(s);
   \   000028   EA           MOV     A,R2
   \   000029   A2E0         MOV     C,0xE0 /* A   */.0
   \   00002B   92AF         MOV     0xa8.7,C
    257          
    258            /* update the radio power setting */
    259            macRadioUpdateTxPower();
   \   00002D                ; Setup parameters for call to function macRadioUpdateTxPower
   \   00002D   12....       LCALL   ??macRadioUpdateTxPower?relay
    260          }
   \   000030   7F02         MOV     R7,#0x2
   \   000032   02....       LJMP    ?BANKED_LEAVE_XDATA
   \   000035                REQUIRE _A_IEN0
    261          
    262          #else
    263          /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
    264          
    265          void macRadioSetTxPower(uint8 txPower)
    266          {
    267            halIntState_t  s;
    268          
    269            /* same as above but with no lookup table, use raw register value */
    270            HAL_ENTER_CRITICAL_SECTION(s);
    271            reqTxPower = txPower;
    272            HAL_EXIT_CRITICAL_SECTION(s);
    273          
    274            /* update the radio power setting */
    275            macRadioUpdateTxPower();
    276          }
    277          
    278          #endif
    279          
    280          
    281          /**************************************************************************************************
    282           * @fn          macRadioUpdateTxPower
    283           *
    284           * @brief       Update the radio's transmit power if a new power level has been requested
    285           *
    286           * @param       reqTxPower - file scope variable that holds the last request power level
    287           *              macPhyTxPower - global variable that holds radio's set power level
    288           *
    289           * @return      none
    290           **************************************************************************************************
    291           */

   \                                 In  segment BANKED_CODE, align 1, keep-with-next
    292          void macRadioUpdateTxPower(void)
   \                     macRadioUpdateTxPower:
    293          {
   \   000000   C082         PUSH    DPL
   \   000002   C083         PUSH    DPH
   \   000004                ; Saved register size: 2
   \   000004                ; Auto size: 0
    294            halIntState_t  s;
    295          
    296            /*
    297             *  If the requested power setting is different from the actual radio setting,
    298             *  attempt to udpate to the new power setting.
    299             */
    300            HAL_ENTER_CRITICAL_SECTION(s);
   \   000004   A2AF         MOV     C,0xa8.7
   \   000006   E4           CLR     A
   \   000007   92E0         MOV     0xE0 /* A   */.0,C
   \   000009   FB           MOV     R3,A
   \   00000A   C2AF         CLR     0xa8.7
    301            if (reqTxPower != macPhyTxPower)
   \   00000C   90....       MOV     DPTR,#reqTxPower
   \   00000F   E0           MOVX    A,@DPTR
   \   000010   FA           MOV     R2,A
   \   000011   90....       MOV     DPTR,#macPhyTxPower
   \   000014   E0           MOVX    A,@DPTR
   \   000015   6A           XRL     A,R2
   \   000016   601A         JZ      ??macRadioUpdateTxPower_0
    302            {
    303              /*
    304               *  Radio power cannot be updated when the radio is physically transmitting.
    305               *  If there is a possibility radio is transmitting, do not change the power
    306               *  setting.  This function will be called again after the current transmit
    307               *  completes.
    308               */
    309              if (!macRxOutgoingAckFlag && !MAC_TX_IS_PHYSICALLY_ACTIVE())
   \   000018   90....       MOV     DPTR,#macRxOutgoingAckFlag
   \   00001B   E0           MOVX    A,@DPTR
   \   00001C   7014         JNZ     ??macRadioUpdateTxPower_0
   \   00001E   90....       MOV     DPTR,#macTxActive
   \   000021   E0           MOVX    A,@DPTR
   \   000022   A2E7         MOV     C,0xE0 /* A   */.7
   \   000024   400C         JC      ??macRadioUpdateTxPower_0
    310              {
    311                /*
    312                 *  Set new power level;  update the shadow value and write
    313                 *  the new value to the radio hardware.
    314                 */
    315                macPhyTxPower = reqTxPower;
   \   000026   90....       MOV     DPTR,#reqTxPower
   \   000029   E0           MOVX    A,@DPTR
   \   00002A   90....       MOV     DPTR,#macPhyTxPower
   \   00002D   F0           MOVX    @DPTR,A
    316                MAC_RADIO_SET_TX_POWER(macPhyTxPower);
   \   00002E   90DF0B       MOV     DPTR,#-0x20f5
   \   000031   F0           MOVX    @DPTR,A
    317              }
    318            }
    319            HAL_EXIT_CRITICAL_SECTION(s);
   \                     ??macRadioUpdateTxPower_0:
   \   000032   EB           MOV     A,R3
   \   000033   A2E0         MOV     C,0xE0 /* A   */.0
   \   000035   92AF         MOV     0xa8.7,C
    320          }
   \   000037   02....       LJMP    ??Subroutine0_1 & 0xFFFF
   \   00003A                REQUIRE _A_IEN0
    321          
    322          
    323          /**************************************************************************************************
    324           * @fn          macRadioSetChannel
    325           *
    326           * @brief       Set radio channel.
    327           *
    328           * @param       channel - channel number, valid range is 11 through 26
    329           *
    330           * @return      none
    331           **************************************************************************************************
    332           */

   \                                 In  segment BANKED_CODE, align 1, keep-with-next
    333          void macRadioSetChannel(uint8 channel)
   \                     macRadioSetChannel:
    334          {
   \   000000   74F7         MOV     A,#-0x9
   \   000002   12....       LCALL   ?BANKED_ENTER_XDATA
   \   000005                ; Saved register size: 9
   \   000005                ; Auto size: 0
   \   000005   E9           MOV     A,R1
   \   000006   FE           MOV     R6,A
    335            halIntState_t  s;
    336          
    337            MAC_ASSERT((channel >= 11) && (channel <= 28));  /* illegal channel */
   \   000007   C3           CLR     C
   \   000008   940B         SUBB    A,#0xb
   \   00000A   4006         JC      ??macRadioSetChannel_0
   \   00000C   EE           MOV     A,R6
   \   00000D   C3           CLR     C
   \   00000E   941D         SUBB    A,#0x1d
   \   000010   4003         JC      ??macRadioSetChannel_1
   \                     ??macRadioSetChannel_0:
   \   000012                ; Setup parameters for call to function halAssertHandler
   \   000012   12....       LCALL   ??halAssertHandler?relay
    338          
    339            /* critical section to make sure transmit does not start while updating channel */
    340            HAL_ENTER_CRITICAL_SECTION(s);
   \                     ??macRadioSetChannel_1:
   \   000015   A2AF         MOV     C,0xa8.7
   \   000017   E4           CLR     A
   \   000018   92E0         MOV     0xE0 /* A   */.0,C
   \   00001A   FF           MOV     R7,A
   \   00001B   C2AF         CLR     0xa8.7
    341          
    342            /* set requested channel */
    343            reqChannel = channel;
   \   00001D   EE           MOV     A,R6
   \   00001E   90....       MOV     DPTR,#reqChannel
   \   000021   F0           MOVX    @DPTR,A
    344          
    345            /*
    346             *  If transmit is not active, update the radio hardware immediately.  If transmit is active,
    347             *  the channel will be updated at the end of the current transmit.
    348             */
    349            if (!macTxActive)
   \   000022   90....       MOV     DPTR,#macTxActive
   \   000025   E0           MOVX    A,@DPTR
   \   000026   7003         JNZ     ??macRadioSetChannel_2
    350            {
    351              macRadioUpdateChannel();
   \   000028                ; Setup parameters for call to function macRadioUpdateChannel
   \   000028   12....       LCALL   ??macRadioUpdateChannel?relay
    352            }
    353            
    354            HAL_EXIT_CRITICAL_SECTION(s);
   \                     ??macRadioSetChannel_2:
   \   00002B   EF           MOV     A,R7
   \   00002C   A2E0         MOV     C,0xE0 /* A   */.0
   \   00002E   92AF         MOV     0xa8.7,C
    355          }
   \   000030                REQUIRE ?Subroutine1
   \   000030                REQUIRE _A_IEN0
   \   000030                ; // Fall through to label ?Subroutine1

   \                                 In  segment BANKED_CODE, align 1, keep-with-next
   \                     ?Subroutine1:
   \   000000   7F01         MOV     R7,#0x1
   \   000002   02....       LJMP    ?BANKED_LEAVE_XDATA
    356          
    357          
    358          /**************************************************************************************************
    359           * @fn          macRadioUpdateChannel
    360           *
    361           * @brief       Update the radio channel if a new channel has been requested.
    362           *
    363           * @param       none
    364           *
    365           * @return      none
    366           **************************************************************************************************
    367           */

   \                                 In  segment BANKED_CODE, align 1, keep-with-next
    368          void macRadioUpdateChannel(void)
   \                     macRadioUpdateChannel:
    369          {
   \   000000   C082         PUSH    DPL
   \   000002   C083         PUSH    DPH
   \   000004                ; Saved register size: 2
   \   000004                ; Auto size: 0
    370            halIntState_t  s;
    371          
    372            MAC_ASSERT(!macTxActive); /* cannot change channel during a transmit */
   \   000004   90....       MOV     DPTR,#macTxActive
   \   000007   E0           MOVX    A,@DPTR
   \   000008   6003         JZ      ??macRadioUpdateChannel_0
   \   00000A                ; Setup parameters for call to function halAssertHandler
   \   00000A   12....       LCALL   ??halAssertHandler?relay
    373          
    374            /* if the channel has changed, set the radio to the new channel */
    375            HAL_ENTER_CRITICAL_SECTION(s);
   \                     ??macRadioUpdateChannel_0:
   \   00000D   A2AF         MOV     C,0xa8.7
   \   00000F   E4           CLR     A
   \   000010   92E0         MOV     0xE0 /* A   */.0,C
   \   000012   FB           MOV     R3,A
   \   000013   C2AF         CLR     0xa8.7
    376            if (reqChannel != macPhyChannel)
   \   000015   90....       MOV     DPTR,#reqChannel
   \   000018   E0           MOVX    A,@DPTR
   \   000019   FA           MOV     R2,A
   \   00001A   90....       MOV     DPTR,#macPhyChannel
   \   00001D   E0           MOVX    A,@DPTR
   \   00001E   6A           XRL     A,R2
   \   00001F   6023         JZ      ??macRadioUpdateChannel_1
    377            {
    378              macPhyChannel = reqChannel;
   \   000021   90....       MOV     DPTR,#reqChannel
   \   000024   E0           MOVX    A,@DPTR
   \   000025   90....       MOV     DPTR,#macPhyChannel
   \   000028   F0           MOVX    @DPTR,A
    379              HAL_EXIT_CRITICAL_SECTION(s);
   \   000029   EB           MOV     A,R3
   \   00002A   A2E0         MOV     C,0xE0 /* A   */.0
   \   00002C   92AF         MOV     0xa8.7,C
    380          
    381              /* changing the channel stops any receive in progress */
    382              macRxOff();
   \   00002E                ; Setup parameters for call to function macRxOff
   \   00002E   12....       LCALL   ??macRxOff?relay
    383              MAC_RADIO_SET_CHANNEL(macPhyChannel);
   \   000031   75F005       MOV     B,#0x5
   \   000034   90....       MOV     DPTR,#macPhyChannel
   \   000037   E0           MOVX    A,@DPTR
   \   000038   A4           MUL     AB
   \   000039   242E         ADD     A,#0x2e
   \   00003B   90DF11       MOV     DPTR,#-0x20ef
   \   00003E   F0           MOVX    @DPTR,A
    384              macRxOnRequest();
   \   00003F                ; Setup parameters for call to function macRxOnRequest
   \   00003F   12....       LCALL   ??macRxOnRequest?relay
   \   000042   8005         SJMP    ??macRadioUpdateChannel_2
    385            }
    386            else
    387            {
    388              HAL_EXIT_CRITICAL_SECTION(s);
   \                     ??macRadioUpdateChannel_1:
   \   000044   EB           MOV     A,R3
   \   000045   A2E0         MOV     C,0xE0 /* A   */.0
   \   000047   92AF         MOV     0xa8.7,C
    389            }
    390          }
   \                     ??macRadioUpdateChannel_2:
   \   000049   02....       LJMP    ??Subroutine0_1 & 0xFFFF
   \   00004C                REQUIRE _A_IEN0
    391          
    392          
    393          /**************************************************************************************************
    394           * @fn          macRadioStartScan
    395           *
    396           * @brief       Puts radio into selected scan mode.
    397           *
    398           * @param       scanMode - scan mode, see #defines in .h file
    399           *
    400           * @return      none
    401           **************************************************************************************************
    402           */

   \                                 In  segment BANKED_CODE, align 1, keep-with-next
    403          void macRadioStartScan(uint8 scanMode)
   \                     macRadioStartScan:
    404          {
   \   000000   74F7         MOV     A,#-0x9
   \   000002   12....       LCALL   ?BANKED_ENTER_XDATA
   \   000005                ; Saved register size: 9
   \   000005                ; Auto size: 0
   \   000005   E9           MOV     A,R1
   \   000006   FE           MOV     R6,A
    405            MAC_ASSERT(macSleepState == MAC_SLEEP_STATE_AWAKE); /* radio must be awake */
   \   000007   90....       MOV     DPTR,#macSleepState
   \   00000A   E0           MOVX    A,@DPTR
   \   00000B   6003         JZ      ??macRadioStartScan_0
   \   00000D                ; Setup parameters for call to function halAssertHandler
   \   00000D   12....       LCALL   ??halAssertHandler?relay
    406            MAC_ASSERT(macRxFilter == RX_FILTER_OFF); /* all filtering must be off to start scan */
   \                     ??macRadioStartScan_0:
   \   000010   90....       MOV     DPTR,#macRxFilter
   \   000013   E0           MOVX    A,@DPTR
   \   000014   6003         JZ      ??macRadioStartScan_1
   \   000016                ; Setup parameters for call to function halAssertHandler
   \   000016   12....       LCALL   ??halAssertHandler?relay
    407          
    408            /* set the receive filter based on the selected scan mode */
    409            if (scanMode == MAC_SCAN_ED)
   \                     ??macRadioStartScan_1:
   \   000019   EE           MOV     A,R6
   \   00001A   7007         JNZ     ??macRadioStartScan_2
    410            {
    411              macRxFilter = RX_FILTER_ALL;
   \   00001C   7401         MOV     A,#0x1
   \                     ??macRadioStartScan_3:
   \   00001E   90....       MOV     DPTR,#macRxFilter
   \   000021   8025         SJMP    ??macRadioStartScan_4
    412            }
    413            else if (scanMode == MAC_SCAN_ORPHAN)
   \                     ??macRadioStartScan_2:
   \   000023   7403         MOV     A,#0x3
   \   000025   6E           XRL     A,R6
   \   000026   7004         JNZ     ??macRadioStartScan_5
    414            {
    415              macRxFilter = RX_FILTER_NON_COMMAND_FRAMES;
   \   000028   7403         MOV     A,#0x3
   \   00002A   80F2         SJMP    ??macRadioStartScan_3
    416            }
    417            else
    418            {
    419              MAC_ASSERT((scanMode == MAC_SCAN_ACTIVE) || (scanMode == MAC_SCAN_PASSIVE)); /* invalid scan type */
   \                     ??macRadioStartScan_5:
   \   00002C   7401         MOV     A,#0x1
   \   00002E   6E           XRL     A,R6
   \   00002F   6008         JZ      ??macRadioStartScan_6
   \   000031   7402         MOV     A,#0x2
   \   000033   6E           XRL     A,R6
   \   000034   6003         JZ      ??macRadioStartScan_6
   \   000036                ; Setup parameters for call to function halAssertHandler
   \   000036   12....       LCALL   ??halAssertHandler?relay
    420              macRxFilter = RX_FILTER_NON_BEACON_FRAMES;
   \                     ??macRadioStartScan_6:
   \   000039   7402         MOV     A,#0x2
   \   00003B   90....       MOV     DPTR,#macRxFilter
   \   00003E   F0           MOVX    @DPTR,A
    421          
    422              /* for active and passive scans, per spec the pan ID must be 0xFFFF */
    423              MAC_RADIO_SET_PAN_ID(0xFFFF);
   \   00003F   74FF         MOV     A,#-0x1
   \   000041   90DF4C       MOV     DPTR,#-0x20b4
   \   000044   F0           MOVX    @DPTR,A
   \   000045   90DF4B       MOV     DPTR,#-0x20b5
   \                     ??macRadioStartScan_4:
   \   000048   F0           MOVX    @DPTR,A
    424            }
    425          }
   \   000049   02....       LJMP    ?Subroutine1 & 0xFFFF
    426          
    427          
    428          /**************************************************************************************************
    429           * @fn          macRadioStopScan
    430           *
    431           * @brief       Takes radio out of scan mode.  Note can be called if
    432           *
    433           * @param       none
    434           *
    435           * @return      none
    436           **************************************************************************************************
    437           */

   \                                 In  segment BANKED_CODE, align 1, keep-with-next
    438          void macRadioStopScan(void)
   \                     macRadioStopScan:
    439          {
   \   000000   C082         PUSH    DPL
   \   000002   C083         PUSH    DPH
   \   000004                ; Saved register size: 2
   \   000004                ; Auto size: 0
    440            macRxFilter = RX_FILTER_OFF;
   \   000004   E4           CLR     A
   \   000005   90....       MOV     DPTR,#macRxFilter
   \   000008   F0           MOVX    @DPTR,A
    441          
    442            /* restore the pan ID (passive and active scans set pan ID to 0xFFFF) */
    443            MAC_RADIO_SET_PAN_ID(macPib.panId);
   \   000009   90....       MOV     DPTR,#(macPib + 29)
   \   00000C   E0           MOVX    A,@DPTR
   \   00000D   90DF4C       MOV     DPTR,#-0x20b4
   \   000010   F0           MOVX    @DPTR,A
   \   000011   90....       MOV     DPTR,#(macPib + 30)
   \   000014   E0           MOVX    A,@DPTR
   \   000015   02....       LJMP    ?Subroutine0 & 0xFFFF
    444          }
    445          
    446          
    447          /**************************************************************************************************
    448           * @fn          macRadioEnergyDetectStart
    449           *
    450           * @brief       Initiates energy detect.  The highest energy detected is recorded from the time
    451           *              when this function is called until the energy detect is stopped.
    452           *
    453           * @param       none
    454           *
    455           * @return      none
    456           **************************************************************************************************
    457           */

   \                                 In  segment BANKED_CODE, align 1, keep-with-next
    458          void macRadioEnergyDetectStart(void)
   \                     macRadioEnergyDetectStart:
    459          {
   \   000000   C082         PUSH    DPL
   \   000002   C083         PUSH    DPH
   \   000004                ; Saved register size: 2
   \   000004                ; Auto size: 0
    460            MAC_RADIO_RECORD_MAX_RSSI_START();
   \   000004                ; Setup parameters for call to function macMcuRecordMaxRssiStart
   \   000004   12....       LCALL   ??macMcuRecordMaxRssiStart?relay
    461          }
   \   000007   02....       LJMP    ??Subroutine0_1 & 0xFFFF
    462          
    463          
    464          /**************************************************************************************************
    465           * @fn          macRadioEnergyDetectStop
    466           *
    467           * @brief       Called at completion of an energy detect.  Note: can be called even if energy
    468           *              detect is already stopped (needed by reset).
    469           *
    470           * @param       none
    471           *
    472           * @return      highest energy detect measurement
    473           **************************************************************************************************
    474           */

   \                                 In  segment BANKED_CODE, align 1, keep-with-next
    475          uint8 macRadioEnergyDetectStop(void)
   \                     macRadioEnergyDetectStop:
    476          {
   \   000000   C082         PUSH    DPL
   \   000002   C083         PUSH    DPH
   \   000004                ; Saved register size: 2
   \   000004                ; Auto size: 0
    477            uint8 rssiDbm;
    478            uint8 energyDetectMeasurement;
    479            
    480            rssiDbm = MAC_RADIO_RECORD_MAX_RSSI_STOP() + MAC_RADIO_RSSI_OFFSET;
   \   000004                ; Setup parameters for call to function macMcuRecordMaxRssiStop
   \   000004   12....       LCALL   ??macMcuRecordMaxRssiStop?relay
   \   000007   E9           MOV     A,R1
   \   000008   24D3         ADD     A,#-0x2d
   \   00000A   F9           MOV     R1,A
    481            energyDetectMeasurement = radioComputeED(rssiDbm);
    482            
    483            return(energyDetectMeasurement);
   \   00000B                ; Setup parameters for call to function radioComputeED
   \   00000B                REQUIRE ?Subroutine2
   \   00000B                ; // Fall through to label ?Subroutine2
    484          }

   \                                 In  segment BANKED_CODE, align 1, keep-with-next
   \                     ?Subroutine2:
   \   000000   12....       LCALL   ??radioComputeED?relay
   \   000003   02....       LJMP    ??Subroutine0_1 & 0xFFFF
    485          
    486          /*=================================================================================================
    487           * @fn          radioComputeED
    488           *
    489           * @brief       Compute energy detect measurement.
    490           *
    491           * @param       rssi - raw RSSI value from radio hardware
    492           *
    493           * @return      energy detect measurement in the range of 0x00-0xFF
    494           *=================================================================================================
    495           */

   \                                 In  segment BANKED_CODE, align 1, keep-with-next
    496          static uint8 radioComputeED(int8 rssiDbm)
   \                     radioComputeED:
    497          {
   \   000000                ; Saved register size: 0
   \   000000                ; Auto size: 0
    498            uint8 ed;
    499            
    500            /*
    501             *  Keep RF power between minimum and maximum values.
    502             *  This min/max range is derived from datasheet and specification.
    503             */
    504            if (rssiDbm < ED_RF_POWER_MIN_DBM)
   \   000000   E9           MOV     A,R1
   \   000001   C3           CLR     C
   \   000002   94AF         SUBB    A,#-0x51
   \   000004   A2D2         MOV     C,0xD0 /* PSW */.2
   \   000006   65D0         XRL     A,PSW
   \   000008   33           RLC     A
   \   000009   5004         JNC     ??radioComputeED_0
    505            {
    506              rssiDbm = ED_RF_POWER_MIN_DBM;
   \   00000B   79AF         MOV     R1,#-0x51
   \   00000D   800D         SJMP    ??radioComputeED_1
    507            }
    508            else if (rssiDbm > ED_RF_POWER_MAX_DBM)
   \                     ??radioComputeED_0:
   \   00000F   E9           MOV     A,R1
   \   000010   C3           CLR     C
   \   000011   940B         SUBB    A,#0xb
   \   000013   A2D2         MOV     C,0xD0 /* PSW */.2
   \   000015   65D0         XRL     A,PSW
   \   000017   33           RLC     A
   \   000018   4002         JC      ??radioComputeED_1
    509            {
    510              rssiDbm = ED_RF_POWER_MAX_DBM;
   \   00001A   790A         MOV     R1,#0xa
    511            }
    512            
    513            /*
    514             *  Create energy detect measurement by normalizing and scaling RF power level.
    515             *
    516             *  Note : The division operation below is designed for maximum accuracy and
    517             *         best granularity.  This is done by grouping the math operations to
    518             *         compute the entire numerator before doing any division.
    519             */
    520            ed = (MAC_SPEC_ED_MAX * (rssiDbm - ED_RF_POWER_MIN_DBM)) / (ED_RF_POWER_MAX_DBM - ED_RF_POWER_MIN_DBM);
    521          
    522            return(ed);
   \                     ??radioComputeED_1:
   \   00001C   E9           MOV     A,R1
   \   00001D   F8           MOV     R0,A
   \   00001E   33           RLC     A
   \   00001F   95E0         SUBB    A,0xE0 /* A   */
   \   000021   F9           MOV     R1,A
   \   000022   7451         MOV     A,#0x51
   \   000024   28           ADD     A,R0
   \   000025   F8           MOV     R0,A
   \   000026   E4           CLR     A
   \   000027   39           ADDC    A,R1
   \   000028   F9           MOV     R1,A
   \   000029   E8           MOV     A,R0
   \   00002A   75F0FF       MOV     B,#-0x1
   \   00002D   A4           MUL     AB
   \   00002E   F8           MOV     R0,A
   \   00002F   AAF0         MOV     R2,B
   \   000031   75F0FF       MOV     B,#-0x1
   \   000034   E9           MOV     A,R1
   \   000035   A4           MUL     AB
   \   000036   2A           ADD     A,R2
   \   000037   F9           MOV     R1,A
   \   000038   7A5B         MOV     R2,#0x5b
   \   00003A   7B00         MOV     R3,#0x0
   \   00003C   12....       LCALL   ?S_DIV_MOD
   \   00003F   E8           MOV     A,R0
   \   000040   F9           MOV     R1,A
   \   000041   02....       LJMP    ?BRET
    523          }
    524          
    525          
    526          /**************************************************************************************************
    527           * @fn          macRadioComputeLQI
    528           *
    529           * @brief       Compute link quality indication.
    530           *
    531           * @param       rssi - raw RSSI value from radio hardware
    532           *              corr - correlation value from radio hardware
    533           *
    534           * @return      link quality indicator value
    535           **************************************************************************************************
    536           */

   \                                 In  segment BANKED_CODE, align 1, keep-with-next
    537          uint8 macRadioComputeLQI(int8 rssiDbm, uint8 corr)
   \                     macRadioComputeLQI:
    538          {
   \   000000   C082         PUSH    DPL
   \   000002   C083         PUSH    DPH
   \   000004                ; Saved register size: 2
   \   000004                ; Auto size: 0
    539            (void) corr; /* suppress compiler warning of unused parameter */
    540            
    541            /*
    542             *  Note : Currently the LQI value is simply the energy detect measurement.
    543             *         A more accurate value could be derived by using the correlation
    544             *         value along with the RSSI value.
    545             */  
    546            return(radioComputeED(rssiDbm));
   \   000004                ; Setup parameters for call to function radioComputeED
   \   000004   80..         SJMP    ?Subroutine2
    547          }

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

   \                                 In  segment BANK_RELAYS, align 1
   \                     ??macRadioComputeLQI?relay:
   \   000000   12....       LCALL   ?BDISPATCH
   \   000003   ......       DC24    macRadioComputeLQI
    548          
    549          
    550          /**************************************************************************************************
    551          */

   Maximum stack usage in bytes:

     Function                      ISTACK PSTACK XSTACK
     --------                      ------ ------ ------
     macRadioComputeLQI                2      0      0
       -> radioComputeED               4      0      0
     macRadioEnergyDetectStart         2      0      0
       -> macMcuRecordMaxRssiStart     4      0      0
     macRadioEnergyDetectStop          2      0      0
       -> macMcuRecordMaxRssiStop      4      0      0
       -> radioComputeED               4      0      0
     macRadioInit                      2      0      0
     macRadioRandomByte                2      0      0
       -> macMcuRandomByte             4      0      0
     macRadioReset                     2      0      0
       -> macRadioStopScan             4      0      0
       -> macRadioEnergyDetectStop     4      0      0
     macRadioSetChannel                0      0      9
       -> halAssertHandler             0      0     18
       -> macRadioUpdateChannel        0      0     18
     macRadioSetIEEEAddr               2      0      0
       -> macMemWriteRam               4      0      0
     macRadioSetPanCoordinator         3      0      0
     macRadioSetPanID                  2      0      0
     macRadioSetShortAddr              2      0      0
     macRadioSetTxPower                0      0     10
       -> macRadioUpdateTxPower        0      0     20
     macRadioStartScan                 0      0      9
       -> halAssertHandler             0      0     18
       -> halAssertHandler             0      0     18
       -> halAssertHandler             0      0     18
     macRadioStopScan                  2      0      0
     macRadioUpdateChannel             2      0      9
       -> halAssertHandler             4      0      0
       -> macRxOff                     4      0      0
       -> macRxOnRequest               4      0      0
     macRadioUpdateTxPower             2      0     10
     radioComputeED                    0      0      0


   Segment part sizes:

     Function/Label                 Bytes
     --------------                 -----
     _A_IEN0                           1
     macPhyTxPower                     1
     macPhyChannel                     1
     reqChannel                        1
     reqTxPower                        1
     macRadioInit                     25
     ?Subroutine0                     11
     macRadioReset                    12
     macRadioRandomByte                9
     macRadioSetPanCoordinator        35
     macRadioSetPanID                 12
     macRadioSetShortAddr             15
     macRadioSetIEEEAddr              19
     macRadioSetTxPower               53
     macRadioUpdateTxPower            58
     macRadioSetChannel               48
     ?Subroutine1                      5
     macRadioUpdateChannel            76
     macRadioStartScan                76
     macRadioStopScan                 24
     macRadioEnergyDetectStart        10
     macRadioEnergyDetectStop         11
     ?Subroutine2                      6
     radioComputeED                   68
     macRadioComputeLQI                6
     ??macRadioInit?relay              6
     ??macRadioReset?relay             6
     ??macRadioRandomByte?relay        6
     ??macRadioSetPanCoordinator?relay
                                       6
     ??macRadioSetPanID?relay          6
     ??macRadioSetShortAddr?relay      6
     ??macRadioSetIEEEAddr?relay       6
     ??macRadioSetTxPower?relay        6
     ??macRadioUpdateTxPower?relay     6
     ??macRadioSetChannel?relay        6
     ??macRadioUpdateChannel?relay     6
     ??macRadioStartScan?relay         6
     ??macRadioStopScan?relay          6
     ??macRadioEnergyDetectStart?relay
                                       6
     ??macRadioEnergyDetectStop?relay
                                       6
     ??radioComputeED?relay            6
     ??macRadioComputeLQI?relay        6

 
 579 bytes in segment BANKED_CODE
 102 bytes in segment BANK_RELAYS
   1 byte  in segment SFR_AN
   4 bytes in segment XDATA_Z
 
 681 bytes of CODE  memory
   0 bytes of DATA  memory (+ 1 byte shared)
   4 bytes of XDATA memory

Errors: none
Warnings: none
