///////////////////////////////////////////////////////////////////////////////
//                                                                            /
// IAR 8051 C/C++ Compiler V7.30B/W32                   08/Aug/2010  22:00:54 /
// 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\Compon /
//                          ents\mac\low_level\srf03\mac_sleep.c              /
//    Command line       =  -f "C:\Texas Instruments                          /
//                          33\ZStack-1.4.3-1.2.1\Projects\zstack\Project\Loc /
//                          ation\CC2430DB\..\..\..\Tools\CC2430DB\f8wCoord.c /
//                          fg" (-DCPU32MHZ -DFORCE_MAC_NEAR                  /
//                          -DROOT=__near_func -DMAC_CFG_APP_PENDING_QUEUE=TR /
//                          UE -DZDO_COORDINATOR -DRTR_NWK -DBLINK_LEDS       /
//                          "-DCONST=const __code" -DGENERIC=__generic) -f    /
//                          "C:\Texas Instruments 33\ZStack-1.4.3-1.2.1\Proje /
//                          cts\zstack\Project\Location\CC2430DB\..\..\..\Too /
//                          ls\CC2430DB\f8wConfig.cfg" (-DSECURE=1            /
//                          -DDEFAULT_CHANLIST=0x04000000                     /
//                          -DZDAPP_CONFIG_PAN_ID=0x00FF                      /
//                          -DNWK_START_DELAY=100 -DEXTENDED_JOINING_RANDOM_M /
//                          ASK=0x007F -DBEACON_REQUEST_DELAY=100             /
//                          -DBEACON_REQ_DELAY_MASK=0x00FF                    /
//                          -DROUTE_EXPIRY_TIME=30 -DAPSC_ACK_WAIT_DURATION_P /
//                          OLLED=3000 -DNWK_INDIRECT_MSG_TIMEOUT=7           /
//                          -DMAX_RREQ_ENTRIES=10 -DAPSC_MAX_FRAME_RETRIES=3  /
//                          -DNWK_MAX_DATA_RETRIES=2                          /
//                          -DMAX_POLL_FAILURE_RETRIES=2 -DMAX_BCAST=9        /
//                          -DAPS_MAX_GROUPS=16 -DMAX_RTG_ENTRIES=20          /
//                          -DNWK_MAX_BINDING_ENTRIES=10                      /
//                          -DMAX_BINDING_CLUSTER_IDS=5                       /
//                          "-DDEFAULT_KEY={0x02, 0x03, 0x05, 0x07, 0x09,     /
//                          0x0B, 0x0D, 0x0F, 0x00, 0x02, 0x04, 0x06, 0x08,   /
//                          0x0A, 0x0C, 0x0D}" -DRFD_RCVC_ALWAYS_ON=FALSE     /
//                          -DPOLL_RATE=1000 -DQUEUED_POLL_RATE=100           /
//                          -DRESPONSE_POLL_RATE=100) -DREJOIN_POLL_RATE=440  /
//                          "C:\Texas Instruments 33\ZStack-1.4.3-1.2.1\Compo /
//                          nents\mac\low_level\srf03\mac_sleep.c" -D         /
//                          CC2430EB -D ZTOOL_P1 -D LOCATION_DONGLE -D        /
//                          MT_TASK -D xNV_RESTORE -D INT_HEAP_LEN=4608 -D    /
//                          HAL_UART_BIG_TX_BUF=1 -D                          /
//                          SPI_MGR_DEFAULT_MAX_TX_BUFF=1024 -D               /
//                          SPI_MGR_DEFAULT_OVERFLOW=1 -lC "C:\Texas          /
//                          Instruments 33\ZStack-1.4.3-1.2.1\Projects\zstack /
//                          \Project\Location\CC2430DB\LocDongle\List\" -lA   /
//                          "C:\Texas Instruments 33\ZStack-1.4.3-1.2.1\Proje /
//                          cts\zstack\Project\Location\CC2430DB\LocDongle\Li /
//                          st\" --diag_suppress Pe001,Pa010 --diag_remark    /
//                          pe550 -o "C:\Texas Instruments                    /
//                          33\ZStack-1.4.3-1.2.1\Projects\zstack\Project\Loc /
//                          ation\CC2430DB\LocDongle\Obj\" -e                 /
//                          --require_prototypes -z9 --no_code_motion         /
//                          --debug --core=plain --dptr=16,1                  /
//                          --data_model=large --code_model=banked            /
//                          --calling_convention=xdata_reentrant              /
//                          --place_constants=data --nr_virtual_regs 8 -I     /
//                          "C:\Texas Instruments 33\ZStack-1.4.3-1.2.1\Proje /
//                          cts\zstack\Project\Location\CC2430DB\" -I         /
//                          "C:\Texas Instruments 33\ZStack-1.4.3-1.2.1\Proje /
//                          cts\zstack\Project\Location\CC2430DB\..\SOURCE\"  /
//                          -I "C:\Texas Instruments                          /
//                          33\ZStack-1.4.3-1.2.1\Projects\zstack\Project\Loc /
//                          ation\CC2430DB\..\..\..\ZMAIN\TI2430DB\" -I       /
//                          "C:\Texas Instruments 33\ZStack-1.4.3-1.2.1\Proje /
//                          cts\zstack\Project\Location\CC2430DB\..\..\..\..\ /
//                          WXL\INCLUDE\" -I "C:\Texas Instruments            /
//                          33\ZStack-1.4.3-1.2.1\Projects\zstack\Project\Loc /
//                          ation\CC2430DB\..\..\..\..\..\COMPONENTS\MT\" -I  /
//                          "C:\Texas Instruments 33\ZStack-1.4.3-1.2.1\Proje /
//                          cts\zstack\Project\Location\CC2430DB\..\..\..\..\ /
//                          ..\COMPONENTS\HAL\INCLUDE\" -I "C:\Texas          /
//                          Instruments 33\ZStack-1.4.3-1.2.1\Projects\zstack /
//                          \Project\Location\CC2430DB\..\..\..\..\..\COMPONE /
//                          NTS\HAL\TARGET\CC2430EB\" -I "C:\Texas            /
//                          Instruments 33\ZStack-1.4.3-1.2.1\Projects\zstack /
//                          \Project\Location\CC2430DB\..\..\..\..\..\COMPONE /
//                          NTS\OSAL\MCU\CCSOC\" -I "C:\Texas Instruments     /
//                          33\ZStack-1.4.3-1.2.1\Projects\zstack\Project\Loc /
//                          ation\CC2430DB\..\..\..\..\..\COMPONENTS\OSAL\INC /
//                          LUDE\" -I "C:\Texas Instruments                   /
//                          33\ZStack-1.4.3-1.2.1\Projects\zstack\Project\Loc /
//                          ation\CC2430DB\..\..\..\..\..\COMPONENTS\STACK\AF /
//                          \" -I "C:\Texas Instruments                       /
//                          33\ZStack-1.4.3-1.2.1\Projects\zstack\Project\Loc /
//                          ation\CC2430DB\..\..\..\..\..\COMPONENTS\STACK\NW /
//                          K\" -I "C:\Texas Instruments                      /
//                          33\ZStack-1.4.3-1.2.1\Projects\zstack\Project\Loc /
//                          ation\CC2430DB\..\..\..\..\..\COMPONENTS\STACK\SE /
//                          C\" -I "C:\Texas Instruments                      /
//                          33\ZStack-1.4.3-1.2.1\Projects\zstack\Project\Loc /
//                          ation\CC2430DB\..\..\..\..\..\COMPONENTS\STACK\SY /
//                          S\" -I "C:\Texas Instruments                      /
//                          33\ZStack-1.4.3-1.2.1\Projects\zstack\Project\Loc /
//                          ation\CC2430DB\..\..\..\..\..\COMPONENTS\STACK\ZD /
//                          O\" -I "C:\Texas Instruments                      /
//                          33\ZStack-1.4.3-1.2.1\Projects\zstack\Project\Loc /
//                          ation\CC2430DB\..\..\..\..\..\COMPONENTS\ZMAC\F8W /
//                          \" -I "C:\Texas Instruments                       /
//                          33\ZStack-1.4.3-1.2.1\Projects\zstack\Project\Loc /
//                          ation\CC2430DB\..\..\..\..\..\COMPONENTS\ZMAC\"   /
//                          -I "C:\Texas Instruments                          /
//                          33\ZStack-1.4.3-1.2.1\Projects\zstack\Project\Loc /
//                          ation\CC2430DB\..\..\..\..\..\COMPONENTS\SERVICES /
//                          \SADDR\" -I "C:\Texas Instruments                 /
//                          33\ZStack-1.4.3-1.2.1\Projects\zstack\Project\Loc /
//                          ation\CC2430DB\..\..\..\..\..\COMPONENTS\SERVICES /
//                          \SDATA\" -I "C:\Texas Instruments                 /
//                          33\ZStack-1.4.3-1.2.1\Projects\zstack\Project\Loc /
//                          ation\CC2430DB\..\..\..\..\..\COMPONENTS\MAC\INCL /
//                          UDE\" -I "C:\Texas Instruments                    /
//                          33\ZStack-1.4.3-1.2.1\Projects\zstack\Project\Loc /
//                          ation\CC2430DB\..\..\..\..\..\COMPONENTS\MAC\HIGH /
//                          _LEVEL\" -I "C:\Texas Instruments                 /
//                          33\ZStack-1.4.3-1.2.1\Projects\zstack\Project\Loc /
//                          ation\CC2430DB\..\..\..\..\..\COMPONENTS\MAC\LOW_ /
//                          LEVEL\SRF03\" -I "C:\Texas Instruments            /
//                          33\ZStack-1.4.3-1.2.1\Projects\zstack\Project\Loc /
//                          ation\CC2430DB\..\..\..\..\..\COMPONENTS\MAC\LOW_ /
//                          LEVEL\SRF03\SINGLE_CHIP\" -I "C:\Program          /
//                          Files\IAR Systems\Embedded Workbench 4.0          /
//                          Evaluation version\8051\INC\" -I "C:\Program      /
//                          Files\IAR Systems\Embedded Workbench 4.0          /
//                          Evaluation version\8051\INC\CLIB\"                /
//    List file          =  C:\Texas Instruments 33\ZStack-1.4.3-1.2.1\Projec /
//                          ts\zstack\Project\Location\CC2430DB\LocDongle\Lis /
//                          t\mac_sleep.s51                                   /
//                                                                            /
//                                                                            /
///////////////////////////////////////////////////////////////////////////////

        NAME mac_sleep

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

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

        EXTERN ?BANKED_ENTER_XDATA
        EXTERN ?BANKED_LEAVE_XDATA
        EXTERN ?BDISPATCH
        EXTERN ?BRET
        EXTERN __INIT_XDATA_I

        PUBLIC ??macSleep?relay
        FUNCTION ??macSleep?relay,0203H
        PUBLIC ??macSleepWakeUp?relay
        FUNCTION ??macSleepWakeUp?relay,0203H
        PUBWEAK SLEEP
        PUBWEAK T2CNF
        PUBWEAK _A_IEN0
        PUBLIC macSleep
        FUNCTION macSleep,021203H
        ARGFRAME XSTACK, 0, STACK
        LOCFRAME XSTACK, 9, STACK
        PUBLIC macSleepState
        PUBLIC macSleepWakeUp
        FUNCTION macSleepWakeUp,021203H
        ARGFRAME XSTACK, 0, STACK
        LOCFRAME ISTACK, 2, STACK
        
        CFI Names cfiNames0
        CFI StackFrame CFA_SP SP DATA
        CFI StackFrame CFA_PSP16 PSP16 XDATA
        CFI StackFrame CFA_XSP16 XSP16 XDATA
        CFI StaticOverlayFrame CFA_IOVERLAY IOVERLAY
        CFI StaticOverlayFrame CFA_DOVERLAY DOVERLAY
        CFI Resource `PSW.CY`:1, `B.BR0`:1, `B.BR1`:1, `B.BR2`:1, `B.BR3`:1
        CFI Resource `B.BR4`:1, `B.BR5`:1, `B.BR6`:1, `B.BR7`:1, `VB.BR8`:1
        CFI Resource `VB.BR9`:1, `VB.BR10`:1, `VB.BR11`:1, `VB.BR12`:1
        CFI Resource `VB.BR13`:1, `VB.BR14`:1, `VB.BR15`:1, VB:8, B:8, A:8
        CFI Resource PSW:8, DPL0:8, DPH0:8, R0:8, R1:8, R2:8, R3:8, R4:8, R5:8
        CFI Resource R6:8, R7:8, V0:8, V1:8, V2:8, V3:8, V4:8, V5:8, V6:8, V7:8
        CFI Resource SP:8, PSPH:8, PSPL:8, PSP16:16, XSPH:8, XSPL:8, XSP16:16
        CFI VirtualResource ?RET:24
        CFI Resource ?BRET_EXT:8
        CFI VirtualResource ?RET_HIGH:8, ?RET_LOW:8
        CFI ResourceParts PSP16 PSPH, PSPL
        CFI ResourceParts XSP16 XSPH, XSPL
        CFI ResourceParts ?RET ?BRET_EXT, ?RET_HIGH, ?RET_LOW
        CFI EndNames cfiNames0
        
        CFI Common cfiCommon0 Using cfiNames0
        CFI CodeAlign 1
        CFI DataAlign -1
        CFI ReturnAddress ?RET CODE
        CFI CFA_DOVERLAY Used
        CFI CFA_IOVERLAY Used
        CFI CFA_SP SP+-3
        CFI CFA_PSP16 PSP16+0
        CFI CFA_XSP16 XSP16+0
        CFI `PSW.CY` SameValue
        CFI `B.BR0` SameValue
        CFI `B.BR1` SameValue
        CFI `B.BR2` SameValue
        CFI `B.BR3` SameValue
        CFI `B.BR4` SameValue
        CFI `B.BR5` SameValue
        CFI `B.BR6` SameValue
        CFI `B.BR7` SameValue
        CFI `VB.BR8` SameValue
        CFI `VB.BR9` SameValue
        CFI `VB.BR10` SameValue
        CFI `VB.BR11` SameValue
        CFI `VB.BR12` SameValue
        CFI `VB.BR13` SameValue
        CFI `VB.BR14` SameValue
        CFI `VB.BR15` SameValue
        CFI VB SameValue
        CFI B Undefined
        CFI A Undefined
        CFI PSW SameValue
        CFI DPL0 SameValue
        CFI DPH0 SameValue
        CFI R0 Undefined
        CFI R1 Undefined
        CFI R2 Undefined
        CFI R3 Undefined
        CFI R4 Undefined
        CFI R5 Undefined
        CFI R6 SameValue
        CFI R7 SameValue
        CFI V0 SameValue
        CFI V1 SameValue
        CFI V2 SameValue
        CFI V3 SameValue
        CFI V4 SameValue
        CFI V5 SameValue
        CFI V6 SameValue
        CFI V7 SameValue
        CFI PSPH Undefined
        CFI PSPL Undefined
        CFI XSPH Undefined
        CFI XSPL Undefined
        CFI ?RET Concat
        CFI ?BRET_EXT Frame(CFA_SP, 3)
        CFI ?RET_HIGH Frame(CFA_SP, 2)
        CFI ?RET_LOW Frame(CFA_SP, 1)
        CFI EndCommon cfiCommon0
        
macRxRadioPowerUpInit SYMBOL "macRxRadioPowerUpInit"
halAssertHandler    SYMBOL "halAssertHandler"
macRxOnRequest      SYMBOL "macRxOnRequest"
macRxOff            SYMBOL "macRxOff"
??halAssertHandler?relay SYMBOL "?relay", halAssertHandler
??macRxOff?relay    SYMBOL "?relay", macRxOff
??macRxOnRequest?relay SYMBOL "?relay", macRxOnRequest
??macRxRadioPowerUpInit?relay SYMBOL "?relay", macRxRadioPowerUpInit
macSleep            SYMBOL "macSleep"
??macSleep?relay    SYMBOL "?relay", macSleep
macSleepWakeUp      SYMBOL "macSleepWakeUp"
??macSleepWakeUp?relay SYMBOL "?relay", macSleepWakeUp

        EXTERN macRxRadioPowerUpInit
        FUNCTION macRxRadioPowerUpInit,0202H
        ARGFRAME ISTACK, 2, STACK
        ARGFRAME PSTACK, 0, STACK
        ARGFRAME XSTACK, 0, STACK
        ARGFRAME IOVERLAY, 0, STATIC
        ARGFRAME DOVERLAY, 0, STATIC
        EXTERN halAssertHandler
        FUNCTION halAssertHandler,0202H
        ARGFRAME ISTACK, 2, STACK
        ARGFRAME PSTACK, 0, STACK
        ARGFRAME XSTACK, 9, STACK
        ARGFRAME IOVERLAY, 0, STATIC
        ARGFRAME DOVERLAY, 0, STATIC
        EXTERN macRxOnRequest
        FUNCTION macRxOnRequest,0202H
        ARGFRAME ISTACK, 2, STACK
        ARGFRAME PSTACK, 0, STACK
        ARGFRAME XSTACK, 0, STACK
        ARGFRAME IOVERLAY, 0, STATIC
        ARGFRAME DOVERLAY, 0, STATIC
        EXTERN macRxOff
        FUNCTION macRxOff,0202H
        ARGFRAME ISTACK, 0, STACK
        ARGFRAME PSTACK, 0, STACK
        ARGFRAME XSTACK, 9, STACK
        ARGFRAME IOVERLAY, 0, STATIC
        ARGFRAME DOVERLAY, 0, STATIC
        EXTERN ??halAssertHandler?relay
        FUNCTION ??halAssertHandler?relay,00H
        EXTERN ??macRxOff?relay
        FUNCTION ??macRxOff?relay,00H
        EXTERN ??macRxOnRequest?relay
        FUNCTION ??macRxOnRequest?relay,00H
        EXTERN ??macRxRadioPowerUpInit?relay
        FUNCTION ??macRxRadioPowerUpInit?relay,00H
        EXTERN macRxActive
        EXTERN macRxEnableFlags
        EXTERN macRxFilter
        EXTERN macRxOutgoingAckFlag
        EXTERN macTxActive

// C:\Texas Instruments 33\ZStack-1.4.3-1.2.1\Components\mac\low_level\srf03\mac_sleep.c
//    1 /**************************************************************************************************
//    2   Filename:       mac_sleep.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 /* exported low-level */
//   49 #include "mac_low_level.h"
//   50 
//   51 /* low-level specific */
//   52 #include "mac_sleep.h"
//   53 #include "mac_radio.h"
//   54 #include "mac_tx.h"
//   55 #include "mac_rx.h"
//   56 #include "mac_rx_onoff.h"
//   57 
//   58 /* target specific */
//   59 #include "mac_radio_defs.h"

        ASEGN SFR_AN:DATA:NOROOT,0a8H
// union <unnamed> volatile __sfr _A_IEN0
_A_IEN0:
        DS 1

        ASEGN SFR_AN:DATA:NOROOT,0beH
// unsigned char volatile __sfr SLEEP
SLEEP:
        DS 1

        ASEGN SFR_AN:DATA:NOROOT,0c3H
// unsigned char volatile __sfr T2CNF
T2CNF:
        DS 1
//   60 
//   61 /* debug */
//   62 #include "mac_assert.h"
//   63 
//   64 
//   65 /* ------------------------------------------------------------------------------------------------
//   66  *                                         Global Variables
//   67  * ------------------------------------------------------------------------------------------------
//   68  */

        RSEG XDATA_I:XDATA:NOROOT(0)
        DATA
//   69 uint8 macSleepState = MAC_SLEEP_STATE_RADIO_OFF;
macSleepState:
        DS 1
        REQUIRE `?<Initializer for macSleepState>`
        REQUIRE __INIT_XDATA_I
//   70 
//   71 
//   72 /**************************************************************************************************
//   73  * @fn          macSleepWakeUp
//   74  *
//   75  * @brief       Wake up the radio from sleep mode.
//   76  *
//   77  * @param       none
//   78  *
//   79  * @return      none
//   80  **************************************************************************************************
//   81  */

        RSEG BANKED_CODE:CODE:NOROOT(0)
//   82 void macSleepWakeUp(void)
macSleepWakeUp:
        CFI Block cfiBlock0 Using cfiCommon0
        CFI Function macSleepWakeUp
//   83 {
        FUNCALL macSleepWakeUp, macRxRadioPowerUpInit
        LOCFRAME ISTACK, 2, STACK
        LOCFRAME PSTACK, 0, STACK
        LOCFRAME XSTACK, 0, STACK
        LOCFRAME IOVERLAY, 0, STATIC
        LOCFRAME DOVERLAY, 0, STATIC
        ARGFRAME ISTACK, 2, STACK
        ARGFRAME PSTACK, 0, STACK
        ARGFRAME XSTACK, 0, STACK
        ARGFRAME IOVERLAY, 0, STATIC
        ARGFRAME DOVERLAY, 0, STATIC
        FUNCALL macSleepWakeUp, halAssertHandler
        LOCFRAME ISTACK, 2, STACK
        LOCFRAME PSTACK, 0, STACK
        LOCFRAME XSTACK, 0, STACK
        LOCFRAME IOVERLAY, 0, STATIC
        LOCFRAME DOVERLAY, 0, STATIC
        ARGFRAME ISTACK, 2, STACK
        ARGFRAME PSTACK, 0, STACK
        ARGFRAME XSTACK, 0, STACK
        ARGFRAME IOVERLAY, 0, STATIC
        ARGFRAME DOVERLAY, 0, STATIC
        FUNCALL macSleepWakeUp, macRxOnRequest
        LOCFRAME ISTACK, 2, STACK
        LOCFRAME PSTACK, 0, STACK
        LOCFRAME XSTACK, 0, STACK
        LOCFRAME IOVERLAY, 0, STATIC
        LOCFRAME DOVERLAY, 0, STATIC
        ARGFRAME ISTACK, 2, STACK
        ARGFRAME PSTACK, 0, STACK
        ARGFRAME XSTACK, 0, STACK
        ARGFRAME IOVERLAY, 0, STATIC
        ARGFRAME DOVERLAY, 0, STATIC
        PUSH    DPL
        CFI DPL0 Frame(CFA_SP, 4)
        CFI CFA_SP SP+-4
        PUSH    DPH
        CFI DPH0 Frame(CFA_SP, 5)
        CFI CFA_SP SP+-5
        ; Saved register size: 2
        ; Auto size: 0
//   84   /* don't wake up radio if it's already awake */
//   85   if (macSleepState == MAC_SLEEP_STATE_AWAKE)
        MOV     DPTR,#macSleepState
        MOVX    A,@DPTR
        JZ      ??macSleepWakeUp_0
//   86   {
//   87     return;
//   88   }
//   89 
//   90   /* wake up MAC timer */
//   91   MAC_RADIO_TIMER_WAKE_UP();
        ORL     0xc3,#0x1
??macSleepWakeUp_1:
        MOV     A,0xc3
        MOV     C,0xE0 /* A   */.0
        JNC     ??macSleepWakeUp_1
//   92 
//   93   /* if radio was completely off, restore from that state first */
//   94   if (macSleepState == MAC_SLEEP_STATE_RADIO_OFF)
        MOVX    A,@DPTR
        XRL     A,#0x2
        JNZ     ??macSleepWakeUp_2
//   95   {
//   96     /* turn on radio power */
//   97     MAC_RADIO_TURN_ON_POWER();
        MOV     DPTR,#-0x20e9
        MOVX    A,@DPTR
        CLR     0xE0 /* A   */.3
        MOVX    @DPTR,A
??macSleepWakeUp_3:
        MOVX    A,@DPTR
        MOV     C,0xE0 /* A   */.4
        JC      ??macSleepWakeUp_3
//   98 
//   99     /* power-up initialization of receive logic */
//  100     macRxRadioPowerUpInit();
        ; Setup parameters for call to function macRxRadioPowerUpInit
        LCALL   ??macRxRadioPowerUpInit?relay
//  101   }
//  102 
//  103   /* turn on the oscillator */
//  104   MAC_RADIO_TURN_ON_OSC();
??macSleepWakeUp_2:
        MOV     A,0xbe
        MOV     C,0xE0 /* A   */.6
        JC      ??macSleepWakeUp_4
        ; Setup parameters for call to function halAssertHandler
        LCALL   ??halAssertHandler?relay
//  105 
//  106   /* update sleep state here before requesting to turn on receiver */
//  107   macSleepState = MAC_SLEEP_STATE_AWAKE;
??macSleepWakeUp_4:
        CLR     A
        MOV     DPTR,#macSleepState
        MOVX    @DPTR,A
//  108 
//  109   /* turn on the receiver if enabled */
//  110   macRxOnRequest();
        ; Setup parameters for call to function macRxOnRequest
        LCALL   ??macRxOnRequest?relay
//  111 }
??macSleepWakeUp_0:
        POP     DPH
        CFI DPH0 SameValue
        CFI CFA_SP SP+-4
        POP     DPL
        CFI DPL0 SameValue
        CFI CFA_SP SP+-3
        LJMP    ?BRET
        CFI EndBlock cfiBlock0
        REQUIRE SLEEP
        REQUIRE T2CNF
//  112 
//  113 
//  114 /**************************************************************************************************
//  115  * @fn          macSleep
//  116  *
//  117  * @brief       Puts radio into the selected sleep mode.
//  118  *
//  119  * @param       sleepState - selected sleep level, see #defines in .h file
//  120  *
//  121  * @return      TRUE if radio was successfully put into selected sleep mode.
//  122  *              FALSE if it was not safe for radio to go to sleep.
//  123  **************************************************************************************************
//  124  */

        RSEG BANKED_CODE:CODE:NOROOT(0)
//  125 uint8 macSleep(uint8 sleepState)
macSleep:
        CFI Block cfiBlock1 Using cfiCommon0
        CFI Function macSleep
//  126 {
        FUNCALL macSleep, halAssertHandler
        LOCFRAME ISTACK, 0, STACK
        LOCFRAME PSTACK, 0, STACK
        LOCFRAME XSTACK, 9, STACK
        LOCFRAME IOVERLAY, 0, STATIC
        LOCFRAME DOVERLAY, 0, STATIC
        ARGFRAME ISTACK, 0, STACK
        ARGFRAME PSTACK, 0, STACK
        ARGFRAME XSTACK, 9, STACK
        ARGFRAME IOVERLAY, 0, STATIC
        ARGFRAME DOVERLAY, 0, STATIC
        FUNCALL macSleep, halAssertHandler
        LOCFRAME ISTACK, 0, STACK
        LOCFRAME PSTACK, 0, STACK
        LOCFRAME XSTACK, 9, STACK
        LOCFRAME IOVERLAY, 0, STATIC
        LOCFRAME DOVERLAY, 0, STATIC
        ARGFRAME ISTACK, 0, STACK
        ARGFRAME PSTACK, 0, STACK
        ARGFRAME XSTACK, 9, STACK
        ARGFRAME IOVERLAY, 0, STATIC
        ARGFRAME DOVERLAY, 0, STATIC
        FUNCALL macSleep, macRxOff
        LOCFRAME ISTACK, 0, STACK
        LOCFRAME PSTACK, 0, STACK
        LOCFRAME XSTACK, 9, STACK
        LOCFRAME IOVERLAY, 0, STATIC
        LOCFRAME DOVERLAY, 0, STATIC
        ARGFRAME ISTACK, 0, STACK
        ARGFRAME PSTACK, 0, STACK
        ARGFRAME XSTACK, 9, STACK
        ARGFRAME IOVERLAY, 0, STATIC
        ARGFRAME DOVERLAY, 0, STATIC
        FUNCALL macSleep, halAssertHandler
        LOCFRAME ISTACK, 0, STACK
        LOCFRAME PSTACK, 0, STACK
        LOCFRAME XSTACK, 9, STACK
        LOCFRAME IOVERLAY, 0, STATIC
        LOCFRAME DOVERLAY, 0, STATIC
        ARGFRAME ISTACK, 0, STACK
        ARGFRAME PSTACK, 0, STACK
        ARGFRAME XSTACK, 9, STACK
        ARGFRAME IOVERLAY, 0, STATIC
        ARGFRAME DOVERLAY, 0, STATIC
        MOV     A,#-0x9
        LCALL   ?BANKED_ENTER_XDATA
        CFI DPH0 load(1, XDATA, add(CFA_XSP16, literal(-1)))
        CFI DPL0 load(1, XDATA, add(CFA_XSP16, literal(-2)))
        CFI ?BRET_EXT load(1, XDATA, add(CFA_XSP16, literal(-3)))
        CFI ?RET_HIGH load(1, XDATA, add(CFA_XSP16, literal(-4)))
        CFI ?RET_LOW load(1, XDATA, add(CFA_XSP16, literal(-5)))
        CFI R7 load(1, XDATA, add(CFA_XSP16, literal(-6)))
        CFI V0 load(1, XDATA, add(CFA_XSP16, literal(-7)))
        CFI VB load(1, XDATA, add(CFA_XSP16, literal(-8)))
        CFI R6 load(1, XDATA, add(CFA_XSP16, literal(-9)))
        CFI CFA_SP SP+0
        CFI CFA_XSP16 add(XSP16, 9)
        ; Saved register size: 9
        ; Auto size: 0
        MOV     A,R1
        MOV     R6,A
//  127   halIntState_t  s;
//  128 
//  129   /* disable interrupts until macSleepState can be set */
//  130   HAL_ENTER_CRITICAL_SECTION(s);
        MOV     C,0xa8.7
        CLR     A
        MOV     0xE0 /* A   */.0,C
        MOV     R7,A
        CLR     0xa8.7
//  131 
//  132   /* assert checks */
//  133   MAC_ASSERT(macSleepState == MAC_SLEEP_STATE_AWAKE); /* radio must be awake to put it to sleep */
        MOV     DPTR,#macSleepState
        MOVX    A,@DPTR
        JZ      ??macSleep_0
        ; Setup parameters for call to function halAssertHandler
        LCALL   ??halAssertHandler?relay
//  134   MAC_ASSERT(macRxFilter == RX_FILTER_OFF); /* do not sleep when scanning or in promiscuous mode */
??macSleep_0:
        MOV     DPTR,#macRxFilter
        MOVX    A,@DPTR
        JZ      ??macSleep_1
        ; Setup parameters for call to function halAssertHandler
        LCALL   ??halAssertHandler?relay
//  135 
//  136   /* if either RX or TX is active or any RX enable flags are set, it's not OK to sleep */
//  137   if (macRxActive || macRxOutgoingAckFlag || macTxActive || macRxEnableFlags)
??macSleep_1:
        MOV     DPTR,#macRxActive
        MOVX    A,@DPTR
        JNZ     ??macSleep_2
        MOV     DPTR,#macRxOutgoingAckFlag
        MOVX    A,@DPTR
        JNZ     ??macSleep_2
        MOV     DPTR,#macTxActive
        MOVX    A,@DPTR
        JNZ     ??macSleep_2
        MOV     DPTR,#macRxEnableFlags
        MOVX    A,@DPTR
        JZ      ??macSleep_3
//  138   {
//  139     HAL_EXIT_CRITICAL_SECTION(s);
??macSleep_2:
        MOV     A,R7
        MOV     C,0xE0 /* A   */.0
        MOV     0xa8.7,C
//  140     return(FALSE);
        MOV     R1,#0x0
        SJMP    ??macSleep_4
//  141   }
//  142 
//  143   /* turn off the receiver */
//  144   macRxOff();
??macSleep_3:
        ; Setup parameters for call to function macRxOff
        LCALL   ??macRxOff?relay
//  145 
//  146   /* update sleep state variable */
//  147   macSleepState = sleepState;
        MOV     A,R6
        MOV     DPTR,#macSleepState
        MOVX    @DPTR,A
//  148 
//  149   /* macSleepState is now set, re-enable interrupts */
//  150   HAL_EXIT_CRITICAL_SECTION(s);
        MOV     A,R7
        MOV     C,0xE0 /* A   */.0
        MOV     0xa8.7,C
//  151 
//  152   /* put MAC timer to sleep */
//  153   MAC_RADIO_TIMER_SLEEP();
        ANL     0xc3,#0xfe
??macSleep_5:
        MOV     A,0xc3
        MOV     C,0xE0 /* A   */.0
        JC      ??macSleep_5
//  154 
//  155   /* put radio in selected sleep mode */
//  156   if (sleepState == MAC_SLEEP_STATE_OSC_OFF)
        MOV     A,#0x1
        XRL     A,R6
        JZ      ??macSleep_6
//  157   {
//  158     MAC_RADIO_TURN_OFF_OSC();
//  159   }
//  160   else
//  161   {
//  162     MAC_ASSERT(sleepState == MAC_SLEEP_STATE_RADIO_OFF); /* unknown sleep state */
        MOV     A,#0x2
        XRL     A,R6
        JZ      ??macSleep_7
        ; Setup parameters for call to function halAssertHandler
        LCALL   ??halAssertHandler?relay
//  163     MAC_RADIO_TURN_OFF_POWER();
??macSleep_7:
        MOV     DPTR,#-0x20e9
        MOVX    A,@DPTR
        SETB    0xE0 /* A   */.3
        MOVX    @DPTR,A
//  164   }
//  165 
//  166   /* radio successfully entered sleep mode */
//  167   return(TRUE);
??macSleep_6:
        MOV     R1,#0x1
??macSleep_4:
        MOV     R7,#0x1
        LJMP    ?BANKED_LEAVE_XDATA
        CFI EndBlock cfiBlock1
        REQUIRE _A_IEN0
        REQUIRE T2CNF
//  168 }

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

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

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

        END
//  169 
//  170 
//  171 
//  172 /**************************************************************************************************
//  173  *                                  Compile Time Integrity Checks
//  174  **************************************************************************************************
//  175  */
//  176 #if ((MAC_SLEEP_STATE_AWAKE == MAC_SLEEP_STATE_OSC_OFF) ||  \ 
//  177      (MAC_SLEEP_STATE_AWAKE == MAC_SLEEP_STATE_RADIO_OFF))
//  178 #error "ERROR!  Non-unique state values."
//  179 #endif
//  180 
//  181 
//  182 /**************************************************************************************************
//  183 */
// 
// 178 bytes in segment BANKED_CODE
//  12 bytes in segment BANK_RELAYS
//   3 bytes in segment SFR_AN
//   1 byte  in segment XDATA_I
//   1 byte  in segment XDATA_ID
// 
// 191 bytes of CODE  memory
//   0 bytes of DATA  memory (+ 3 bytes shared)
//   1 byte  of XDATA memory
//
//Errors: none
//Warnings: none
