###############################################################################
#                                                                             #
# IAR 8051 C/C++ Compiler V7.30B/W32                    12/Sep/2010  21:57:30 #
# 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\hal\target\CC2430BB\hal_uart.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\hal\target\CC2430 #
#                          BB\hal_uart.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\ha #
#                          l_uart.lst                                         #
#    Object file        =  C:\Texas Instruments 33\ZStack-1.4.3-1.2.1\Project #
#                          s\zstack\Project\Location\CC2430DB\RefNode\Obj\hal #
#                          _uart.r51                                          #
#                                                                             #
#                                                                             #
###############################################################################

C:\Texas Instruments 33\ZStack-1.4.3-1.2.1\Components\hal\target\CC2430BB\hal_uart.c
      1          /**************************************************************************************************
      2            Filename:       _hal_uart.c
      3            Revised:        $Date: 2007-11-01 08:44:53 -0700 (Thu, 01 Nov 2007) $
      4            Revision:       $Revision: 15821 $
      5          
      6            Description: This file contains the interface to the H/W UART driver.
      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          #include "hal_types.h"
     45          #include "hal_assert.h"
     46          #include "hal_board.h"

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

   \                                 In  segment SFR_AN, at 0x86
   \   unsigned char volatile __sfr U0CSR
   \                     U0CSR:
   \   000000                DS 1

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

   \                                 In  segment SFR_AN, at 0x95
   \   unsigned char volatile __sfr ST0
   \                     ST0:
   \   000000                DS 1

   \                                 In  segment SFR_AN, at 0xc1
   \   unsigned char volatile __sfr U0DBUF
   \                     U0DBUF:
   \   000000                DS 1

   \                                 In  segment SFR_AN, at 0xc2
   \   unsigned char volatile __sfr U0BAUD
   \                     U0BAUD:
   \   000000                DS 1

   \                                 In  segment SFR_AN, at 0xc4
   \   unsigned char volatile __sfr U0UCR
   \                     U0UCR:
   \   000000                DS 1

   \                                 In  segment SFR_AN, at 0xc5
   \   unsigned char volatile __sfr U0GCR
   \                     U0GCR:
   \   000000                DS 1

   \                                 In  segment SFR_AN, at 0xd1
   \   unsigned char volatile __sfr DMAIRQ
   \                     DMAIRQ:
   \   000000                DS 1

   \                                 In  segment SFR_AN, at 0xd6
   \   unsigned char volatile __sfr DMAARM
   \                     DMAARM:
   \   000000                DS 1

   \                                 In  segment SFR_AN, at 0xd7
   \   unsigned char volatile __sfr DMAREQ
   \                     DMAREQ:
   \   000000                DS 1

   \                                 In  segment SFR_AN, at 0xf1
   \   unsigned char volatile __sfr PERCFG
   \                     PERCFG:
   \   000000                DS 1

   \                                 In  segment SFR_AN, at 0xf2
   \   unsigned char volatile __sfr ADCCFG
   \                     ADCCFG:
   \   000000                DS 1

   \                                 In  segment SFR_AN, at 0xf3
   \   unsigned char volatile __sfr P0SEL
   \                     P0SEL:
   \   000000                DS 1

   \                                 In  segment SFR_AN, at 0xfd
   \   unsigned char volatile __sfr P0DIR
   \                     P0DIR:
   \   000000                DS 1

   \                                 In  segment SFR_AN, at 0xff
   \   unsigned char volatile __sfr P2DIR
   \                     P2DIR:
   \   000000                DS 1
     47          #include "hal_defs.h"
     48          #if defined( HAL_UART_DMA ) && HAL_UART_DMA
     49            #include "hal_dma.h"
     50          #endif
     51          #include "hal_mcu.h"
     52          #include "hal_uart.h"
     53          #include "osal.h"
     54          
     55          /*********************************************************************
     56           * MACROS
     57           */
     58          
     59          #if !defined ( HAL_UART_DEBUG )
     60            #define HAL_UART_DEBUG  FALSE
     61          #endif
     62          
     63          #if !defined ( HAL_UART_CLOSE )
     64            #define HAL_UART_CLOSE  FALSE
     65          #endif
     66          
     67          #if !defined ( HAL_UART_BIG_TX_BUF )
     68            #define HAL_UART_BIG_TX_BUF  FALSE
     69          #endif
     70          
     71          /*
     72           *  The MAC_ASSERT macro is for use during debugging.
     73           *  The given expression must evaluate as "true" or else fatal error occurs.
     74           *  At that point, the call stack feature of the debugger can pinpoint where
     75           *  the problem occurred.
     76           *
     77           *  To disable this feature and save code size, the project should define
     78           *  HAL_UART_DEBUG to FALSE.
     79           */
     80          #if ( HAL_UART_DEBUG )
     81            #define HAL_UART_ASSERT( expr)        HAL_ASSERT( expr )
     82          #else
     83            #define HAL_UART_ASSERT( expr )
     84          #endif
     85          
     86          #define P2DIR_PRIPO               0xC0
     87          #if HAL_UART_0_ENABLE
     88            #define HAL_UART_PRIPO          0x00
     89          #else
     90            #define HAL_UART_PRIPO          0x40
     91          #endif
     92          
     93          #define HAL_UART_0_PERCFG_BIT     0x01  // USART0 on P0, so clear this bit.
     94          //#define HAL_UART_0_P0_RX_TX       0x0c  // Peripheral I/O Select for Rx/Tx.
     95          #if defined ( LOCATION_REFNODE )
     96            #define HAL_UART_0_P0_RX_TX       0x10  // Peripheral I/O Select for Rx/Tx.
     97          #endif
     98          #if defined ( LOCATION_DONGLE )
     99            #define HAL_UART_0_P0_RX_TX       0x0c  // Peripheral I/O Select for Rx/Tx.
    100          #endif
    101          #define HAL_UART_0_P0_RTS         0x10  // Peripheral I/O Select for RTS.
    102          #define HAL_UART_0_P0_CTS         0x20  // Peripheral I/O Select for CTS.
    103          
    104          #define HAL_UART_1_PERCFG_BIT     0x02  // USART1 on P1, so set this bit.
    105          #define HAL_UART_1_P1_RTS         0x10  // Peripheral I/O Select for RTS.
    106          #define HAL_UART_1_P1_CTS         0x20  // Peripheral I/O Select for CTS.
    107          #define HAL_UART_1_P1_RX_TX       0xC0  // Peripheral I/O Select for Rx/Tx.
    108          
    109          #define TX_AVAIL( cfg ) \
    110            ((cfg->txTail == cfg->txHead) ? (cfg->txMax-1) : \
    111            ((cfg->txTail >  cfg->txHead) ? (cfg->txTail - cfg->txHead - 1) : \
    112                               (cfg->txMax - cfg->txHead + cfg->txTail)))
    113          
    114          #define RX0_FLOW_ON  ( P0 &= ~HAL_UART_0_P0_CTS )
    115          #define RX0_FLOW_OFF ( P0 |= HAL_UART_0_P0_CTS )
    116          #define RX1_FLOW_ON  ( P1 &= ~HAL_UART_1_P1_CTS)
    117          #define RX1_FLOW_OFF ( P1 |= HAL_UART_1_P1_CTS )
    118          
    119          #define RX_STOP_FLOW( cfg ) { \
    120            if ( !(cfg->flag & UART_CFG_U1F) ) \
    121            { \
    122              RX0_FLOW_OFF; \
    123            } \
    124            else \
    125            { \
    126              RX1_FLOW_OFF; \
    127            } \
    128            if ( cfg->flag & UART_CFG_DMA ) \
    129            { \
    130              cfg->rxTick = DMA_RX_DLY; \
    131            } \
    132            cfg->flag |= UART_CFG_RXF; \
    133          }
    134          
    135          #define RX_STRT_FLOW( cfg ) { \
    136            if ( !(cfg->flag & UART_CFG_U1F) ) \
    137            { \
    138              RX0_FLOW_ON; \
    139            } \
    140            else \
    141            { \
    142              RX1_FLOW_ON; \
    143            } \
    144            cfg->flag &= ~UART_CFG_RXF; \
    145          }
    146          
    147          #define UART_RX_AVAIL( cfg ) \
    148            ( (cfg->rxHead >= cfg->rxTail) ? (cfg->rxHead - cfg->rxTail) : \
    149                                             (cfg->rxMax - cfg->rxTail + cfg->rxHead +1 ) )
    150          
    151          /* Need to leave enough of the Rx buffer free to handle the incoming bytes
    152           * after asserting flow control, but before the transmitter has obeyed it.
    153           * At the max expected baud rate of 115.2k, 16 bytes will only take ~1.3 msecs,
    154           * but at the min expected baud rate of 38.4k, they could take ~4.2 msecs.
    155           * SAFE_RX_MIN and DMA_RX_DLY must both be consistent according to
    156           * the min & max expected baud rate.
    157           */
    158          #if !defined( SAFE_RX_MIN )
    159            #define SAFE_RX_MIN  48  // bytes - max expected per poll @ 115.2k
    160            // 16 bytes @ 38.4 kBaud -> 4.16 msecs -> 138 32-kHz ticks.
    161            #define DMA_RX_DLY  140
    162            //  2 bytes @ 38.4 kBaud -> 0.52 msecs ->  17 32-kHz ticks.
    163            #define DMA_TX_DLY   20
    164          #endif
    165          
    166          // The timeout tick is at 32-kHz, so multiply msecs by 33.
    167          #define RX_MSECS_TO_TICKS  33
    168          
    169          // The timeout only supports 1 byte.
    170          #if !defined( HAL_UART_RX_IDLE )
    171            #define HAL_UART_RX_IDLE  (6 * RX_MSECS_TO_TICKS)
    172          #endif
    173          
    174          // Only supporting 1 of the 2 USART modules to be driven by DMA at a time.
    175          #if HAL_UART_DMA == 1
    176            #define DMATRIG_RX  HAL_DMA_TRIG_URX0
    177            #define DMATRIG_TX  HAL_DMA_TRIG_UTX0
    178            #define DMA_UDBUF   HAL_DMA_U0DBUF
    179            #define DMA_PAD     U0BAUD
    180          #elif HAL_UART_DMA == 2
    181            #define DMATRIG_RX  HAL_DMA_TRIG_URX1
    182            #define DMATRIG_TX  HAL_DMA_TRIG_UTX1
    183            #define DMA_UDBUF   HAL_DMA_U1DBUF
    184            #define DMA_PAD     U1BAUD
    185          #endif
    186          
    187          #define DMA_RX( cfg ) { \
    188            volatile uint8 ft2430 = U0DBUF; \
    189            \
    190            halDMADesc_t *ch = HAL_DMA_GET_DESC1234( HAL_DMA_CH_RX ); \
    191            \
    192            HAL_DMA_SET_DEST( ch, cfg->rxBuf ); \
    193            \
    194            HAL_DMA_SET_LEN( ch, cfg->rxMax ); \
    195            \
    196            HAL_DMA_CLEAR_IRQ( HAL_DMA_CH_RX ); \
    197            \
    198            HAL_DMA_ARM_CH( HAL_DMA_CH_RX ); \
    199          }
    200          
    201          #define DMA_TX( cfg ) { \
    202            halDMADesc_t *ch = HAL_DMA_GET_DESC1234( HAL_DMA_CH_TX ); \
    203            \
    204            HAL_DMA_SET_SOURCE( ch, (cfg->txBuf + cfg->txTail) ); \
    205            \
    206            HAL_DMA_SET_LEN( ch, cfg->txCnt ); \
    207            \
    208            HAL_DMA_CLEAR_IRQ( HAL_DMA_CH_TX ); \
    209            \
    210            HAL_DMA_ARM_CH( HAL_DMA_CH_TX ); \
    211            \
    212            HAL_DMA_START_CH( HAL_DMA_CH_TX ); \
    213          }
    214          
    215          /*********************************************************************
    216           * TYPEDEFS
    217           */
    218          
    219          typedef struct
    220          {
    221            uint8 *rxBuf;
    222            uint8 rxHead;
    223            uint8 rxTail;
    224            uint8 rxMax;
    225            uint8 rxCnt;
    226            uint8 rxTick;
    227            uint8 rxHigh;
    228          
    229            uint8 *txBuf;
    230          #if HAL_UART_BIG_TX_BUF
    231            uint16 txHead;
    232            uint16 txTail;
    233            uint16 txMax;
    234            uint16 txCnt;
    235          #else
    236            uint8 txHead;
    237            uint8 txTail;
    238            uint8 txMax;
    239            uint8 txCnt;
    240          #endif
    241            uint8 txTick;
    242          
    243            uint8 flag;
    244          
    245            halUARTCBack_t rxCB;
    246          } uartCfg_t;
    247          
    248          /*********************************************************************
    249           * CONSTANTS
    250           */
    251          
    252          // Used by DMA macros to shift 1 to create a mask for DMA registers.
    253          #define HAL_DMA_CH_TX    3
    254          #define HAL_DMA_CH_RX    4
    255          
    256          #define HAL_DMA_U0DBUF  0xDFC1
    257          #define HAL_DMA_U1DBUF  0xDFF9
    258          
    259          // UxCSR - USART Control and Status Register.
    260          #define CSR_MODE      0x80
    261          #define CSR_RE        0x40
    262          #define CSR_SLAVE     0x20
    263          #define CSR_FE        0x10
    264          #define CSR_ERR       0x08
    265          #define CSR_RX_BYTE   0x04
    266          #define CSR_TX_BYTE   0x02
    267          #define CSR_ACTIVE    0x01
    268          
    269          // UxUCR - USART UART Control Register.
    270          #define UCR_FLUSH     0x80
    271          #define UCR_FLOW      0x40
    272          #define UCR_D9        0x20
    273          #define UCR_BIT9      0x10
    274          #define UCR_PARITY    0x08
    275          #define UCR_SPB       0x04
    276          #define UCR_STOP      0x02
    277          #define UCR_START     0x01
    278          
    279          #define UTX0IE        0x04
    280          #define UTX1IE        0x08
    281          
    282          #define UART_CFG_U1F  0x80  // USART1 flag bit.
    283          #define UART_CFG_DMA  0x40  // Port is using DMA.
    284          #define UART_CFG_FLW  0x20  // Port is using flow control.
    285          #define UART_CFG_SP4  0x10
    286          #define UART_CFG_SP3  0x08
    287          #define UART_CFG_SP2  0x04
    288          #define UART_CFG_RXF  0x02  // Rx flow is disabled.
    289          #define UART_CFG_TXF  0x01  // Tx is in process.
    290          
    291          /*********************************************************************
    292           * GLOBAL VARIABLES
    293           */
    294          
    295          /*********************************************************************
    296           * GLOBAL FUNCTIONS
    297           */
    298          
    299          /*********************************************************************
    300           * LOCAL VARIABLES
    301           */
    302          
    303          #if HAL_UART_0_ENABLE

   \                                 In  segment XDATA_Z, align 1, keep-with-next
    304          static uartCfg_t *cfg0;
   \                     cfg0:
   \   000000                DS 2
   \   000002                REQUIRE __INIT_XDATA_Z
    305          #endif
    306          #if HAL_UART_1_ENABLE
    307          static uartCfg_t *cfg1;
    308          #endif
    309          
    310          /*********************************************************************
    311           * LOCAL FUNCTIONS
    312           */
    313          
    314          #if HAL_UART_DMA
    315          static void pollDMA( uartCfg_t *cfg );
    316          #endif
    317          #if HAL_UART_ISR
    318          static void pollISR( uartCfg_t *cfg );
    319          #endif
    320          
    321          #if HAL_UART_DMA
    322          /******************************************************************************
    323           * @fn      pollDMA
    324           *
    325           * @brief   Poll a USART module implemented by DMA.
    326           *
    327           * @param   cfg - USART configuration structure.
    328           *
    329           * @return  none
    330           *****************************************************************************/

   \                                 In  segment BANKED_CODE, align 1, keep-with-next
    331          static void pollDMA( uartCfg_t *cfg )
   \                     pollDMA:
    332          {
   \   000000   74F6         MOV     A,#-0xa
   \   000002   12....       LCALL   ?BANKED_ENTER_XDATA
   \   000005                ; Saved register size: 10
   \   000005                ; Auto size: 1
   \   000005   74FF         MOV     A,#-0x1
   \   000007   12....       LCALL   ?ALLOC_XSTACK8
   \   00000A   EA           MOV     A,R2
   \   00000B   FE           MOV     R6,A
   \   00000C   EB           MOV     A,R3
   \   00000D   FF           MOV     R7,A
    333            const uint8 cnt = cfg->rxHead;
   \   00000E   EE           MOV     A,R6
   \   00000F   2402         ADD     A,#0x2
   \   000011   0A           INC     R2
   \   000012   0A           INC     R2
   \   000013   12....       LCALL   ?Subroutine6 & 0xFFFF
    334            uint8 *pad = cfg->rxBuf+(cfg->rxHead*2);
   \                     ??CrossCallReturnLabel_33:
   \   000016   C3           CLR     C
   \   000017   33           RLC     A
   \   000018   F8           MOV     R0,A
   \   000019   E4           CLR     A
   \   00001A   33           RLC     A
   \   00001B   F9           MOV     R1,A
   \   00001C   8E82         MOV     DPL,R6
   \   00001E   8F83         MOV     DPH,R7
   \   000020   E0           MOVX    A,@DPTR
   \   000021   28           ADD     A,R0
   \   000022   F8           MOV     R0,A
   \   000023   A3           INC     DPTR
   \   000024   E0           MOVX    A,@DPTR
   \   000025   39           ADDC    A,R1
   \   000026   8035         SJMP    ??pollDMA_0
    335          
    336            // Pack the received bytes to the front of the queue.
    337            while ( (*pad == DMA_PAD) && (cfg->rxHead < cfg->rxMax) )
    338            {
    339              cfg->rxBuf[cfg->rxHead++] = *(pad+1);
   \                     ??pollDMA_1:
   \   000028   EE           MOV     A,R6
   \   000029   2402         ADD     A,#0x2
   \   00002B   FA           MOV     R2,A
   \   00002C   8882         MOV     DPL,R0
   \   00002E   8983         MOV     DPH,R1
   \   000030   A3           INC     DPTR
   \   000031   E0           MOVX    A,@DPTR
   \   000032   C0E0         PUSH    A
   \   000034   8A82         MOV     DPL,R2
   \   000036   8B83         MOV     DPH,R3
   \   000038   E0           MOVX    A,@DPTR
   \   000039   F5..         MOV     ?V0 + 0,A
   \   00003B   8E82         MOV     DPL,R6
   \   00003D   8F83         MOV     DPH,R7
   \   00003F   E0           MOVX    A,@DPTR
   \   000040   25..         ADD     A,?V0 + 0
   \   000042   FD           MOV     R5,A
   \   000043   A3           INC     DPTR
   \   000044   E0           MOVX    A,@DPTR
   \   000045   3400         ADDC    A,#0x0
   \   000047   8D82         MOV     DPL,R5
   \   000049   F583         MOV     DPH,A
   \   00004B   D0E0         POP     A
   \   00004D   F0           MOVX    @DPTR,A
   \   00004E   8A82         MOV     DPL,R2
   \   000050   8B83         MOV     DPH,R3
   \   000052   E0           MOVX    A,@DPTR
   \   000053   04           INC     A
   \   000054   F0           MOVX    @DPTR,A
    340              pad += 2;
   \   000055   E8           MOV     A,R0
   \   000056   2402         ADD     A,#0x2
   \   000058   08           INC     R0
   \   000059   08           INC     R0
   \   00005A   E9           MOV     A,R1
   \   00005B   3400         ADDC    A,#0x0
   \                     ??pollDMA_0:
   \   00005D   F9           MOV     R1,A
    341            }
   \   00005E   8882         MOV     DPL,R0
   \   000060   8983         MOV     DPH,R1
   \   000062   E0           MOVX    A,@DPTR
   \   000063   65C2         XRL     A,0xc2
   \   000065   7019         JNZ     ??pollDMA_2
   \   000067   8E82         MOV     DPL,R6
   \   000069   8F83         MOV     DPH,R7
   \   00006B   A3           INC     DPTR
   \   00006C   A3           INC     DPTR
   \   00006D   E0           MOVX    A,@DPTR
   \   00006E   C0E0         PUSH    A
   \   000070   8E82         MOV     DPL,R6
   \   000072   8F83         MOV     DPH,R7
   \   000074   A3           INC     DPTR
   \   000075   A3           INC     DPTR
   \   000076   A3           INC     DPTR
   \   000077   A3           INC     DPTR
   \   000078   E0           MOVX    A,@DPTR
   \   000079   FA           MOV     R2,A
   \   00007A   D0E0         POP     A
   \   00007C   C3           CLR     C
   \   00007D   9A           SUBB    A,R2
   \   00007E   40A8         JC      ??pollDMA_1
    342          
    343            if ( !(cfg->flag & UART_CFG_RXF) )
   \                     ??pollDMA_2:
   \   000080   12....       LCALL   ?Subroutine5 & 0xFFFF
   \                     ??CrossCallReturnLabel_16:
   \   000083   A2E1         MOV     C,0xE0 /* A   */.1
   \   000085   8E82         MOV     DPL,R6
   \   000087   8F83         MOV     DPH,R7
   \   000089   A3           INC     DPTR
   \   00008A   A3           INC     DPTR
   \   00008B   4042         JC      ??pollDMA_3
    344            {
    345              /* It is necessary to stop Rx flow and wait for H/W-enqueued bytes still
    346               * incoming to stop before resetting the DMA Rx engine. If DMA Rx is
    347               * aborted during incoming data, a byte may be lost inside the engine
    348               * during the 2-step transfer process of read/write.
    349               */
    350              if ( cfg->rxHead >= (cfg->rxMax - SAFE_RX_MIN) )
   \   00008D   E0           MOVX    A,@DPTR
   \   00008E   FA           MOV     R2,A
   \   00008F   12....       LCALL   ?Subroutine3 & 0xFFFF
   \                     ??CrossCallReturnLabel_11:
   \   000092   4023         JC      ??pollDMA_4
    351              {
    352                RX_STOP_FLOW( cfg );
   \   000094   12....       LCALL   ?Subroutine4 & 0xFFFF
   \                     ??CrossCallReturnLabel_13:
   \   000097   4004         JC      ??pollDMA_5
   \   000099   D285         SETB    0x80.5
   \   00009B   8002         SJMP    ??pollDMA_6
   \                     ??pollDMA_5:
   \   00009D   D295         SETB    0x90.5
   \                     ??pollDMA_6:
   \   00009F   A2E6         MOV     C,0xE0 /* A   */.6
   \   0000A1   500D         JNC     ??pollDMA_7
   \   0000A3   748C         MOV     A,#-0x74
   \   0000A5   8E82         MOV     DPL,R6
   \   0000A7   8F83         MOV     DPH,R7
   \   0000A9   A3           INC     DPTR
   \   0000AA   A3           INC     DPTR
   \   0000AB   A3           INC     DPTR
   \   0000AC   A3           INC     DPTR
   \   0000AD   A3           INC     DPTR
   \   0000AE   A3           INC     DPTR
   \   0000AF   F0           MOVX    @DPTR,A
   \                     ??pollDMA_7:
   \   0000B0   12....       LCALL   ?Subroutine5 & 0xFFFF
   \                     ??CrossCallReturnLabel_17:
   \   0000B3   D2E1         SETB    0xE0 /* A   */.1
   \   0000B5   8057         SJMP    ??pollDMA_8
    353              }
    354              // If anything received, reset the Rx idle timer.
    355              else if ( cfg->rxHead != cnt )
   \                     ??pollDMA_4:
   \   0000B7   8E82         MOV     DPL,R6
   \   0000B9   8F83         MOV     DPH,R7
   \   0000BB   A3           INC     DPTR
   \   0000BC   A3           INC     DPTR
   \   0000BD   E0           MOVX    A,@DPTR
   \   0000BE   6C           XRL     A,R4
   \   0000BF   604E         JZ      ??pollDMA_9
    356              {
    357                cfg->rxTick = HAL_UART_RX_IDLE;
   \   0000C1   74C6         MOV     A,#-0x3a
   \   0000C3   8E82         MOV     DPL,R6
   \   0000C5   8F83         MOV     DPH,R7
   \   0000C7   A3           INC     DPTR
   \   0000C8   A3           INC     DPTR
   \   0000C9   A3           INC     DPTR
   \   0000CA   A3           INC     DPTR
   \   0000CB   A3           INC     DPTR
   \   0000CC   A3           INC     DPTR
   \   0000CD   803F         SJMP    ??pollDMA_8
    358              }
    359            }
    360            else if ( !cfg->rxTick && (cfg->rxHead == cfg->rxTail) )
   \                     ??pollDMA_3:
   \   0000CF   A3           INC     DPTR
   \   0000D0   A3           INC     DPTR
   \   0000D1   A3           INC     DPTR
   \   0000D2   A3           INC     DPTR
   \   0000D3   E0           MOVX    A,@DPTR
   \   0000D4   7039         JNZ     ??pollDMA_9
   \   0000D6   12....       LCALL   ?Subroutine12 & 0xFFFF
   \                     ??CrossCallReturnLabel_51:
   \   0000D9   7034         JNZ     ??pollDMA_9
    361            {
    362              HAL_DMA_ABORT_CH( HAL_DMA_CH_RX );
   \   0000DB   75D690       MOV     0xd6,#-0x70
    363              cfg->rxHead = cfg->rxTail = 0;
   \   0000DE   12....       LCALL   ?Subroutine18 & 0xFFFF
    364              osal_memset( cfg->rxBuf, ~DMA_PAD, cfg->rxMax*2 );
   \                     ??CrossCallReturnLabel_63:
   \   0000E1   2404         ADD     A,#0x4
   \   0000E3   F5..         MOV     ?V0 + 0,A
   \   0000E5   EF           MOV     A,R7
   \   0000E6   3400         ADDC    A,#0x0
   \   0000E8   F5..         MOV     ?V0 + 1,A
   \   0000EA                ; Setup parameters for call to function osal_memset
   \   0000EA   85..82       MOV     DPL,?V0 + 0
   \   0000ED   F583         MOV     DPH,A
   \   0000EF   12....       LCALL   ?Subroutine10 & 0xFFFF
   \                     ??CrossCallReturnLabel_47:
   \   0000F2   A3           INC     DPTR
   \   0000F3   E0           MOVX    A,@DPTR
   \   0000F4   FB           MOV     R3,A
   \   0000F5   12....       LCALL   ?Subroutine11 & 0xFFFF
    365              DMA_RX( cfg );
   \                     ??CrossCallReturnLabel_49:
   \   0000F8   85..82       MOV     DPL,?V0 + 0
   \   0000FB   85..83       MOV     DPH,?V0 + 1
   \   0000FE   12....       LCALL   ?Subroutine9 & 0xFFFF
    366              RX_STRT_FLOW( cfg );
   \                     ??CrossCallReturnLabel_45:
   \   000101   12....       LCALL   ?Subroutine4 & 0xFFFF
   \                     ??CrossCallReturnLabel_14:
   \   000104   4004         JC      ??pollDMA_10
   \   000106   C285         CLR     0x80.5
   \   000108   8002         SJMP    ??pollDMA_11
   \                     ??pollDMA_10:
   \   00010A   C295         CLR     0x90.5
   \                     ??pollDMA_11:
   \   00010C   C2E1         CLR     0xE0 /* A   */.1
   \                     ??pollDMA_8:
   \   00010E   F0           MOVX    @DPTR,A
    367            }
    368          
    369            if ( HAL_DMA_CHECK_IRQ( HAL_DMA_CH_TX ) )
   \                     ??pollDMA_9:
   \   00010F   E5D1         MOV     A,0xd1
   \   000111   A2E3         MOV     C,0xE0 /* A   */.3
   \   000113   5056         JNC     ??pollDMA_12
    370            {
    371              HAL_DMA_CLEAR_IRQ( HAL_DMA_CH_TX );
   \   000115   53D1F7       ANL     0xd1,#0xf7
    372              cfg->flag &= ~UART_CFG_TXF;
   \   000118   12....       LCALL   ?Subroutine5 & 0xFFFF
   \                     ??CrossCallReturnLabel_18:
   \   00011B   C2E0         CLR     0xE0 /* A   */.0
   \   00011D   F0           MOVX    @DPTR,A
    373              cfg->txTick = DMA_TX_DLY;
   \   00011E   EE           MOV     A,R6
   \   00011F   2412         ADD     A,#0x12
   \   000121   12....       LCALL   ??Subroutine8_0 & 0xFFFF
   \                     ??CrossCallReturnLabel_37:
   \   000124   7414         MOV     A,#0x14
   \   000126   F0           MOVX    @DPTR,A
    374          
    375              if ( (cfg->txMax - cfg->txCnt) < cfg->txTail )
   \   000127   12....       LCALL   ?Subroutine8 & 0xFFFF
   \                     ??CrossCallReturnLabel_38:
   \   00012A   C082         PUSH    DPL
   \   00012C   C083         PUSH    DPH
   \   00012E   EE           MOV     A,R6
   \   00012F   2410         ADD     A,#0x10
   \   000131   12....       LCALL   ??Subroutine1_0 & 0xFFFF
   \                     ??CrossCallReturnLabel_3:
   \   000134   D083         POP     DPH
   \   000136   D082         POP     DPL
   \   000138   E0           MOVX    A,@DPTR
   \   000139   C3           CLR     C
   \   00013A   98           SUBB    A,R0
   \   00013B   FA           MOV     R2,A
   \   00013C   A3           INC     DPTR
   \   00013D   E0           MOVX    A,@DPTR
   \   00013E   99           SUBB    A,R1
   \   00013F   FB           MOV     R3,A
   \   000140   12....       LCALL   ?Subroutine1 & 0xFFFF
   \                     ??CrossCallReturnLabel_4:
   \   000143   C3           CLR     C
   \   000144   EA           MOV     A,R2
   \   000145   98           SUBB    A,R0
   \   000146   EB           MOV     A,R3
   \   000147   99           SUBB    A,R1
   \   000148   EE           MOV     A,R6
   \   000149   500C         JNC     ??pollDMA_13
    376              {
    377                cfg->txTail = 0;  // DMA can only run to the end of the Tx buffer.
   \   00014B   240C         ADD     A,#0xc
   \   00014D   12....       LCALL   ??Subroutine8_0 & 0xFFFF
   \                     ??CrossCallReturnLabel_39:
   \   000150   E4           CLR     A
   \   000151   F0           MOVX    @DPTR,A
   \   000152   A3           INC     DPTR
   \                     ??pollDMA_14:
   \   000153   F0           MOVX    @DPTR,A
   \   000154   02....       LJMP    ??pollDMA_15 & 0xFFFF
    378              }
    379              else
    380              {
    381                cfg->txTail += cfg->txCnt;
   \                     ??pollDMA_13:
   \   000157   2410         ADD     A,#0x10
   \   000159   F582         MOV     DPL,A
   \   00015B   EF           MOV     A,R7
   \   00015C   12....       LCALL   ??Subroutine0_0 & 0xFFFF
   \                     ??CrossCallReturnLabel_0:
   \   00015F   240C         ADD     A,#0xc
   \   000161   12....       LCALL   ??Subroutine5_0 & 0xFFFF
   \                     ??CrossCallReturnLabel_19:
   \   000164   28           ADD     A,R0
   \   000165   F0           MOVX    @DPTR,A
   \   000166   A3           INC     DPTR
   \   000167   E0           MOVX    A,@DPTR
   \   000168   39           ADDC    A,R1
   \   000169   80E8         SJMP    ??pollDMA_14
    382              }
    383            }
    384            else if ( !(cfg->flag & UART_CFG_TXF) && !cfg->txTick )
   \                     ??pollDMA_12:
   \   00016B   12....       LCALL   ?Subroutine5 & 0xFFFF
   \                     ??CrossCallReturnLabel_20:
   \   00016E   A2E0         MOV     C,0xE0 /* A   */.0
   \   000170   5003         JNC     $+5
   \   000172   02....       LJMP    ??pollDMA_15 & 0xFFFF
   \   000175   EE           MOV     A,R6
   \   000176   2412         ADD     A,#0x12
   \   000178   12....       LCALL   ??Subroutine5_0 & 0xFFFF
   \                     ??CrossCallReturnLabel_21:
   \   00017B   6003         JZ      $+5
   \   00017D   02....       LJMP    ??pollDMA_15 & 0xFFFF
    385            {
    386              if ( cfg->txTail != cfg->txHead )
   \   000180   12....       LCALL   ?Subroutine1 & 0xFFFF
   \                     ??CrossCallReturnLabel_5:
   \   000183   8E82         MOV     DPL,R6
   \   000185   8F83         MOV     DPH,R7
   \   000187   A3           INC     DPTR
   \   000188   A3           INC     DPTR
   \   000189   A3           INC     DPTR
   \   00018A   A3           INC     DPTR
   \   00018B   A3           INC     DPTR
   \   00018C   A3           INC     DPTR
   \   00018D   A3           INC     DPTR
   \   00018E   A3           INC     DPTR
   \   00018F   A3           INC     DPTR
   \   000190   A3           INC     DPTR
   \   000191   E0           MOVX    A,@DPTR
   \   000192   68           XRL     A,R0
   \   000193   7003         JNZ     ??pollDMA_16
   \   000195   A3           INC     DPTR
   \   000196   E0           MOVX    A,@DPTR
   \   000197   69           XRL     A,R1
   \                     ??pollDMA_16:
   \   000198   7003         JNZ     $+5
   \   00019A   02....       LJMP    ??pollDMA_15 & 0xFFFF
    387              {
    388                if ( cfg->txTail < cfg->txHead )
   \   00019D   EE           MOV     A,R6
   \   00019E   240C         ADD     A,#0xc
   \   0001A0   12....       LCALL   ??Subroutine8_0 & 0xFFFF
   \                     ??CrossCallReturnLabel_40:
   \   0001A3   C082         PUSH    DPL
   \   0001A5   C083         PUSH    DPH
   \   0001A7   8E82         MOV     DPL,R6
   \   0001A9   8F83         MOV     DPH,R7
   \   0001AB   A3           INC     DPTR
   \   0001AC   A3           INC     DPTR
   \   0001AD   A3           INC     DPTR
   \   0001AE   A3           INC     DPTR
   \   0001AF   A3           INC     DPTR
   \   0001B0   A3           INC     DPTR
   \   0001B1   A3           INC     DPTR
   \   0001B2   A3           INC     DPTR
   \   0001B3   A3           INC     DPTR
   \   0001B4   A3           INC     DPTR
   \   0001B5   12....       LCALL   ?Subroutine24 & 0xFFFF
   \                     ??CrossCallReturnLabel_82:
   \   0001B8   D083         POP     DPH
   \   0001BA   D082         POP     DPL
   \   0001BC   C3           CLR     C
   \   0001BD   E0           MOVX    A,@DPTR
   \   0001BE   98           SUBB    A,R0
   \   0001BF   A3           INC     DPTR
   \   0001C0   E0           MOVX    A,@DPTR
   \   0001C1   99           SUBB    A,R1
   \   0001C2   5022         JNC     ??pollDMA_17
    389                {
    390                  cfg->txCnt = cfg->txHead - cfg->txTail;
   \   0001C4   8E82         MOV     DPL,R6
   \   0001C6   8F83         MOV     DPH,R7
   \   0001C8   A3           INC     DPTR
   \   0001C9   A3           INC     DPTR
   \   0001CA   A3           INC     DPTR
   \   0001CB   A3           INC     DPTR
   \   0001CC   A3           INC     DPTR
   \   0001CD   A3           INC     DPTR
   \   0001CE   A3           INC     DPTR
   \   0001CF   A3           INC     DPTR
   \   0001D0   A3           INC     DPTR
   \   0001D1   A3           INC     DPTR
   \   0001D2   C082         PUSH    DPL
   \   0001D4   C083         PUSH    DPH
   \   0001D6   12....       LCALL   ?Subroutine1 & 0xFFFF
   \                     ??CrossCallReturnLabel_6:
   \   0001D9   D083         POP     DPH
   \   0001DB   D082         POP     DPL
   \   0001DD   E0           MOVX    A,@DPTR
   \   0001DE   C3           CLR     C
   \   0001DF   98           SUBB    A,R0
   \   0001E0   F8           MOV     R0,A
   \   0001E1   A3           INC     DPTR
   \   0001E2   E0           MOVX    A,@DPTR
   \   0001E3   99           SUBB    A,R1
   \   0001E4   801C         SJMP    ??pollDMA_18
    391                }
    392                else  // Can only run DMA engine up to max, then restart at zero.
    393                {
    394                  cfg->txCnt = cfg->txMax - cfg->txTail + 1;
   \                     ??pollDMA_17:
   \   0001E6   12....       LCALL   ?Subroutine8 & 0xFFFF
   \                     ??CrossCallReturnLabel_41:
   \   0001E9   C082         PUSH    DPL
   \   0001EB   C083         PUSH    DPH
   \   0001ED   12....       LCALL   ?Subroutine1 & 0xFFFF
   \                     ??CrossCallReturnLabel_7:
   \   0001F0   D083         POP     DPH
   \   0001F2   D082         POP     DPL
   \   0001F4   E0           MOVX    A,@DPTR
   \   0001F5   C3           CLR     C
   \   0001F6   98           SUBB    A,R0
   \   0001F7   F8           MOV     R0,A
   \   0001F8   A3           INC     DPTR
   \   0001F9   E0           MOVX    A,@DPTR
   \   0001FA   99           SUBB    A,R1
   \   0001FB   F9           MOV     R1,A
   \   0001FC   7401         MOV     A,#0x1
   \   0001FE   28           ADD     A,R0
   \   0001FF   08           INC     R0
   \   000200   E4           CLR     A
   \   000201   39           ADDC    A,R1
   \                     ??pollDMA_18:
   \   000202   F9           MOV     R1,A
   \   000203   EE           MOV     A,R6
   \   000204   2410         ADD     A,#0x10
   \   000206   12....       LCALL   ?Subroutine2 & 0xFFFF
    395                }
    396          
    397                cfg->flag |= UART_CFG_TXF;
   \                     ??CrossCallReturnLabel_8:
   \   000209   12....       LCALL   ?Subroutine5 & 0xFFFF
   \                     ??CrossCallReturnLabel_22:
   \   00020C   D2E0         SETB    0xE0 /* A   */.0
   \   00020E   F0           MOVX    @DPTR,A
    398                DMA_TX( cfg );
   \   00020F   EE           MOV     A,R6
   \   000210   2408         ADD     A,#0x8
   \   000212   F8           MOV     R0,A
   \   000213   EF           MOV     A,R7
   \   000214   3400         ADDC    A,#0x0
   \   000216   F9           MOV     R1,A
   \   000217   EE           MOV     A,R6
   \   000218   240C         ADD     A,#0xc
   \   00021A   FA           MOV     R2,A
   \   00021B   12....       LCALL   ?Subroutine6 & 0xFFFF
   \                     ??CrossCallReturnLabel_34:
   \   00021E   A3           INC     DPTR
   \   00021F   E0           MOVX    A,@DPTR
   \   000220   FD           MOV     R5,A
   \   000221   8882         MOV     DPL,R0
   \   000223   8983         MOV     DPH,R1
   \   000225   E0           MOVX    A,@DPTR
   \   000226   2C           ADD     A,R4
   \   000227   A3           INC     DPTR
   \   000228   E0           MOVX    A,@DPTR
   \   000229   3D           ADDC    A,R5
   \   00022A   90....       MOV     DPTR,#(dmaCh1234 + 16)
   \   00022D   F0           MOVX    @DPTR,A
   \   00022E   8A82         MOV     DPL,R2
   \   000230   8B83         MOV     DPH,R3
   \   000232   E0           MOVX    A,@DPTR
   \   000233   FA           MOV     R2,A
   \   000234   8882         MOV     DPL,R0
   \   000236   8983         MOV     DPH,R1
   \   000238   E0           MOVX    A,@DPTR
   \   000239   2A           ADD     A,R2
   \   00023A   90....       MOV     DPTR,#(dmaCh1234 + 17)
   \   00023D   F0           MOVX    @DPTR,A
   \   00023E   EE           MOV     A,R6
   \   00023F   2410         ADD     A,#0x10
   \   000241   F8           MOV     R0,A
   \   000242   EF           MOV     A,R7
   \   000243   3400         ADDC    A,#0x0
   \   000245   F9           MOV     R1,A
   \   000246   8882         MOV     DPL,R0
   \   000248   8983         MOV     DPH,R1
   \   00024A   E0           MOVX    A,@DPTR
   \   00024B   90....       MOV     DPTR,#(dmaCh1234 + 21)
   \   00024E   F0           MOVX    @DPTR,A
   \   00024F   90....       MOV     DPTR,#(dmaCh1234 + 20)
   \   000252   E0           MOVX    A,@DPTR
   \   000253   54E0         ANL     A,#0xe0
   \   000255   F0           MOVX    @DPTR,A
   \   000256   8882         MOV     DPL,R0
   \   000258   8983         MOV     DPH,R1
   \   00025A   A3           INC     DPTR
   \   00025B   E0           MOVX    A,@DPTR
   \   00025C   F8           MOV     R0,A
   \   00025D   90....       MOV     DPTR,#(dmaCh1234 + 20)
   \   000260   E0           MOVX    A,@DPTR
   \   000261   48           ORL     A,R0
   \   000262   F0           MOVX    @DPTR,A
   \   000263   53D1F7       ANL     0xd1,#0xf7
   \   000266   75D608       MOV     0xd6,#0x8
   \   000269   75D708       MOV     0xd7,#0x8
    399              }
    400            }
    401          }
   \                     ??pollDMA_15:
   \   00026C   7401         MOV     A,#0x1
   \   00026E   12....       LCALL   ?DEALLOC_XSTACK8
   \   000271   7F02         MOV     R7,#0x2
   \   000273   02....       LJMP    ?BANKED_LEAVE_XDATA
   \   000276                REQUIRE _A_P0
   \   000276                REQUIRE _A_P1
   \   000276                REQUIRE U0DBUF
   \   000276                REQUIRE U0BAUD
   \   000276                REQUIRE DMAIRQ
   \   000276                REQUIRE DMAARM
   \   000276                REQUIRE DMAREQ

   \                                 In  segment BANKED_CODE, align 1, keep-with-next
   \                     ?Subroutine8:
   \   000000   EE           MOV     A,R6
   \   000001   240E         ADD     A,#0xe
   \                     ??Subroutine8_0:
   \   000003   F582         MOV     DPL,A
   \   000005   EF           MOV     A,R7
   \                     ??Subroutine8_1:
   \   000006   12....       LCALL   ??Subroutine23_0 & 0xFFFF
   \                     ??CrossCallReturnLabel_80:
   \   000009   22           RET

   \                                 In  segment BANKED_CODE, align 1, keep-with-next
   \                     ?Subroutine6:
   \   000000   EF           MOV     A,R7
   \   000001   3400         ADDC    A,#0x0
   \   000003   FB           MOV     R3,A
   \   000004   8A82         MOV     DPL,R2
   \   000006   8B83         MOV     DPH,R3
   \   000008   E0           MOVX    A,@DPTR
   \   000009   FC           MOV     R4,A
   \   00000A   22           RET

   \                                 In  segment BANKED_CODE, align 1, keep-with-next
   \                     ?Subroutine5:
   \   000000   EE           MOV     A,R6
   \   000001   2413         ADD     A,#0x13
   \                     ??Subroutine5_0:
   \   000003   F582         MOV     DPL,A
   \   000005   EF           MOV     A,R7
   \                     ??Subroutine5_1:
   \   000006   12....       LCALL   ??Subroutine23_0 & 0xFFFF
   \                     ??CrossCallReturnLabel_78:
   \   000009   E0           MOVX    A,@DPTR
   \   00000A   22           RET

   \                                 In  segment BANKED_CODE, align 1, keep-with-next
   \                     ?Subroutine1:
   \   000000   EE           MOV     A,R6
   \   000001   240C         ADD     A,#0xc
   \                     ??Subroutine1_0:
   \   000003   F582         MOV     DPL,A
   \   000005   EF           MOV     A,R7
   \   000006   12....       LCALL   ?Subroutine22 & 0xFFFF
   \                     ??CrossCallReturnLabel_87:
   \   000009   22           RET

   \                                 In  segment BANKED_CODE, align 1, keep-with-next
   \                     ?Subroutine22:
   \   000000   12....       LCALL   ??Subroutine23_0 & 0xFFFF
   \                     ??CrossCallReturnLabel_81:
   \   000003                REQUIRE ?Subroutine24
   \   000003                ; // Fall through to label ?Subroutine24

   \                                 In  segment BANKED_CODE, align 1, keep-with-next
   \                     ?Subroutine24:
   \   000000   E0           MOVX    A,@DPTR
   \   000001   F8           MOV     R0,A
   \   000002   A3           INC     DPTR
   \   000003   E0           MOVX    A,@DPTR
   \   000004   F9           MOV     R1,A
   \   000005   22           RET

   \                                 In  segment BANKED_CODE, align 1, keep-with-next
   \                     ?Subroutine18:
   \   000000   E4           CLR     A
   \   000001   8E82         MOV     DPL,R6
   \   000003   8F83         MOV     DPH,R7
   \   000005   A3           INC     DPTR
   \   000006   A3           INC     DPTR
   \   000007   A3           INC     DPTR
   \   000008   12....       LCALL   ?Subroutine21 & 0xFFFF
   \                     ??CrossCallReturnLabel_75:
   \   00000B   A3           INC     DPTR
   \   00000C   F0           MOVX    @DPTR,A
   \   00000D   EE           MOV     A,R6
   \   00000E   22           RET

   \                                 In  segment BANKED_CODE, align 1, keep-with-next
   \                     ?Subroutine11:
   \   000000   12....       LCALL   ??osal_memset?relay
   \   000003   E5C1         MOV     A,0xc1
   \   000005   85..82       MOV     DPL,?XSP + 0
   \   000008   85..83       MOV     DPH,?XSP + 1
   \   00000B   12....       LCALL   ?Subroutine21 & 0xFFFF
   \                     ??CrossCallReturnLabel_72:
   \   00000E   E0           MOVX    A,@DPTR
   \   00000F   90....       MOV     DPTR,#(dmaCh1234 + 26)
   \   000012   F0           MOVX    @DPTR,A
   \   000013   8E82         MOV     DPL,R6
   \   000015   8F83         MOV     DPH,R7
   \   000017   E0           MOVX    A,@DPTR
   \   000018   90....       MOV     DPTR,#(dmaCh1234 + 27)
   \   00001B   F0           MOVX    @DPTR,A
   \   00001C   22           RET

   \                                 In  segment BANKED_CODE, align 1, keep-with-next
   \                     ?Subroutine10:
   \   000000   E0           MOVX    A,@DPTR
   \   000001   C3           CLR     C
   \   000002   33           RLC     A
   \   000003   FC           MOV     R4,A
   \   000004   E4           CLR     A
   \   000005   33           RLC     A
   \   000006   FD           MOV     R5,A
   \   000007   E5C2         MOV     A,0xc2
   \   000009   F4           CPL     A
   \   00000A   F9           MOV     R1,A
   \   00000B   8E82         MOV     DPL,R6
   \   00000D   8F83         MOV     DPH,R7
   \   00000F   E0           MOVX    A,@DPTR
   \   000010   FA           MOV     R2,A
   \   000011   22           RET

   \                                 In  segment BANKED_CODE, align 1, keep-with-next
   \                     ?Subroutine9:
   \   000000   E0           MOVX    A,@DPTR
   \   000001   90....       MOV     DPTR,#(dmaCh1234 + 29)
   \   000004   F0           MOVX    @DPTR,A
   \   000005   90....       MOV     DPTR,#(dmaCh1234 + 28)
   \   000008   E0           MOVX    A,@DPTR
   \   000009   54E0         ANL     A,#0xe0
   \   00000B   F0           MOVX    @DPTR,A
   \   00000C   53D1EF       ANL     0xd1,#0xef
   \   00000F   75D610       MOV     0xd6,#0x10
   \   000012   22           RET

   \                                 In  segment BANKED_CODE, align 1, keep-with-next
   \                     ?Subroutine2:
   \   000000   12....       LCALL   ?Subroutine23 & 0xFFFF
   \                     ??CrossCallReturnLabel_76:
   \   000003   E8           MOV     A,R0
   \   000004   F0           MOVX    @DPTR,A
   \   000005   A3           INC     DPTR
   \   000006   E9           MOV     A,R1
   \   000007   F0           MOVX    @DPTR,A
   \   000008   22           RET

   \                                 In  segment BANKED_CODE, align 1, keep-with-next
   \                     ?Subroutine0:
   \   000000   F582         MOV     DPL,A
   \   000002   E5..         MOV     A,?V0 + 1
   \                     ??Subroutine0_0:
   \   000004   12....       LCALL   ?Subroutine22 & 0xFFFF
   \                     ??CrossCallReturnLabel_86:
   \   000007   EE           MOV     A,R6
   \   000008   22           RET

   \                                 In  segment BANKED_CODE, align 1, keep-with-next
   \                     ?Subroutine21:
   \   000000   F0           MOVX    @DPTR,A
   \   000001   8E82         MOV     DPL,R6
   \   000003   8F83         MOV     DPH,R7
   \   000005   A3           INC     DPTR
   \   000006   22           RET

   \                                 In  segment BANKED_CODE, align 1, keep-with-next
   \                     ?Subroutine12:
   \   000000   8E82         MOV     DPL,R6
   \   000002   8F83         MOV     DPH,R7
   \   000004   A3           INC     DPTR
   \   000005   A3           INC     DPTR
   \   000006   E0           MOVX    A,@DPTR
   \   000007   FA           MOV     R2,A
   \   000008   8E82         MOV     DPL,R6
   \   00000A   8F83         MOV     DPH,R7
   \   00000C   A3           INC     DPTR
   \   00000D   A3           INC     DPTR
   \   00000E   A3           INC     DPTR
   \   00000F   E0           MOVX    A,@DPTR
   \   000010   6A           XRL     A,R2
   \   000011   22           RET

   \                                 In  segment BANKED_CODE, align 1, keep-with-next
   \                     ?Subroutine4:
   \   000000   EE           MOV     A,R6
   \   000001   2413         ADD     A,#0x13
   \   000003   12....       LCALL   ?Subroutine23 & 0xFFFF
   \                     ??CrossCallReturnLabel_77:
   \   000006   E0           MOVX    A,@DPTR
   \   000007   A2E7         MOV     C,0xE0 /* A   */.7
   \   000009   22           RET

   \                                 In  segment BANKED_CODE, align 1, keep-with-next
   \                     ?Subroutine3:
   \   000000   8E82         MOV     DPL,R6
   \   000002   8F83         MOV     DPH,R7
   \   000004   A3           INC     DPTR
   \   000005   A3           INC     DPTR
   \   000006   A3           INC     DPTR
   \   000007   A3           INC     DPTR
   \   000008   E0           MOVX    A,@DPTR
   \   000009   F8           MOV     R0,A
   \   00000A   74D0         MOV     A,#-0x30
   \   00000C   28           ADD     A,R0
   \   00000D   F8           MOV     R0,A
   \   00000E   74FF         MOV     A,#-0x1
   \   000010   3400         ADDC    A,#0x0
   \   000012   F9           MOV     R1,A
   \   000013   C3           CLR     C
   \   000014   EA           MOV     A,R2
   \   000015   98           SUBB    A,R0
   \   000016   E4           CLR     A
   \   000017   99           SUBB    A,R1
   \   000018   A2D2         MOV     C,0xD0 /* PSW */.2
   \   00001A   65D0         XRL     A,PSW
   \   00001C   33           RLC     A
   \   00001D   22           RET

   \                                 In  segment BANKED_CODE, align 1, keep-with-next
   \                     ?Subroutine23:
   \   000000   F582         MOV     DPL,A
   \   000002   EF           MOV     A,R7
   \                     ??Subroutine23_0:
   \   000003   3400         ADDC    A,#0x0
   \   000005   F583         MOV     DPH,A
   \   000007   22           RET
    402          #endif
    403          
    404          #if HAL_UART_ISR
    405          /******************************************************************************
    406           * @fn      pollISR
    407           *
    408           * @brief   Poll a USART module implemented by ISR.
    409           *
    410           * @param   cfg - USART configuration structure.
    411           *
    412           * @return  none
    413           *****************************************************************************/
    414          static void pollISR( uartCfg_t *cfg )
    415          {
    416            uint8 cnt = UART_RX_AVAIL( cfg );
    417          
    418            if ( !(cfg->flag & UART_CFG_RXF) )
    419            {
    420              // If anything received, reset the Rx idle timer.
    421              if ( cfg->rxCnt != cnt )
    422              {
    423                cfg->rxTick = HAL_UART_RX_IDLE;
    424                cfg->rxCnt = cnt;
    425              }
    426          
    427              /* It is necessary to stop Rx flow in advance of a full Rx buffer because
    428               * bytes can keep coming while sending H/W fifo flushes.
    429               */
    430              if ( cfg->rxCnt >= (cfg->rxMax - SAFE_RX_MIN) )
    431              {
    432                RX_STOP_FLOW( cfg );
    433              }
    434            }
    435          }
    436          #endif
    437          
    438          /******************************************************************************
    439           * @fn      HalUARTInit
    440           *
    441           * @brief   Initialize the UART
    442           *
    443           * @param   none
    444           *
    445           * @return  none
    446           *****************************************************************************/

   \                                 In  segment BANKED_CODE, align 1, keep-with-next
    447          void HalUARTInit( void )
   \                     HalUARTInit:
    448          {
   \   000000   C082         PUSH    DPL
   \   000002   C083         PUSH    DPH
   \   000004                ; Saved register size: 2
   \   000004                ; Auto size: 0
    449          #if HAL_UART_DMA
    450            halDMADesc_t *ch;
    451          #endif
    452          
    453            // Set P2 priority - USART0 over USART1 if both are defined.
    454            P2DIR &= ~P2DIR_PRIPO;
   \   000004   53FF3F       ANL     0xff,#0x3f
   \   000007   E5FF         MOV     A,0xff
    455            P2DIR |= HAL_UART_PRIPO;
   \   000009   85FFFF       MOV     0xff,0xff
    456          
    457          #if HAL_UART_0_ENABLE
    458            // Set UART0 I/O location to P0.
    459            PERCFG &= ~HAL_UART_0_PERCFG_BIT;
   \   00000C   53F1FE       ANL     0xf1,#0xfe
    460          
    461            /* Enable Tx and Rx on P0 */
    462            P0SEL |= HAL_UART_0_P0_RX_TX;
   \   00000F   43F310       ORL     0xf3,#0x10
    463          
    464            /* Make sure ADC doesnt use this */
    465            ADCCFG &= ~HAL_UART_0_P0_RX_TX;
   \   000012   53F2EF       ANL     0xf2,#0xef
    466          
    467            /* Mode is UART Mode */
    468            U0CSR = CSR_MODE;
   \   000015   758680       MOV     0x86,#-0x80
    469          
    470            /* Flush it */
    471            U0UCR = UCR_FLUSH;
   \   000018   75C480       MOV     0xc4,#-0x80
    472          #endif
    473          
    474          #if HAL_UART_1_ENABLE
    475            // Set UART1 I/O location to P1.
    476            PERCFG |= HAL_UART_1_PERCFG_BIT;
    477          
    478            /* Enable Tx and Rx on P1 */
    479            P1SEL  |= HAL_UART_1_P1_RX_TX;
    480          
    481            /* Make sure ADC doesnt use this */
    482            ADCCFG &= ~HAL_UART_1_P1_RX_TX;
    483          
    484            /* Mode is UART Mode */
    485            U1CSR = CSR_MODE;
    486          
    487            /* Flush it */
    488            U1UCR = UCR_FLUSH;
    489          #endif
    490          
    491          #if HAL_UART_DMA
    492            // Setup Tx by DMA.
    493            ch = HAL_DMA_GET_DESC1234( HAL_DMA_CH_TX );
    494          
    495            // The start address of the destination.
    496            HAL_DMA_SET_DEST( ch, DMA_UDBUF );
   \   00001B   74DF         MOV     A,#-0x21
   \   00001D   90....       MOV     DPTR,#(dmaCh1234 + 18)
   \   000020   F0           MOVX    @DPTR,A
   \   000021   74C1         MOV     A,#-0x3f
   \   000023   90....       MOV     DPTR,#(dmaCh1234 + 19)
   \   000026   F0           MOVX    @DPTR,A
    497          
    498            // Using the length field to determine how many bytes to transfer.
    499            HAL_DMA_SET_VLEN( ch, HAL_DMA_VLEN_USE_LEN );
   \   000027   90....       MOV     DPTR,#(dmaCh1234 + 20)
   \   00002A   E0           MOVX    A,@DPTR
   \   00002B   541F         ANL     A,#0x1f
   \   00002D   F0           MOVX    @DPTR,A
    500          
    501            // One byte is transferred each time.
    502            HAL_DMA_SET_WORD_SIZE( ch, HAL_DMA_WORDSIZE_BYTE );
    503          
    504            // The bytes are transferred 1-by-1 on Tx Complete trigger.
    505            HAL_DMA_SET_TRIG_MODE( ch, HAL_DMA_TMODE_SINGLE );
    506            HAL_DMA_SET_TRIG_SRC( ch, DMATRIG_TX );
   \   00002E   740F         MOV     A,#0xf
   \   000030   90....       MOV     DPTR,#(dmaCh1234 + 22)
   \   000033   F0           MOVX    @DPTR,A
    507          
    508            // The source address is decremented by 1 byte after each transfer.
    509            HAL_DMA_SET_SRC_INC( ch, HAL_DMA_SRCINC_1 );
    510          
    511            // The destination address is constant - the Tx Data Buffer.
    512            HAL_DMA_SET_DST_INC( ch, HAL_DMA_DSTINC_0 );
    513          
    514            // The DMA is to be polled and shall not issue an IRQ upon completion.
    515            HAL_DMA_SET_IRQ( ch, HAL_DMA_IRQMASK_DISABLE );
    516          
    517            // Xfer all 8 bits of a byte xfer.
    518            HAL_DMA_SET_M8( ch, HAL_DMA_M8_USE_8_BITS );
    519          
    520            // DMA Tx has shared priority for memory access - every other one.
    521            HAL_DMA_SET_PRIORITY( ch, HAL_DMA_PRI_HIGH );
   \   000034   7442         MOV     A,#0x42
   \   000036   90....       MOV     DPTR,#(dmaCh1234 + 23)
   \   000039   F0           MOVX    @DPTR,A
    522          
    523            // Setup Rx by DMA.
    524            ch = HAL_DMA_GET_DESC1234( HAL_DMA_CH_RX );
    525          
    526            // The start address of the source.
    527            HAL_DMA_SET_SOURCE( ch, DMA_UDBUF );
   \   00003A   74DF         MOV     A,#-0x21
   \   00003C   90....       MOV     DPTR,#(dmaCh1234 + 24)
   \   00003F   F0           MOVX    @DPTR,A
   \   000040   74C1         MOV     A,#-0x3f
   \   000042   90....       MOV     DPTR,#(dmaCh1234 + 25)
   \   000045   F0           MOVX    @DPTR,A
    528          
    529            // Using the length field to determine how many bytes to transfer.
    530            HAL_DMA_SET_VLEN( ch, HAL_DMA_VLEN_USE_LEN );
   \   000046   90....       MOV     DPTR,#(dmaCh1234 + 28)
   \   000049   E0           MOVX    A,@DPTR
   \   00004A   541F         ANL     A,#0x1f
   \   00004C   F0           MOVX    @DPTR,A
    531          
    532            /* The trick is to cfg DMA to xfer 2 bytes for every 1 byte of Rx.
    533             * The byte after the Rx Data Buffer is the Baud Cfg Register,
    534             * which always has a known value. So init Rx buffer to inverse of that
    535             * known value. DMA word xfer will flip the bytes, so every valid Rx byte
    536             * in the Rx buffer will be preceded by a DMA_PAD char equal to the
    537             * Baud Cfg Register value.
    538             */
    539            HAL_DMA_SET_WORD_SIZE( ch, HAL_DMA_WORDSIZE_WORD );
    540          
    541            // The bytes are transferred 1-by-1 on Rx Complete trigger.
    542            HAL_DMA_SET_TRIG_MODE( ch, HAL_DMA_TMODE_SINGLE );
    543            HAL_DMA_SET_TRIG_SRC( ch, DMATRIG_RX );
   \   00004D   748E         MOV     A,#-0x72
   \   00004F   90....       MOV     DPTR,#(dmaCh1234 + 30)
   \   000052   F0           MOVX    @DPTR,A
    544          
    545            // The source address is constant - the Rx Data Buffer.
    546            HAL_DMA_SET_SRC_INC( ch, HAL_DMA_SRCINC_0 );
    547          
    548            // The destination address is incremented by 1 word after each transfer.
    549            HAL_DMA_SET_DST_INC( ch, HAL_DMA_DSTINC_1 );
    550          
    551            // The DMA is to be polled and shall not issue an IRQ upon completion.
    552            HAL_DMA_SET_IRQ( ch, HAL_DMA_IRQMASK_DISABLE );
    553          
    554            // Xfer all 8 bits of a byte xfer.
    555            HAL_DMA_SET_M8( ch, HAL_DMA_M8_USE_8_BITS );
    556          
    557            // DMA has highest priority for memory access.
    558            HAL_DMA_SET_PRIORITY( ch, HAL_DMA_PRI_HIGH );
   \   000053   7412         MOV     A,#0x12
   \   000055   90....       MOV     DPTR,#(dmaCh1234 + 31)
   \   000058   F0           MOVX    @DPTR,A
    559          #endif
    560          }
   \   000059                REQUIRE ?Subroutine25
   \   000059                REQUIRE U0CSR
   \   000059                REQUIRE U0UCR
   \   000059                REQUIRE PERCFG
   \   000059                REQUIRE ADCCFG
   \   000059                REQUIRE P0SEL
   \   000059                REQUIRE P2DIR
   \   000059                ; // Fall through to label ?Subroutine25

   \                                 In  segment BANKED_CODE, align 1, keep-with-next
   \                     ?Subroutine25:
   \   000000   D083         POP     DPH
   \   000002   D082         POP     DPL
   \   000004   02....       LJMP    ?BRET
    561          
    562          /******************************************************************************
    563           * @fn      HalUARTOpen
    564           *
    565           * @brief   Open a port according tp the configuration specified by parameter.
    566           *
    567           * @param   port   - UART port
    568           *          config - contains configuration information
    569           *
    570           * @return  Status of the function call
    571           *****************************************************************************/

   \                                 In  segment BANKED_CODE, align 1, keep-with-next
    572          uint8 HalUARTOpen( uint8 port, halUARTCfg_t *config )
   \                     HalUARTOpen:
    573          {
   \   000000   74F2         MOV     A,#-0xe
   \   000002   12....       LCALL   ?BANKED_ENTER_XDATA
   \   000005                ; Saved register size: 14
   \   000005                ; Auto size: 1
   \   000005   74FF         MOV     A,#-0x1
   \   000007   12....       LCALL   ?ALLOC_XSTACK8
   \   00000A   89..         MOV     ?V0 + 2,R1
   \   00000C   8A..         MOV     ?V0 + 0,R2
   \   00000E   8B..         MOV     ?V0 + 1,R3
    574            uartCfg_t **cfgPP = NULL;
   \   000010   7E00         MOV     R6,#0x0
   \   000012   7F00         MOV     R7,#0x0
    575            uartCfg_t *cfg;
    576          
    577          #if HAL_UART_0_ENABLE
    578            if ( port == HAL_UART_PORT_0 )
   \   000014   E9           MOV     A,R1
   \   000015   7004         JNZ     ??HalUARTOpen_0
    579            {
    580              cfgPP = &cfg0;
   \   000017   7E..         MOV     R6,#(cfg0 & 0xff)
   \   000019   7F..         MOV     R7,#((cfg0 >> 8) & 0xff)
    581            }
    582          #endif
    583          
    584          #if HAL_UART_1_ENABLE
    585            if ( port == HAL_UART_PORT_1 )
    586            {
    587              cfgPP = &cfg1;
    588            }
    589          #endif
    590          
    591            HAL_UART_ASSERT( cfgPP );
    592          
    593          #if HAL_UART_CLOSE
    594            // Protect against user re-opening port before closing it.
    595            HalUARTClose( port );
    596          #else
    597            HAL_UART_ASSERT( *cfgPP == NULL );
    598          #endif
    599          
    600            HAL_UART_ASSERT( (config->baudRate == HAL_UART_BR_38400) ||
    601                             (config->baudRate == HAL_UART_BR_115200) );
    602          
    603            /* Whereas runtime heap alloc can be expected to fail - one-shot system
    604             * initialization must succeed, so no check for alloc fail.
    605             */
    606            *cfgPP = (uartCfg_t *)osal_mem_alloc( sizeof( uartCfg_t ) );
   \                     ??HalUARTOpen_0:
   \   00001B                ; Setup parameters for call to function osal_mem_alloc
   \   00001B   7A16         MOV     R2,#0x16
   \   00001D   7B00         MOV     R3,#0x0
   \   00001F   12....       LCALL   ?Subroutine19 & 0xFFFF
    607            cfg = *cfgPP;
   \                     ??CrossCallReturnLabel_65:
   \   000022   8E82         MOV     DPL,R6
   \   000024   8F83         MOV     DPH,R7
   \   000026   E0           MOVX    A,@DPTR
   \   000027   FE           MOV     R6,A
   \   000028   A3           INC     DPTR
   \   000029   E0           MOVX    A,@DPTR
   \   00002A   FF           MOV     R7,A
    608            HAL_UART_ASSERT( cfg );
    609          
    610            cfg->rxMax = config->rx.maxBufSize;
   \   00002B   E5..         MOV     A,?V0 + 0
   \   00002D   240A         ADD     A,#0xa
   \   00002F   F5..         MOV     ?V0 + 4,A
   \   000031   E5..         MOV     A,?V0 + 1
   \   000033   3400         ADDC    A,#0x0
   \   000035   F5..         MOV     ?V0 + 5,A
   \   000037   85..82       MOV     DPL,?V0 + 4
   \   00003A   F583         MOV     DPH,A
   \   00003C   E0           MOVX    A,@DPTR
   \   00003D   8E82         MOV     DPL,R6
   \   00003F   8F83         MOV     DPH,R7
   \   000041   A3           INC     DPTR
   \   000042   A3           INC     DPTR
   \   000043   A3           INC     DPTR
   \   000044   A3           INC     DPTR
   \   000045   F0           MOVX    @DPTR,A
    611          
    612          #if !HAL_UART_BIG_TX_BUF
    613            HAL_UART_ASSERT( (config->tx.maxBufSize < 256) );
    614          #endif
    615            cfg->txMax = config->tx.maxBufSize;
   \   000046   E5..         MOV     A,?V0 + 0
   \   000048   2412         ADD     A,#0x12
   \   00004A   12....       LCALL   ?Subroutine0 & 0xFFFF
   \                     ??CrossCallReturnLabel_1:
   \   00004D   240E         ADD     A,#0xe
   \   00004F   12....       LCALL   ?Subroutine2 & 0xFFFF
    616            cfg->txBuf = osal_mem_alloc( cfg->txMax+1 );
   \                     ??CrossCallReturnLabel_9:
   \   000052                ; Setup parameters for call to function osal_mem_alloc
   \   000052   7401         MOV     A,#0x1
   \   000054   28           ADD     A,R0
   \   000055   FA           MOV     R2,A
   \   000056   E4           CLR     A
   \   000057   39           ADDC    A,R1
   \   000058   FB           MOV     R3,A
   \   000059   12....       LCALL   ??osal_mem_alloc?relay
   \   00005C   8E82         MOV     DPL,R6
   \   00005E   8F83         MOV     DPH,R7
   \   000060   A3           INC     DPTR
   \   000061   A3           INC     DPTR
   \   000062   A3           INC     DPTR
   \   000063   A3           INC     DPTR
   \   000064   A3           INC     DPTR
   \   000065   A3           INC     DPTR
   \   000066   A3           INC     DPTR
   \   000067   A3           INC     DPTR
   \   000068   EA           MOV     A,R2
   \   000069   F0           MOVX    @DPTR,A
   \   00006A   A3           INC     DPTR
   \   00006B   EB           MOV     A,R3
   \   00006C   F0           MOVX    @DPTR,A
    617          
    618            cfg->rxHead = cfg->rxTail = 0;
   \   00006D   12....       LCALL   ?Subroutine18 & 0xFFFF
    619            cfg->txHead = cfg->txTail = 0;
   \                     ??CrossCallReturnLabel_64:
   \   000070   240C         ADD     A,#0xc
   \   000072   F582         MOV     DPL,A
   \   000074   EF           MOV     A,R7
   \   000075   12....       LCALL   ?Subroutine7 & 0xFFFF
   \                     ??CrossCallReturnLabel_35:
   \   000078   8E82         MOV     DPL,R6
   \   00007A   8F83         MOV     DPH,R7
   \   00007C   A3           INC     DPTR
   \   00007D   A3           INC     DPTR
   \   00007E   A3           INC     DPTR
   \   00007F   A3           INC     DPTR
   \   000080   A3           INC     DPTR
   \   000081   A3           INC     DPTR
   \   000082   A3           INC     DPTR
   \   000083   A3           INC     DPTR
   \   000084   A3           INC     DPTR
   \   000085   A3           INC     DPTR
   \   000086   F0           MOVX    @DPTR,A
   \   000087   A3           INC     DPTR
   \   000088   F0           MOVX    @DPTR,A
    620            cfg->rxHigh = config->rx.maxBufSize - config->flowControlThreshold;
   \   000089   85..82       MOV     DPL,?V0 + 0
   \   00008C   85..83       MOV     DPH,?V0 + 1
   \   00008F   A3           INC     DPTR
   \   000090   A3           INC     DPTR
   \   000091   A3           INC     DPTR
   \   000092   E0           MOVX    A,@DPTR
   \   000093   F8           MOV     R0,A
   \   000094   85..82       MOV     DPL,?V0 + 4
   \   000097   85..83       MOV     DPH,?V0 + 5
   \   00009A   E0           MOVX    A,@DPTR
   \   00009B   C3           CLR     C
   \   00009C   98           SUBB    A,R0
   \   00009D   8E82         MOV     DPL,R6
   \   00009F   8F83         MOV     DPH,R7
   \   0000A1   A3           INC     DPTR
   \   0000A2   A3           INC     DPTR
   \   0000A3   A3           INC     DPTR
   \   0000A4   A3           INC     DPTR
   \   0000A5   A3           INC     DPTR
   \   0000A6   A3           INC     DPTR
   \   0000A7   A3           INC     DPTR
   \   0000A8   F0           MOVX    @DPTR,A
    621            cfg->rxCB = config->callBackFunc;
   \   0000A9   E5..         MOV     A,?V0 + 0
   \   0000AB   241B         ADD     A,#0x1b
   \   0000AD   12....       LCALL   ?Subroutine0 & 0xFFFF
   \                     ??CrossCallReturnLabel_2:
   \   0000B0   2414         ADD     A,#0x14
   \   0000B2   12....       LCALL   ?Subroutine2 & 0xFFFF
    622          
    623          #if HAL_UART_0_ENABLE
    624            if ( port == HAL_UART_PORT_0 )
   \                     ??CrossCallReturnLabel_10:
   \   0000B5   E5..         MOV     A,?V0 + 2
   \   0000B7   6003         JZ      $+5
   \   0000B9   02....       LJMP    ??HalUARTOpen_1 & 0xFFFF
    625            {
    626              // Only supporting 38400 or 115200 for code size - other is possible.
    627              U0BAUD = (config->baudRate == HAL_UART_BR_38400) ? 59 : 216;
   \   0000BC   85..82       MOV     DPL,?V0 + 0
   \   0000BF   85..83       MOV     DPH,?V0 + 1
   \   0000C2   A3           INC     DPTR
   \   0000C3   E0           MOVX    A,@DPTR
   \   0000C4   6406         XRL     A,#0x6
   \   0000C6   7004         JNZ     ??HalUARTOpen_2
   \   0000C8   7A3B         MOV     R2,#0x3b
   \   0000CA   8002         SJMP    ??HalUARTOpen_3
   \                     ??HalUARTOpen_2:
   \   0000CC   7AD8         MOV     R2,#-0x28
   \                     ??HalUARTOpen_3:
   \   0000CE   8AC2         MOV     0xc2,R2
    628              U0GCR = (config->baudRate == HAL_UART_BR_38400) ? 10 : 11;
   \   0000D0   85..82       MOV     DPL,?V0 + 0
   \   0000D3   85..83       MOV     DPH,?V0 + 1
   \   0000D6   A3           INC     DPTR
   \   0000D7   E0           MOVX    A,@DPTR
   \   0000D8   6406         XRL     A,#0x6
   \   0000DA   7004         JNZ     ??HalUARTOpen_4
   \   0000DC   7A0A         MOV     R2,#0xa
   \   0000DE   8002         SJMP    ??HalUARTOpen_5
   \                     ??HalUARTOpen_4:
   \   0000E0   7A0B         MOV     R2,#0xb
   \                     ??HalUARTOpen_5:
   \   0000E2   8AC5         MOV     0xc5,R2
    629          
    630              U0CSR |= CSR_RE;
   \   0000E4   438640       ORL     0x86,#0x40
    631          
    632          #if HAL_UART_DMA == 1
    633              cfg->flag = UART_CFG_DMA;
   \   0000E7   EE           MOV     A,R6
   \   0000E8   2413         ADD     A,#0x13
   \   0000EA   12....       LCALL   ??Subroutine8_0 & 0xFFFF
   \                     ??CrossCallReturnLabel_42:
   \   0000ED   7440         MOV     A,#0x40
   \   0000EF   F0           MOVX    @DPTR,A
    634              HAL_UART_ASSERT( (config->rx.maxBufSize <= 128) );
    635              HAL_UART_ASSERT( (config->rx.maxBufSize > SAFE_RX_MIN) );
    636              cfg->rxBuf = osal_mem_alloc( cfg->rxMax*2 );
   \   0000F0   EE           MOV     A,R6
   \   0000F1   2404         ADD     A,#0x4
   \   0000F3   F5..         MOV     ?V0 + 2,A
   \   0000F5   EF           MOV     A,R7
   \   0000F6   3400         ADDC    A,#0x0
   \   0000F8   F5..         MOV     ?V0 + 3,A
   \   0000FA                ; Setup parameters for call to function osal_mem_alloc
   \   0000FA   85..82       MOV     DPL,?V0 + 2
   \   0000FD   F583         MOV     DPH,A
   \   0000FF   E0           MOVX    A,@DPTR
   \   000100   C3           CLR     C
   \   000101   33           RLC     A
   \   000102   FA           MOV     R2,A
   \   000103   E4           CLR     A
   \   000104   33           RLC     A
   \   000105   FB           MOV     R3,A
   \   000106   12....       LCALL   ?Subroutine19 & 0xFFFF
    637              osal_memset( cfg->rxBuf, ~DMA_PAD, cfg->rxMax*2 );
   \                     ??CrossCallReturnLabel_66:
   \   000109                ; Setup parameters for call to function osal_memset
   \   000109   85..82       MOV     DPL,?V0 + 2
   \   00010C   85..83       MOV     DPH,?V0 + 3
   \   00010F   12....       LCALL   ?Subroutine10 & 0xFFFF
   \                     ??CrossCallReturnLabel_48:
   \   000112   12....       LCALL   ?Subroutine11 & 0xFFFF
    638              DMA_RX( cfg );
   \                     ??CrossCallReturnLabel_50:
   \   000115   85..82       MOV     DPL,?V0 + 2
   \   000118   85..83       MOV     DPH,?V0 + 3
   \   00011B   12....       LCALL   ?Subroutine9 & 0xFFFF
    639          #else
    640              cfg->flag = 0;
    641              HAL_UART_ASSERT( (config->rx.maxBufSize < 256) );
    642              cfg->rxBuf = osal_mem_alloc( cfg->rxMax+1 );
    643              URX0IE = 1;
    644              IEN2 |= UTX0IE;
    645          #endif
    646          
    647              // 8 bits/char; no parity; 1 stop bit; stop bit hi.
    648              if ( config->flowControl )
   \                     ??CrossCallReturnLabel_46:
   \   00011E   85..82       MOV     DPL,?V0 + 0
   \   000121   85..83       MOV     DPH,?V0 + 1
   \   000124   A3           INC     DPTR
   \   000125   A3           INC     DPTR
   \   000126   E0           MOVX    A,@DPTR
   \   000127   6013         JZ      ??HalUARTOpen_6
    649              {
    650                cfg->flag |= UART_CFG_FLW;
   \   000129   12....       LCALL   ?Subroutine5 & 0xFFFF
   \                     ??CrossCallReturnLabel_23:
   \   00012C   D2E5         SETB    0xE0 /* A   */.5
   \   00012E   F0           MOVX    @DPTR,A
    651                U0UCR = UCR_FLOW | UCR_STOP;
   \   00012F   75C442       MOV     0xc4,#0x42
    652                // Must rely on H/W for RTS (i.e. Tx stops when receiver negates CTS.)
    653                P0SEL |= HAL_UART_0_P0_RTS;
   \   000132   43F310       ORL     0xf3,#0x10
    654                // Cannot use H/W for CTS as DMA does not clear the Rx bytes properly.
    655                P0DIR |= HAL_UART_0_P0_CTS;
   \   000135   43FD20       ORL     0xfd,#0x20
    656                RX0_FLOW_ON;
   \   000138   C285         CLR     0x80.5
   \   00013A   8003         SJMP    ??HalUARTOpen_1
    657              }
    658              else
    659              {
    660                U0UCR = UCR_STOP;
   \                     ??HalUARTOpen_6:
   \   00013C   75C402       MOV     0xc4,#0x2
    661              }
    662              }
    663          #endif
    664          
    665          #if HAL_UART_1_ENABLE
    666            if ( port == HAL_UART_PORT_1 )
    667            {
    668              // Only supporting 38400 or 115200 for code size - other is possible.
    669              U1BAUD = (config->baudRate == HAL_UART_BR_38400) ? 59 : 216;
    670              U1GCR = (config->baudRate == HAL_UART_BR_38400) ? 10 : 11;
    671          
    672              U1CSR |= CSR_RE;
    673          
    674          #if HAL_UART_DMA == 2
    675              cfg->flag = (UART_CFG_U1F | UART_CFG_DMA);
    676              HAL_UART_ASSERT( (config->rx.maxBufSize <= 128) );
    677              HAL_UART_ASSERT( (config->rx.maxBufSize > SAFE_RX_MIN) );
    678              cfg->rxBuf = osal_mem_alloc( cfg->rxMax*2 );
    679              osal_memset( cfg->rxBuf, ~DMA_PAD, cfg->rxMax*2 );
    680              DMA_RX( cfg );
    681          #else
    682              cfg->flag = UART_CFG_U1F;
    683              HAL_UART_ASSERT( (config->rx.maxBufSize < 256) );
    684              cfg->rxBuf = osal_mem_alloc( cfg->rxMax+1 );
    685              URX1IE = 1;
    686              IEN2 |= UTX1IE;
    687          #endif
    688          
    689              // 8 bits/char; no parity; 1 stop bit; stop bit hi.
    690              if ( config->flowControl )
    691              {
    692                cfg->flag |= UART_CFG_FLW;
    693                U1UCR = UCR_FLOW | UCR_STOP;
    694                // Must rely on H/W for RTS (i.e. Tx stops when receiver negates CTS.)
    695                P1SEL |= HAL_UART_1_P1_RTS;
    696                // Cannot use H/W for CTS as DMA does not clear the Rx bytes properly.
    697                P1DIR |= HAL_UART_1_P1_CTS;
    698                RX1_FLOW_ON;
    699              }
    700              else
    701              {
    702                U1UCR = UCR_STOP;
    703              }
    704            }
    705          #endif
    706          
    707            return HAL_UART_SUCCESS;
   \                     ??HalUARTOpen_1:
   \   00013F   7900         MOV     R1,#0x0
   \   000141   7401         MOV     A,#0x1
   \   000143   12....       LCALL   ?DEALLOC_XSTACK8
   \   000146   7F06         MOV     R7,#0x6
   \   000148   02....       LJMP    ?BANKED_LEAVE_XDATA
   \   00014B                REQUIRE _A_P0
   \   00014B                REQUIRE U0CSR
   \   00014B                REQUIRE U0DBUF
   \   00014B                REQUIRE U0BAUD
   \   00014B                REQUIRE U0UCR
   \   00014B                REQUIRE U0GCR
   \   00014B                REQUIRE DMAIRQ
   \   00014B                REQUIRE DMAARM
   \   00014B                REQUIRE P0SEL
   \   00014B                REQUIRE P0DIR
    708          }

   \                                 In  segment BANKED_CODE, align 1, keep-with-next
   \                     ?Subroutine19:
   \   000000   12....       LCALL   ??osal_mem_alloc?relay
   \   000003   8E82         MOV     DPL,R6
   \   000005   8F83         MOV     DPH,R7
   \   000007   EA           MOV     A,R2
   \   000008   F0           MOVX    @DPTR,A
   \   000009   A3           INC     DPTR
   \   00000A   EB           MOV     A,R3
   \   00000B   F0           MOVX    @DPTR,A
   \   00000C   22           RET

   \                                 In  segment BANKED_CODE, align 1, keep-with-next
   \                     ?Subroutine7:
   \   000000   12....       LCALL   ??Subroutine23_0 & 0xFFFF
   \                     ??CrossCallReturnLabel_79:
   \   000003   E4           CLR     A
   \   000004   F0           MOVX    @DPTR,A
   \   000005   A3           INC     DPTR
   \   000006   F0           MOVX    @DPTR,A
   \   000007   22           RET
    709          
    710          /******************************************************************************
    711           * @fn      HalUARTClose
    712           *
    713           * @brief   Close the UART
    714           *
    715           * @param   port - UART port
    716           *
    717           * @return  none
    718           *****************************************************************************/

   \                                 In  segment BANKED_CODE, align 1, keep-with-next
    719          void HalUARTClose( uint8 port )
   \                     HalUARTClose:
    720          {
   \   000000                ; Saved register size: 0
   \   000000                ; Auto size: 0
    721          #if HAL_UART_CLOSE
    722            uartCfg_t *cfg;
    723          
    724          #if HAL_UART_0_ENABLE
    725            if ( port == HAL_UART_PORT_0 )
    726            {
    727              U0CSR &= ~CSR_RE;
    728          #if HAL_UART_DMA == 1
    729              HAL_DMA_ABORT_CH( HAL_DMA_CH_RX );
    730              HAL_DMA_ABORT_CH( HAL_DMA_CH_TX );
    731          #else
    732              URX0IE = 0;
    733          #endif
    734              cfg = cfg0;
    735              cfg0 = NULL;
    736            }
    737          #endif
    738          #if HAL_UART_1_ENABLE
    739            if ( port == HAL_UART_PORT_1 )
    740            {
    741              U1CSR &= ~CSR_RE;
    742          #if HAL_UART_DMA == 2
    743              HAL_DMA_ABORT_CH( HAL_DMA_CH_RX );
    744              HAL_DMA_ABORT_CH( HAL_DMA_CH_TX );
    745          #else
    746              URX1IE = 0;
    747          #endif
    748              cfg = cfg1;
    749              cfg1 = NULL;
    750            }
    751          #endif
    752          
    753            if ( cfg )
    754            {
    755              if ( cfg->rxBuf )
    756              {
    757                osal_mem_free( cfg->rxBuf );
    758              }
    759              if ( cfg->txBuf )
    760              {
    761                osal_mem_free( cfg->txBuf );
    762              }
    763              osal_mem_free( cfg );
    764            }
    765          #endif
    766          }
   \   000000   02....       LJMP    ?BRET
    767          
    768          /******************************************************************************
    769           * @fn      HalUARTPoll
    770           *
    771           * @brief   Poll the UART.
    772           *
    773           * @param   none
    774           *
    775           * @return  none
    776           *****************************************************************************/

   \                                 In  segment BANKED_CODE, align 1, keep-with-next
    777          void HalUARTPoll( void )
   \                     HalUARTPoll:
    778          {
   \   000000   74F7         MOV     A,#-0x9
   \   000002   12....       LCALL   ?BANKED_ENTER_XDATA
   \   000005                ; Saved register size: 9
   \   000005                ; Auto size: 0
    779          #if ( HAL_UART_0_ENABLE | HAL_UART_1_ENABLE )
    780            static uint8 tickShdw;
    781            uartCfg_t *cfg;
    782            uint8 tick;
    783          
    784          #if HAL_UART_0_ENABLE
    785            if ( cfg0 )
   \   000005   90....       MOV     DPTR,#cfg0
   \   000008   E0           MOVX    A,@DPTR
   \   000009   7002         JNZ     ??HalUARTPoll_0
   \   00000B   A3           INC     DPTR
   \   00000C   E0           MOVX    A,@DPTR
   \                     ??HalUARTPoll_0:
   \   00000D   6008         JZ      ??HalUARTPoll_1
    786            {
    787              cfg = cfg0;
   \   00000F   90....       MOV     DPTR,#cfg0
   \   000012   E0           MOVX    A,@DPTR
   \   000013   FE           MOV     R6,A
   \   000014   A3           INC     DPTR
   \   000015   E0           MOVX    A,@DPTR
   \   000016   FF           MOV     R7,A
    788            }
    789          #endif
    790          #if HAL_UART_1_ENABLE
    791            if ( cfg1 )
    792            {
    793              cfg = cfg1;
    794            }
    795          #endif
    796          
    797            // Use the LSB of the sleep timer (ST0 must be read first anyway).
    798            tick = ST0 - tickShdw;
   \                     ??HalUARTPoll_1:
   \   000017   90....       MOV     DPTR,#??tickShdw
   \   00001A   E0           MOVX    A,@DPTR
   \   00001B   FA           MOV     R2,A
   \   00001C   E595         MOV     A,0x95
   \   00001E   C3           CLR     C
   \   00001F   9A           SUBB    A,R2
   \   000020   FA           MOV     R2,A
    799            tickShdw = ST0;
   \   000021   E595         MOV     A,0x95
   \   000023   F0           MOVX    @DPTR,A
    800          
    801            do
    802            {
    803              if ( cfg->txTick > tick )
   \   000024   EE           MOV     A,R6
   \   000025   2412         ADD     A,#0x12
   \   000027   12....       LCALL   ??Subroutine5_0 & 0xFFFF
   \                     ??CrossCallReturnLabel_24:
   \   00002A   FB           MOV     R3,A
   \   00002B   EA           MOV     A,R2
   \   00002C   C3           CLR     C
   \   00002D   9B           SUBB    A,R3
   \   00002E   5005         JNC     ??HalUARTPoll_2
    804              {
    805                cfg->txTick -= tick;
   \   000030   E0           MOVX    A,@DPTR
   \   000031   C3           CLR     C
   \   000032   9A           SUBB    A,R2
   \   000033   8001         SJMP    ??HalUARTPoll_3
    806              }
    807              else
    808              {
    809                cfg->txTick = 0;
   \                     ??HalUARTPoll_2:
   \   000035   E4           CLR     A
   \                     ??HalUARTPoll_3:
   \   000036   12....       LCALL   ?Subroutine21 & 0xFFFF
    810              }
    811          
    812              if ( cfg->rxTick > tick )
   \                     ??CrossCallReturnLabel_73:
   \   000039   A3           INC     DPTR
   \   00003A   A3           INC     DPTR
   \   00003B   A3           INC     DPTR
   \   00003C   A3           INC     DPTR
   \   00003D   A3           INC     DPTR
   \   00003E   E0           MOVX    A,@DPTR
   \   00003F   FB           MOV     R3,A
   \   000040   EA           MOV     A,R2
   \   000041   C3           CLR     C
   \   000042   9B           SUBB    A,R3
   \   000043   500F         JNC     ??HalUARTPoll_4
    813              {
    814                cfg->rxTick -= tick;
   \   000045   8E82         MOV     DPL,R6
   \   000047   8F83         MOV     DPH,R7
   \   000049   A3           INC     DPTR
   \   00004A   A3           INC     DPTR
   \   00004B   A3           INC     DPTR
   \   00004C   A3           INC     DPTR
   \   00004D   A3           INC     DPTR
   \   00004E   A3           INC     DPTR
   \   00004F   E0           MOVX    A,@DPTR
   \   000050   C3           CLR     C
   \   000051   9A           SUBB    A,R2
   \   000052   800B         SJMP    ??HalUARTPoll_5
    815              }
    816              else
    817              {
    818                cfg->rxTick = 0;
   \                     ??HalUARTPoll_4:
   \   000054   E4           CLR     A
   \   000055   8E82         MOV     DPL,R6
   \   000057   8F83         MOV     DPH,R7
   \   000059   A3           INC     DPTR
   \   00005A   A3           INC     DPTR
   \   00005B   A3           INC     DPTR
   \   00005C   A3           INC     DPTR
   \   00005D   A3           INC     DPTR
   \   00005E   A3           INC     DPTR
   \                     ??HalUARTPoll_5:
   \   00005F   F0           MOVX    @DPTR,A
    819              }
    820          
    821          #if HAL_UART_ISR
    822          #if HAL_UART_DMA
    823              if ( cfg->flag & UART_CFG_DMA )
    824              {
    825                pollDMA( cfg );
    826              }
    827              else
    828          #endif
    829                {
    830                pollISR( cfg );
    831                }
    832          #elif HAL_UART_DMA
    833              pollDMA( cfg );
   \   000060                ; Setup parameters for call to function pollDMA
   \   000060   EE           MOV     A,R6
   \   000061   FA           MOV     R2,A
   \   000062   EF           MOV     A,R7
   \   000063   FB           MOV     R3,A
   \   000064   12....       LCALL   ??pollDMA?relay
    834          #endif
    835          
    836              /* The following logic makes continuous callbacks on any eligible flag
    837               * until the condition corresponding to the flag is rectified.
    838               * So even if new data is not received, continuous callbacks are made.
    839               */
    840                if ( cfg->rxHead != cfg->rxTail )
   \   000067   12....       LCALL   ?Subroutine12 & 0xFFFF
   \                     ??CrossCallReturnLabel_52:
   \   00006A   6069         JZ      ??HalUARTPoll_6
    841                {
    842                uint8 evt;
    843          
    844                if ( cfg->rxHead >= (cfg->rxMax - SAFE_RX_MIN) )
   \   00006C   12....       LCALL   ?Subroutine3 & 0xFFFF
   \                     ??CrossCallReturnLabel_12:
   \   00006F   4004         JC      ??HalUARTPoll_7
    845                {
    846                  evt = HAL_UART_RX_FULL;
   \   000071   7A01         MOV     R2,#0x1
   \   000073   803D         SJMP    ??HalUARTPoll_8
    847                }
    848                else if ( cfg->rxHigh && (cfg->rxHead >= cfg->rxHigh) )
   \                     ??HalUARTPoll_7:
   \   000075   8E82         MOV     DPL,R6
   \   000077   8F83         MOV     DPH,R7
   \   000079   A3           INC     DPTR
   \   00007A   A3           INC     DPTR
   \   00007B   A3           INC     DPTR
   \   00007C   A3           INC     DPTR
   \   00007D   A3           INC     DPTR
   \   00007E   A3           INC     DPTR
   \   00007F   A3           INC     DPTR
   \   000080   E0           MOVX    A,@DPTR
   \   000081   6020         JZ      ??HalUARTPoll_9
   \   000083   8E82         MOV     DPL,R6
   \   000085   8F83         MOV     DPH,R7
   \   000087   A3           INC     DPTR
   \   000088   A3           INC     DPTR
   \   000089   E0           MOVX    A,@DPTR
   \   00008A   C0E0         PUSH    A
   \   00008C   8E82         MOV     DPL,R6
   \   00008E   8F83         MOV     DPH,R7
   \   000090   A3           INC     DPTR
   \   000091   A3           INC     DPTR
   \   000092   A3           INC     DPTR
   \   000093   A3           INC     DPTR
   \   000094   A3           INC     DPTR
   \   000095   A3           INC     DPTR
   \   000096   A3           INC     DPTR
   \   000097   E0           MOVX    A,@DPTR
   \   000098   FA           MOV     R2,A
   \   000099   D0E0         POP     A
   \   00009B   C3           CLR     C
   \   00009C   9A           SUBB    A,R2
   \   00009D   4004         JC      ??HalUARTPoll_9
    849                {
    850                  evt = HAL_UART_RX_ABOUT_FULL;
   \   00009F   7A02         MOV     R2,#0x2
   \   0000A1   800F         SJMP    ??HalUARTPoll_8
    851              }
    852                else if ( cfg->rxTick == 0 )
   \                     ??HalUARTPoll_9:
   \   0000A3   8E82         MOV     DPL,R6
   \   0000A5   8F83         MOV     DPH,R7
   \   0000A7   A3           INC     DPTR
   \   0000A8   A3           INC     DPTR
   \   0000A9   A3           INC     DPTR
   \   0000AA   A3           INC     DPTR
   \   0000AB   A3           INC     DPTR
   \   0000AC   A3           INC     DPTR
   \   0000AD   E0           MOVX    A,@DPTR
   \   0000AE   7025         JNZ     ??HalUARTPoll_6
    853              {
    854                  evt = HAL_UART_RX_TIMEOUT;
   \   0000B0   7A04         MOV     R2,#0x4
   \                     ??HalUARTPoll_8:
   \   0000B2   EE           MOV     A,R6
   \   0000B3   2414         ADD     A,#0x14
   \   0000B5   12....       LCALL   ??Subroutine5_0 & 0xFFFF
   \                     ??CrossCallReturnLabel_25:
   \   0000B8   7002         JNZ     ??HalUARTPoll_10
   \   0000BA   A3           INC     DPTR
   \   0000BB   E0           MOVX    A,@DPTR
   \                     ??HalUARTPoll_10:
   \   0000BC   6017         JZ      ??HalUARTPoll_6
    855              }
    856              else
    857              {
    858                  evt = 0;
    859              }
    860          
    861              if ( evt && cfg->rxCB )
    862              {
    863                  cfg->rxCB( ((cfg->flag & UART_CFG_U1F)!=0), evt );
   \   0000BE                ; Setup parameters for indirect call
   \   0000BE   12....       LCALL   ?Subroutine4 & 0xFFFF
   \                     ??CrossCallReturnLabel_15:
   \   0000C1   E4           CLR     A
   \   0000C2   92E0         MOV     0xE0 /* A   */.0,C
   \   0000C4   F9           MOV     R1,A
   \   0000C5   EE           MOV     A,R6
   \   0000C6   2414         ADD     A,#0x14
   \   0000C8   12....       LCALL   ??Subroutine5_0 & 0xFFFF
   \                     ??CrossCallReturnLabel_26:
   \   0000CB   F8           MOV     R0,A
   \   0000CC   A3           INC     DPTR
   \   0000CD   E0           MOVX    A,@DPTR
   \   0000CE   F583         MOV     DPH,A
   \   0000D0   8882         MOV     DPL,R0
   \   0000D2   12....       LCALL   ?CALL_IND
    864              }
    865              }
    866          
    867          #if HAL_UART_0_ENABLE
    868              if ( cfg == cfg0 )
    869              {
    870          #if HAL_UART_1_ENABLE
    871                if ( cfg1 )
    872                {
    873                  cfg = cfg1;
    874                }
    875                else
    876          #endif
    877                  break;
    878              }
    879              else
    880          #endif
    881                break;
    882          
    883            } while ( TRUE );
    884          #else
    885            return;
    886          #endif
    887          }
   \                     ??HalUARTPoll_6:
   \   0000D5   7F01         MOV     R7,#0x1
   \   0000D7   02....       LJMP    ?BANKED_LEAVE_XDATA
   \   0000DA                REQUIRE ST0

   \                                 In  segment XDATA_Z, align 1, keep-with-next
   \                     ??tickShdw:
   \   000000                DS 1
   \   000001                REQUIRE __INIT_XDATA_Z
    888          
    889          /**************************************************************************************************
    890           * @fn      Hal_UART_RxBufLen()
    891           *
    892           * @brief   Calculate Rx Buffer length - the number of bytes in the buffer.
    893           *
    894           * @param   port - UART port
    895           *
    896           * @return  length of current Rx Buffer
    897           **************************************************************************************************/

   \                                 In  segment BANKED_CODE, align 1, keep-with-next
    898          uint16 Hal_UART_RxBufLen( uint8 port )
   \                     Hal_UART_RxBufLen:
    899          {
   \   000000   C082         PUSH    DPL
   \   000002   C083         PUSH    DPH
   \   000004                ; Saved register size: 2
   \   000004                ; Auto size: 0
   \   000004   E9           MOV     A,R1
    900            uartCfg_t *cfg = NULL;
   \   000005   7800         MOV     R0,#0x0
   \   000007   7900         MOV     R1,#0x0
    901          
    902          #if HAL_UART_0_ENABLE
    903            if ( port == HAL_UART_PORT_0 )
   \   000009   7003         JNZ     ??CrossCallReturnLabel_83
    904            {
    905              cfg = cfg0;
   \   00000B   12....       LCALL   ?Subroutine14 & 0xFFFF
    906            }
    907          #endif
    908          #if HAL_UART_1_ENABLE
    909            if ( port == HAL_UART_PORT_1 )
    910            {
    911              cfg = cfg1;
    912            }
    913          #endif
    914          
    915            HAL_UART_ASSERT( cfg );
    916          
    917            return UART_RX_AVAIL( cfg );
   \                     ??CrossCallReturnLabel_83:
   \   00000E   8882         MOV     DPL,R0
   \   000010   8983         MOV     DPH,R1
   \   000012   A3           INC     DPTR
   \   000013   A3           INC     DPTR
   \   000014   E0           MOVX    A,@DPTR
   \   000015   C0E0         PUSH    A
   \   000017   8882         MOV     DPL,R0
   \   000019   8983         MOV     DPH,R1
   \   00001B   A3           INC     DPTR
   \   00001C   A3           INC     DPTR
   \   00001D   A3           INC     DPTR
   \   00001E   E0           MOVX    A,@DPTR
   \   00001F   FA           MOV     R2,A
   \   000020   D0E0         POP     A
   \   000022   C3           CLR     C
   \   000023   9A           SUBB    A,R2
   \   000024   8882         MOV     DPL,R0
   \   000026   8983         MOV     DPH,R1
   \   000028   A3           INC     DPTR
   \   000029   A3           INC     DPTR
   \   00002A   400D         JC      ??Hal_UART_RxBufLen_0
   \   00002C   12....       LCALL   ?Subroutine13 & 0xFFFF
   \                     ??CrossCallReturnLabel_53:
   \   00002F   F8           MOV     R0,A
   \   000030   EA           MOV     A,R2
   \   000031   C3           CLR     C
   \   000032   98           SUBB    A,R0
   \   000033   FA           MOV     R2,A
   \   000034   E4           CLR     A
   \   000035   9400         SUBB    A,#0x0
   \   000037   8020         SJMP    ??Hal_UART_RxBufLen_1
   \                     ??Hal_UART_RxBufLen_0:
   \   000039   A3           INC     DPTR
   \   00003A   A3           INC     DPTR
   \   00003B   12....       LCALL   ?Subroutine13 & 0xFFFF
   \                     ??CrossCallReturnLabel_54:
   \   00003E   FC           MOV     R4,A
   \   00003F   EA           MOV     A,R2
   \   000040   C3           CLR     C
   \   000041   9C           SUBB    A,R4
   \   000042   FA           MOV     R2,A
   \   000043   E4           CLR     A
   \   000044   9400         SUBB    A,#0x0
   \   000046   FB           MOV     R3,A
   \   000047   8882         MOV     DPL,R0
   \   000049   8983         MOV     DPH,R1
   \   00004B   A3           INC     DPTR
   \   00004C   A3           INC     DPTR
   \   00004D   E0           MOVX    A,@DPTR
   \   00004E   2A           ADD     A,R2
   \   00004F   F8           MOV     R0,A
   \   000050   E4           CLR     A
   \   000051   3B           ADDC    A,R3
   \   000052   F9           MOV     R1,A
   \   000053   7401         MOV     A,#0x1
   \   000055   28           ADD     A,R0
   \   000056   FA           MOV     R2,A
   \   000057   E4           CLR     A
   \   000058   39           ADDC    A,R1
   \                     ??Hal_UART_RxBufLen_1:
   \   000059   FB           MOV     R3,A
   \   00005A   02....       LJMP    ?Subroutine25 & 0xFFFF
    918          }

   \                                 In  segment BANKED_CODE, align 1, keep-with-next
   \                     ?Subroutine13:
   \   000000   E0           MOVX    A,@DPTR
   \   000001   FA           MOV     R2,A
   \   000002   8882         MOV     DPL,R0
   \   000004   8983         MOV     DPH,R1
   \   000006   A3           INC     DPTR
   \   000007   A3           INC     DPTR
   \   000008   A3           INC     DPTR
   \   000009   E0           MOVX    A,@DPTR
   \   00000A   22           RET

   \                                 In  segment BANKED_CODE, align 1, keep-with-next
   \                     ?Subroutine14:
   \   000000   90....       MOV     DPTR,#cfg0
   \   000003   02....       LJMP    ?Subroutine24 & 0xFFFF
    919          
    920          /*****************************************************************************
    921           * @fn      HalUARTRead
    922           *
    923           * @brief   Read a buffer from the UART
    924           *
    925           * @param   port - USART module designation
    926           *          buf  - valid data buffer at least 'len' bytes in size
    927           *          len  - max length number of bytes to copy to 'buf'
    928           *
    929           * @return  length of buffer that was read
    930           *****************************************************************************/

   \                                 In  segment BANKED_CODE, align 1, keep-with-next
    931          uint16 HalUARTRead( uint8 port, uint8 *buf, uint16 len )
   \                     HalUARTRead:
    932          {
   \   000000   74F4         MOV     A,#-0xc
   \   000002   12....       LCALL   ?BANKED_ENTER_XDATA
   \   000005                ; Saved register size: 12
   \   000005                ; Auto size: 0
   \   000005   E9           MOV     A,R1
    933            uartCfg_t *cfg = NULL;
   \   000006   7800         MOV     R0,#0x0
   \   000008   7900         MOV     R1,#0x0
    934            uint8 cnt = 0;
   \   00000A   88..         MOV     ?V0 + 2,R0
    935          
    936          #if HAL_UART_0_ENABLE
    937            if ( port == HAL_UART_PORT_0 )
   \   00000C   7011         JNZ     ??HalUARTRead_0
    938            {
    939              cfg = cfg0;
   \   00000E   12....       LCALL   ?Subroutine14 & 0xFFFF
   \                     ??CrossCallReturnLabel_84:
   \   000011   800C         SJMP    ??HalUARTRead_0
    940            }
    941          #endif
    942          #if HAL_UART_1_ENABLE
    943            if ( port == HAL_UART_PORT_1 )
    944            {
    945              cfg = cfg1;
    946            }
    947          #endif
    948          
    949            HAL_UART_ASSERT( cfg );
    950          
    951            while ( (cfg->rxTail != cfg->rxHead) && (cnt < len) )
    952            {
    953              *buf++ = cfg->rxBuf[cfg->rxTail];
    954              if ( cfg->rxTail == cfg->rxMax )
    955              {
    956                cfg->rxTail = 0;
    957              }
    958              else
    959              {
    960                cfg->rxTail++;
   \                     ??HalUARTRead_1:
   \   000013   8882         MOV     DPL,R0
   \   000015   8983         MOV     DPH,R1
   \   000017   A3           INC     DPTR
   \   000018   A3           INC     DPTR
   \   000019   A3           INC     DPTR
   \   00001A   E0           MOVX    A,@DPTR
   \   00001B   04           INC     A
   \                     ??HalUARTRead_2:
   \   00001C   F0           MOVX    @DPTR,A
    961              }
    962              cnt++;
   \   00001D   05..         INC     ?V0 + 2
   \                     ??HalUARTRead_0:
   \   00001F   8882         MOV     DPL,R0
   \   000021   8983         MOV     DPH,R1
   \   000023   A3           INC     DPTR
   \   000024   A3           INC     DPTR
   \   000025   A3           INC     DPTR
   \   000026   12....       LCALL   ?Subroutine17 & 0xFFFF
   \                     ??CrossCallReturnLabel_61:
   \   000029   E0           MOVX    A,@DPTR
   \   00002A   6E           XRL     A,R6
   \   00002B   604E         JZ      ??HalUARTRead_3
   \   00002D   85....       MOV     ?V0 + 0,?V0 + 2
   \   000030   C3           CLR     C
   \   000031   E5..         MOV     A,?V0 + 0
   \   000033   9C           SUBB    A,R4
   \   000034   E4           CLR     A
   \   000035   9D           SUBB    A,R5
   \   000036   5043         JNC     ??HalUARTRead_3
   \   000038   E8           MOV     A,R0
   \   000039   2403         ADD     A,#0x3
   \   00003B   FE           MOV     R6,A
   \   00003C   E9           MOV     A,R1
   \   00003D   3400         ADDC    A,#0x0
   \   00003F   FF           MOV     R7,A
   \   000040   8E82         MOV     DPL,R6
   \   000042   8F83         MOV     DPH,R7
   \   000044   E0           MOVX    A,@DPTR
   \   000045   F5..         MOV     ?V0 + 0,A
   \   000047   8882         MOV     DPL,R0
   \   000049   8983         MOV     DPH,R1
   \   00004B   E0           MOVX    A,@DPTR
   \   00004C   25..         ADD     A,?V0 + 0
   \   00004E   F5..         MOV     ?V0 + 3,A
   \   000050   A3           INC     DPTR
   \   000051   E0           MOVX    A,@DPTR
   \   000052   3400         ADDC    A,#0x0
   \   000054   85..82       MOV     DPL,?V0 + 3
   \   000057   F583         MOV     DPH,A
   \   000059   E0           MOVX    A,@DPTR
   \   00005A   8A82         MOV     DPL,R2
   \   00005C   8B83         MOV     DPH,R3
   \   00005E   F0           MOVX    @DPTR,A
   \   00005F   A3           INC     DPTR
   \   000060   AA82         MOV     R2,DPL
   \   000062   AB83         MOV     R3,DPH
   \   000064   8E82         MOV     DPL,R6
   \   000066   8F83         MOV     DPH,R7
   \   000068   12....       LCALL   ?Subroutine17 & 0xFFFF
   \                     ??CrossCallReturnLabel_62:
   \   00006B   A3           INC     DPTR
   \   00006C   A3           INC     DPTR
   \   00006D   E0           MOVX    A,@DPTR
   \   00006E   6E           XRL     A,R6
   \   00006F   70A2         JNZ     ??HalUARTRead_1
   \   000071   E4           CLR     A
   \   000072   8882         MOV     DPL,R0
   \   000074   8983         MOV     DPH,R1
   \   000076   A3           INC     DPTR
   \   000077   A3           INC     DPTR
   \   000078   A3           INC     DPTR
   \   000079   80A1         SJMP    ??HalUARTRead_2
    963            }
    964          
    965          #if HAL_UART_DMA
    966            #if HAL_UART_ISR
    967            if ( cfg->flag & UART_CFG_DMA )
    968            #endif
    969            {
    970              /* If there is no flow control on a DMA-driven UART, the Rx Head & Tail
    971               * pointers must be reset to zero after every read in order to preserve the
    972               * full length of the Rx buffer. This implies that every Read must read all
    973               * of the Rx bytes available, or the pointers will not be reset and the
    974               * next incoming packet may not fit in the Rx buffer space remaining - thus
    975               * the end portion of the incoming packet that does not fit would be lost.
    976               */
    977              if ( !(cfg->flag & UART_CFG_FLW) )
   \                     ??HalUARTRead_3:
   \   00007B   E8           MOV     A,R0
   \   00007C   2413         ADD     A,#0x13
   \   00007E   F582         MOV     DPL,A
   \   000080   E9           MOV     A,R1
   \   000081   12....       LCALL   ??Subroutine5_1 & 0xFFFF
   \                     ??CrossCallReturnLabel_27:
   \   000084   A2E5         MOV     C,0xE0 /* A   */.5
   \   000086   4003         JC      ??HalUARTRead_4
    978              {
    979                // This is a trick to trigger the DMA abort and restart logic in pollDMA.
    980                cfg->flag |= UART_CFG_RXF;
   \   000088   D2E1         SETB    0xE0 /* A   */.1
   \   00008A   F0           MOVX    @DPTR,A
    981              }
    982            }
    983          #endif
    984          
    985          #if HAL_UART_ISR
    986            #if HAL_UART_DMA
    987            if ( !(cfg->flag & UART_CFG_DMA) )
    988            #endif
    989            {
    990              cfg->rxCnt = UART_RX_AVAIL( cfg );
    991          
    992              if ( cfg->flag & UART_CFG_RXF )
    993              {
    994                if ( cfg->rxCnt < (cfg->rxMax - SAFE_RX_MIN) )
    995                {
    996                  RX_STRT_FLOW( cfg );
    997                }
    998              }
    999            }
   1000          #endif
   1001          
   1002            return cnt;
   \                     ??HalUARTRead_4:
   \   00008B   AA..         MOV     R2,?V0 + 2
   \   00008D   7B00         MOV     R3,#0x0
   \   00008F                REQUIRE ?Subroutine26
   \   00008F                ; // Fall through to label ?Subroutine26
   1003          }

   \                                 In  segment BANKED_CODE, align 1, keep-with-next
   \                     ?Subroutine26:
   \   000000   7F04         MOV     R7,#0x4
   \   000002   02....       LJMP    ?BANKED_LEAVE_XDATA

   \                                 In  segment BANKED_CODE, align 1, keep-with-next
   \                     ?Subroutine17:
   \   000000   E0           MOVX    A,@DPTR
   \   000001   FE           MOV     R6,A
   \   000002   8882         MOV     DPL,R0
   \   000004   8983         MOV     DPH,R1
   \   000006   A3           INC     DPTR
   \   000007   A3           INC     DPTR
   \   000008   22           RET
   1004          
   1005          /******************************************************************************
   1006           * @fn      HalUARTWrite
   1007           *
   1008           * @brief   Write a buffer to the UART.
   1009           *
   1010           * @param   port    - UART port
   1011           *          pBuffer - pointer to the buffer that will be written, not freed
   1012           *          length  - length of
   1013           *
   1014           * @return  length of the buffer that was sent
   1015           *****************************************************************************/

   \                                 In  segment BANKED_CODE, align 1, keep-with-next
   1016          uint16 HalUARTWrite( uint8 port, uint8 *buf, uint16 len )
   \                     HalUARTWrite:
   1017          {
   \   000000   74F4         MOV     A,#-0xc
   \   000002   12....       LCALL   ?BANKED_ENTER_XDATA
   \   000005                ; Saved register size: 12
   \   000005                ; Auto size: 0
   \   000005   89..         MOV     ?V0 + 0,R1
   \   000007   EA           MOV     A,R2
   \   000008   FE           MOV     R6,A
   \   000009   EB           MOV     A,R3
   \   00000A   FF           MOV     R7,A
   \   00000B   EC           MOV     A,R4
   \   00000C   FA           MOV     R2,A
   \   00000D   ED           MOV     A,R5
   \   00000E   FB           MOV     R3,A
   1018            uartCfg_t *cfg = NULL;
   \   00000F   7800         MOV     R0,#0x0
   \   000011   7900         MOV     R1,#0x0
   1019            uint8 cnt;
   1020          
   1021          #if HAL_UART_0_ENABLE
   1022            if ( port == HAL_UART_PORT_0 )
   \   000013   E5..         MOV     A,?V0 + 0
   \   000015   7003         JNZ     ??CrossCallReturnLabel_85
   1023            {
   1024              cfg = cfg0;
   \   000017   12....       LCALL   ?Subroutine14 & 0xFFFF
   1025            }
   1026          #endif
   1027          #if HAL_UART_1_ENABLE
   1028            if ( port == HAL_UART_PORT_1 )
   1029            {
   1030              cfg = cfg1;
   1031            }
   1032          #endif
   1033          
   1034            HAL_UART_ASSERT( cfg );
   1035          
   1036            if ( cfg->txHead == cfg->txTail )
   \                     ??CrossCallReturnLabel_85:
   \   00001A   12....       LCALL   ?Subroutine15 & 0xFFFF
   \                     ??CrossCallReturnLabel_55:
   \   00001D   12....       LCALL   ?Subroutine20 & 0xFFFF
   \                     ??CrossCallReturnLabel_67:
   \   000020   12....       LCALL   ??Subroutine5_1 & 0xFFFF
   \                     ??CrossCallReturnLabel_28:
   \   000023   6C           XRL     A,R4
   \   000024   7003         JNZ     ??HalUARTWrite_0
   \   000026   A3           INC     DPTR
   \   000027   E0           MOVX    A,@DPTR
   \   000028   6D           XRL     A,R5
   \                     ??HalUARTWrite_0:
   \   000029   7029         JNZ     ??HalUARTWrite_1
   1037            {
   1038          #if HAL_UART_DMA
   1039              // When pointers are equal, reset to zero to get max len w/out wrapping.
   1040              cfg->txHead = cfg->txTail = 0;
   \   00002B   12....       LCALL   ?Subroutine20 & 0xFFFF
   \                     ??CrossCallReturnLabel_68:
   \   00002E   12....       LCALL   ?Subroutine7 & 0xFFFF
   \                     ??CrossCallReturnLabel_36:
   \   000031   8882         MOV     DPL,R0
   \   000033   8983         MOV     DPH,R1
   \   000035   A3           INC     DPTR
   \   000036   A3           INC     DPTR
   \   000037   A3           INC     DPTR
   \   000038   A3           INC     DPTR
   \   000039   A3           INC     DPTR
   \   00003A   A3           INC     DPTR
   \   00003B   A3           INC     DPTR
   \   00003C   A3           INC     DPTR
   \   00003D   A3           INC     DPTR
   \   00003E   A3           INC     DPTR
   \   00003F   F0           MOVX    @DPTR,A
   \   000040   A3           INC     DPTR
   \   000041   F0           MOVX    @DPTR,A
   \   000042   E8           MOV     A,R0
   \   000043   240E         ADD     A,#0xe
   \   000045   F582         MOV     DPL,A
   \   000047   E9           MOV     A,R1
   \   000048   12....       LCALL   ??Subroutine5_1 & 0xFFFF
   \                     ??CrossCallReturnLabel_29:
   \   00004B   24FF         ADD     A,#-0x1
   \   00004D   FC           MOV     R4,A
   \   00004E   A3           INC     DPTR
   \   00004F   E0           MOVX    A,@DPTR
   \   000050   34FF         ADDC    A,#-0x1
   \   000052   8066         SJMP    ??HalUARTWrite_2
   1041          #endif
   1042          #if HAL_UART_ISR
   1043          #if HAL_UART_DMA
   1044              if ( !(cfg->flag & UART_CFG_DMA) )
   1045          #endif
   1046              {
   1047                cfg->flag &= ~UART_CFG_TXF;
   1048              }
   1049          #endif
   1050            }
   1051          
   1052            // Accept "all-or-none" on write request.
   1053            if ( TX_AVAIL( cfg ) < len )
   \                     ??HalUARTWrite_1:
   \   000054   8882         MOV     DPL,R0
   \   000056   8983         MOV     DPH,R1
   \   000058   A3           INC     DPTR
   \   000059   A3           INC     DPTR
   \   00005A   A3           INC     DPTR
   \   00005B   A3           INC     DPTR
   \   00005C   A3           INC     DPTR
   \   00005D   A3           INC     DPTR
   \   00005E   A3           INC     DPTR
   \   00005F   A3           INC     DPTR
   \   000060   A3           INC     DPTR
   \   000061   A3           INC     DPTR
   \   000062   C082         PUSH    DPL
   \   000064   C083         PUSH    DPH
   \   000066   12....       LCALL   ?Subroutine20 & 0xFFFF
   \                     ??CrossCallReturnLabel_69:
   \   000069   12....       LCALL   ??Subroutine5_1 & 0xFFFF
   \                     ??CrossCallReturnLabel_30:
   \   00006C   FC           MOV     R4,A
   \   00006D   A3           INC     DPTR
   \   00006E   E0           MOVX    A,@DPTR
   \   00006F   FD           MOV     R5,A
   \   000070   D083         POP     DPH
   \   000072   D082         POP     DPL
   \   000074   C3           CLR     C
   \   000075   E0           MOVX    A,@DPTR
   \   000076   9C           SUBB    A,R4
   \   000077   A3           INC     DPTR
   \   000078   E0           MOVX    A,@DPTR
   \   000079   9D           SUBB    A,R5
   \   00007A   E8           MOV     A,R0
   \   00007B   501C         JNC     ??HalUARTWrite_3
   \   00007D   12....       LCALL   ??Subroutine20_0 & 0xFFFF
   \                     ??CrossCallReturnLabel_70:
   \   000080   12....       LCALL   ??Subroutine8_1 & 0xFFFF
   \                     ??CrossCallReturnLabel_43:
   \   000083   C082         PUSH    DPL
   \   000085   C083         PUSH    DPH
   \   000087   12....       LCALL   ?Subroutine15 & 0xFFFF
   \                     ??CrossCallReturnLabel_56:
   \   00008A   D083         POP     DPH
   \   00008C   D082         POP     DPL
   \   00008E   12....       LCALL   ?Subroutine16 & 0xFFFF
   \                     ??CrossCallReturnLabel_59:
   \   000091   74FF         MOV     A,#-0x1
   \   000093   2C           ADD     A,R4
   \   000094   1C           DEC     R4
   \   000095   74FF         MOV     A,#-0x1
   \   000097   8020         SJMP    ??HalUARTWrite_4
   \                     ??HalUARTWrite_3:
   \   000099   240E         ADD     A,#0xe
   \   00009B   F582         MOV     DPL,A
   \   00009D   E9           MOV     A,R1
   \   00009E   12....       LCALL   ??Subroutine8_1 & 0xFFFF
   \                     ??CrossCallReturnLabel_44:
   \   0000A1   C082         PUSH    DPL
   \   0000A3   C083         PUSH    DPH
   \   0000A5   12....       LCALL   ?Subroutine15 & 0xFFFF
   \                     ??CrossCallReturnLabel_57:
   \   0000A8   D083         POP     DPH
   \   0000AA   D082         POP     DPL
   \   0000AC   12....       LCALL   ?Subroutine16 & 0xFFFF
   \                     ??CrossCallReturnLabel_60:
   \   0000AF   12....       LCALL   ?Subroutine20 & 0xFFFF
   \                     ??CrossCallReturnLabel_71:
   \   0000B2   12....       LCALL   ??Subroutine5_1 & 0xFFFF
   \                     ??CrossCallReturnLabel_31:
   \   0000B5   2C           ADD     A,R4
   \   0000B6   FC           MOV     R4,A
   \   0000B7   A3           INC     DPTR
   \   0000B8   E0           MOVX    A,@DPTR
   \                     ??HalUARTWrite_4:
   \   0000B9   3D           ADDC    A,R5
   \                     ??HalUARTWrite_2:
   \   0000BA   FD           MOV     R5,A
   \   0000BB   C3           CLR     C
   \   0000BC   EC           MOV     A,R4
   \   0000BD   9A           SUBB    A,R2
   \   0000BE   ED           MOV     A,R5
   \   0000BF   9B           SUBB    A,R3
   \   0000C0   5006         JNC     ??HalUARTWrite_5
   1054            {
   1055              return 0;
   \   0000C2   7A00         MOV     R2,#0x0
   \   0000C4   7B00         MOV     R3,#0x0
   \   0000C6   807C         SJMP    ??HalUARTWrite_6
   1056            }
   1057          
   1058            for ( cnt = len; cnt; cnt-- )
   \                     ??HalUARTWrite_5:
   \   0000C8   EA           MOV     A,R2
   \   0000C9   F5..         MOV     ?V0 + 3,A
   \   0000CB   800B         SJMP    ??HalUARTWrite_7
   1059            {
   1060              cfg->txBuf[ cfg->txHead ] = *buf++;
   1061          
   1062              if ( cfg->txHead == cfg->txMax )
   1063              {
   1064                cfg->txHead = 0;
   1065              }
   1066              else
   1067              {
   1068                cfg->txHead++;
   \                     ??HalUARTWrite_8:
   \   0000CD   E0           MOVX    A,@DPTR
   \   0000CE   2401         ADD     A,#0x1
   \   0000D0   F0           MOVX    @DPTR,A
   \   0000D1   A3           INC     DPTR
   \   0000D2   E0           MOVX    A,@DPTR
   \   0000D3   3400         ADDC    A,#0x0
   \                     ??HalUARTWrite_9:
   \   0000D5   F0           MOVX    @DPTR,A
   1069              }
   \   0000D6   15..         DEC     ?V0 + 3
   \                     ??HalUARTWrite_7:
   \   0000D8   E5..         MOV     A,?V0 + 3
   \   0000DA   6068         JZ      ??HalUARTWrite_6
   \   0000DC   E8           MOV     A,R0
   \   0000DD   240A         ADD     A,#0xa
   \   0000DF   FC           MOV     R4,A
   \   0000E0   E9           MOV     A,R1
   \   0000E1   3400         ADDC    A,#0x0
   \   0000E3   FD           MOV     R5,A
   \   0000E4   8E82         MOV     DPL,R6
   \   0000E6   8F83         MOV     DPH,R7
   \   0000E8   E0           MOVX    A,@DPTR
   \   0000E9   C0E0         PUSH    A
   \   0000EB   8C82         MOV     DPL,R4
   \   0000ED   8D83         MOV     DPH,R5
   \   0000EF   E0           MOVX    A,@DPTR
   \   0000F0   F5..         MOV     ?V0 + 0,A
   \   0000F2   A3           INC     DPTR
   \   0000F3   E0           MOVX    A,@DPTR
   \   0000F4   F5..         MOV     ?V0 + 1,A
   \   0000F6   8882         MOV     DPL,R0
   \   0000F8   8983         MOV     DPH,R1
   \   0000FA   A3           INC     DPTR
   \   0000FB   A3           INC     DPTR
   \   0000FC   A3           INC     DPTR
   \   0000FD   A3           INC     DPTR
   \   0000FE   A3           INC     DPTR
   \   0000FF   A3           INC     DPTR
   \   000100   A3           INC     DPTR
   \   000101   A3           INC     DPTR
   \   000102   E0           MOVX    A,@DPTR
   \   000103   25..         ADD     A,?V0 + 0
   \   000105   F5..         MOV     ?V0 + 2,A
   \   000107   A3           INC     DPTR
   \   000108   E0           MOVX    A,@DPTR
   \   000109   35..         ADDC    A,?V0 + 1
   \   00010B   85..82       MOV     DPL,?V0 + 2
   \   00010E   F583         MOV     DPH,A
   \   000110   D0E0         POP     A
   \   000112   12....       LCALL   ?Subroutine21 & 0xFFFF
   \                     ??CrossCallReturnLabel_74:
   \   000115   AE82         MOV     R6,DPL
   \   000117   AF83         MOV     R7,DPH
   \   000119   8C82         MOV     DPL,R4
   \   00011B   8D83         MOV     DPH,R5
   \   00011D   12....       LCALL   ??Subroutine15_0 & 0xFFFF
   \                     ??CrossCallReturnLabel_58:
   \   000120   E8           MOV     A,R0
   \   000121   240E         ADD     A,#0xe
   \   000123   F582         MOV     DPL,A
   \   000125   E9           MOV     A,R1
   \   000126   12....       LCALL   ??Subroutine5_1 & 0xFFFF
   \                     ??CrossCallReturnLabel_32:
   \   000129   6C           XRL     A,R4
   \   00012A   7003         JNZ     ??HalUARTWrite_10
   \   00012C   A3           INC     DPTR
   \   00012D   E0           MOVX    A,@DPTR
   \   00012E   6D           XRL     A,R5
   \                     ??HalUARTWrite_10:
   \   00012F   8882         MOV     DPL,R0
   \   000131   8983         MOV     DPH,R1
   \   000133   A3           INC     DPTR
   \   000134   A3           INC     DPTR
   \   000135   A3           INC     DPTR
   \   000136   A3           INC     DPTR
   \   000137   A3           INC     DPTR
   \   000138   A3           INC     DPTR
   \   000139   A3           INC     DPTR
   \   00013A   A3           INC     DPTR
   \   00013B   A3           INC     DPTR
   \   00013C   A3           INC     DPTR
   \   00013D   708E         JNZ     ??HalUARTWrite_8
   \   00013F   E4           CLR     A
   \   000140   F0           MOVX    @DPTR,A
   \   000141   A3           INC     DPTR
   \   000142   8091         SJMP    ??HalUARTWrite_9
   1070            }
   1071          
   1072          #if HAL_UART_ISR
   1073          #if HAL_UART_DMA
   1074            if ( !(cfg->flag & UART_CFG_DMA) )
   1075          #endif
   1076            {
   1077              if ( !(cfg->flag & UART_CFG_TXF) && len )
   1078              {
   1079                cfg->flag |= UART_CFG_TXF;
   1080                if ( !(cfg->flag & UART_CFG_U1F) )
   1081                {
   1082                  U0DBUF = cfg->txBuf[cfg->txTail];
   1083                }
   1084                else
   1085                {
   1086                  U1DBUF = cfg->txBuf[cfg->txTail];
   1087                }
   1088              }
   1089            }
   1090          #endif
   1091          
   1092            return len;
   \                     ??HalUARTWrite_6:
   \   000144   02....       LJMP    ?Subroutine26 & 0xFFFF
   1093          }

   \                                 In  segment BANKED_CODE, align 1, keep-with-next
   \                     ?Subroutine20:
   \   000000   E8           MOV     A,R0
   \                     ??Subroutine20_0:
   \   000001   240C         ADD     A,#0xc
   \   000003   F582         MOV     DPL,A
   \   000005   E9           MOV     A,R1
   \   000006   22           RET

   \                                 In  segment BANKED_CODE, align 1, keep-with-next
   \                     ?Subroutine16:
   \   000000   E0           MOVX    A,@DPTR
   \   000001   C3           CLR     C
   \   000002   9C           SUBB    A,R4
   \   000003   FC           MOV     R4,A
   \   000004   A3           INC     DPTR
   \   000005   E0           MOVX    A,@DPTR
   \   000006   9D           SUBB    A,R5
   \   000007   FD           MOV     R5,A
   \   000008   22           RET

   \                                 In  segment BANKED_CODE, align 1, keep-with-next
   \                     ?Subroutine15:
   \   000000   8882         MOV     DPL,R0
   \   000002   8983         MOV     DPH,R1
   \   000004   A3           INC     DPTR
   \   000005   A3           INC     DPTR
   \   000006   A3           INC     DPTR
   \   000007   A3           INC     DPTR
   \   000008   A3           INC     DPTR
   \   000009   A3           INC     DPTR
   \   00000A   A3           INC     DPTR
   \   00000B   A3           INC     DPTR
   \   00000C   A3           INC     DPTR
   \   00000D   A3           INC     DPTR
   \                     ??Subroutine15_0:
   \   00000E   E0           MOVX    A,@DPTR
   \   00000F   FC           MOV     R4,A
   \   000010   A3           INC     DPTR
   \   000011   E0           MOVX    A,@DPTR
   \   000012   FD           MOV     R5,A
   \   000013   22           RET

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

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

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

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

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

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

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

   \                                 In  segment BANK_RELAYS, align 1
   \                     ??HalUARTWrite?relay:
   \   000000   12....       LCALL   ?BDISPATCH
   \   000003   ......       DC24    HalUARTWrite
   1094          
   1095          #if HAL_UART_ISR
   1096          /***************************************************************************************************
   1097           * @fn      halUart0RxIsr
   1098           *
   1099           * @brief   UART0 Receive Interrupt
   1100           *
   1101           * @param   None
   1102           *
   1103           * @return  None
   1104           ***************************************************************************************************/
   1105          #if HAL_UART_0_ENABLE
   1106          HAL_ISR_FUNCTION( halUart0RxIsr, URX0_VECTOR )
   1107          {
   1108            cfg0->rxBuf[cfg0->rxHead] = U0DBUF;
   1109          
   1110            if ( cfg0->rxHead == cfg0->rxMax )
   1111            {
   1112              cfg0->rxHead = 0;
   1113            }
   1114            else
   1115            {
   1116              cfg0->rxHead++;
   1117            }
   1118          }
   1119          #endif
   1120          
   1121          /***************************************************************************************************
   1122           * @fn      halUart1RxIsr
   1123           *
   1124           * @brief   UART1 Receive Interrupt
   1125           *
   1126           * @param   None
   1127           *
   1128           * @return  None
   1129           ***************************************************************************************************/
   1130          #if HAL_UART_1_ENABLE
   1131          HAL_ISR_FUNCTION( halUart1RxIsr, URX1_VECTOR )
   1132          {
   1133            cfg1->rxBuf[cfg1->rxHead] = U1DBUF;
   1134          
   1135            if ( cfg1->rxHead == cfg1->rxMax )
   1136            {
   1137              cfg1->rxHead = 0;
   1138            }
   1139            else
   1140            {
   1141              cfg1->rxHead++;
   1142            }
   1143          }
   1144          #endif
   1145          
   1146          /***************************************************************************************************
   1147           * @fn      halUart0TxIsr
   1148           *
   1149           * @brief   UART0 Transmit Interrupt
   1150           *
   1151           * @param   None
   1152           *
   1153           * @return  None
   1154           ***************************************************************************************************/
   1155          #if HAL_UART_0_ENABLE
   1156          HAL_ISR_FUNCTION( halUart0TxIsr, UTX0_VECTOR )
   1157          {
   1158            UTX0IF = 0;
   1159          
   1160            if ( cfg0->txTail == cfg0->txMax )
   1161            {
   1162              cfg0->txTail = 0;
   1163            }
   1164            else
   1165            {
   1166              cfg0->txTail++;
   1167            }
   1168          
   1169            if ( cfg0->txTail != cfg0->txHead )
   1170            {
   1171              U0DBUF = cfg0->txBuf[cfg0->txTail];
   1172            }
   1173          }
   1174          #endif
   1175          
   1176          /***************************************************************************************************
   1177           * @fn      halUart1TxIsr
   1178           *
   1179           * @brief   UART1 Transmit Interrupt
   1180           *
   1181           * @param   None
   1182           *
   1183           * @return  None
   1184           ***************************************************************************************************/
   1185          #if HAL_UART_1_ENABLE
   1186          HAL_ISR_FUNCTION( halUart1TxIsr, UTX1_VECTOR )
   1187          {
   1188            UTX1IF = 0;
   1189            U1CSR &= ~CSR_TX_BYTE;  // Rev-D does not require, older does.
   1190          
   1191            if ( cfg1->txTail == cfg1->txMax )
   1192            {
   1193              cfg1->txTail = 0;
   1194            }
   1195            else
   1196            {
   1197              cfg1->txTail++;
   1198            }
   1199          
   1200            if ( cfg1->txTail != cfg1->txHead )
   1201            {
   1202              U1DBUF = cfg1->txBuf[cfg1->txTail];
   1203            }
   1204          }
   1205          #endif
   1206          #endif
   1207          
   1208          /******************************************************************************
   1209          ******************************************************************************/

   Maximum stack usage in bytes:

     Function            ISTACK PSTACK XSTACK
     --------            ------ ------ ------
     HalUARTClose            0      0      0
     HalUARTInit             2      0      0
     HalUARTOpen             1      0     15
       -> osal_mem_alloc     0      0     30
       -> osal_mem_alloc     0      0     30
       -> osal_mem_alloc     0      0     30
       -> osal_memset        0      0     30
     HalUARTPoll             1      0      9
       -> pollDMA            0      0     18
     HalUARTRead             1      0     12
     HalUARTWrite            2      0     12
     Hal_UART_RxBufLen       3      0      0
     pollDMA                 2      0     20
       -> osal_memset        0      0     22


   Segment part sizes:

     Function/Label            Bytes
     --------------            -----
     _A_P0                        1
     U0CSR                        1
     _A_P1                        1
     ST0                          1
     U0DBUF                       1
     U0BAUD                       1
     U0UCR                        1
     U0GCR                        1
     DMAIRQ                       1
     DMAARM                       1
     DMAREQ                       1
     PERCFG                       1
     ADCCFG                       1
     P0SEL                        1
     P0DIR                        1
     P2DIR                        1
     cfg0                         2
     pollDMA                    630
     ?Subroutine8                10
     ?Subroutine6                11
     ?Subroutine5                11
     ?Subroutine1                10
     ?Subroutine22                3
     ?Subroutine24                6
     ?Subroutine18               15
     ?Subroutine11               29
     ?Subroutine10               18
     ?Subroutine9                19
     ?Subroutine2                 9
     ?Subroutine0                 9
     ?Subroutine21                7
     ?Subroutine12               18
     ?Subroutine4                10
     ?Subroutine3                30
     ?Subroutine23                8
     HalUARTInit                 89
     ?Subroutine25                7
     HalUARTOpen                331
     ?Subroutine19               13
     ?Subroutine7                 8
     HalUARTClose                 3
     HalUARTPoll                218
     tickShdw                     1
     Hal_UART_RxBufLen           93
     ?Subroutine13               11
     ?Subroutine14                6
     HalUARTRead                143
     ?Subroutine26                5
     ?Subroutine17                9
     HalUARTWrite               327
     ?Subroutine20                7
     ?Subroutine16                9
     ?Subroutine15               20
     ??pollDMA?relay              6
     ??HalUARTInit?relay          6
     ??HalUARTOpen?relay          6
     ??HalUARTClose?relay         6
     ??HalUARTPoll?relay          6
     ??Hal_UART_RxBufLen?relay    6
     ??HalUARTRead?relay          6
     ??HalUARTWrite?relay         6

 
 2 152 bytes in segment BANKED_CODE
    48 bytes in segment BANK_RELAYS
    16 bytes in segment SFR_AN
     3 bytes in segment XDATA_Z
 
 2 200 bytes of CODE  memory
     0 bytes of DATA  memory (+ 16 bytes shared)
     3 bytes of XDATA memory

Errors: none
Warnings: none
