###############################################################################
#                                                                             #
# IAR 8051 C/C++ Compiler V7.30B/W32                    12/Sep/2010  21:57:27 #
# 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\mt\SPIMgr.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\mt\SPIMgr.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\SP #
#                          IMgr.lst                                           #
#    Object file        =  C:\Texas Instruments 33\ZStack-1.4.3-1.2.1\Project #
#                          s\zstack\Project\Location\CC2430DB\RefNode\Obj\SPI #
#                          Mgr.r51                                            #
#                                                                             #
#                                                                             #
###############################################################################

C:\Texas Instruments 33\ZStack-1.4.3-1.2.1\Components\mt\SPIMgr.c
      1          /**************************************************************************************************
      2            Filename:       SPIMgr.c
      3            Revised:        $Date: 2007-10-28 18:43:04 -0700 (Sun, 28 Oct 2007) $
      4            Revision:       $Revision: 15800 $
      5          
      6            Description:    This module handles anything dealing with the serial port.
      7          
      8          
      9            Copyright 2005-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          #include "ZComDef.h"
     44          #include "OSAL.h"
     45          #include "hal_uart.h"
     46          #include "MTEL.h"
     47          #include "SPIMgr.h"
     48          #include "OSAL_Memory.h"
     49          
     50          /***************************************************************************************************
     51           *                                            MACROS
     52           ***************************************************************************************************/
     53          
     54          /***************************************************************************************************
     55           *                                           CONSTANTS
     56           ***************************************************************************************************/
     57          
     58          /* State values for ZTool protocal */
     59          #define SOP_STATE      0x00
     60          #define CMD_STATE1     0x01
     61          #define CMD_STATE2     0x02
     62          #define LEN_STATE      0x03
     63          #define DATA_STATE     0x04
     64          #define FCS_STATE      0x05
     65          
     66          /***************************************************************************************************
     67           *                                            TYPEDEFS
     68           ***************************************************************************************************/
     69          
     70          /***************************************************************************************************
     71           *                                         GLOBAL VARIABLES
     72           ***************************************************************************************************/

   \                                 In  segment XDATA_Z, align 1, keep-with-next
     73          byte App_TaskID;
   \                     App_TaskID:
   \   000000                DS 1
   \   000001                REQUIRE __INIT_XDATA_Z
     74          
     75          /* ZTool protocal parameters */
     76          
     77          #if defined (ZTOOL_P1) || defined (ZTOOL_P2)

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

   \                                 In  segment XDATA_Z, align 1, keep-with-next
     79          uint8  CMD_Token[2];
   \                     CMD_Token:
   \   000000                DS 2
   \   000002                REQUIRE __INIT_XDATA_Z

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

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

   \                                 In  segment XDATA_Z, align 1, keep-with-next
     82          mtOSALSerialData_t  *SPI_Msg;
   \                     SPI_Msg:
   \   000000                DS 2
   \   000002                REQUIRE __INIT_XDATA_Z

   \                                 In  segment XDATA_Z, align 1, keep-with-next
     83          uint8  tempDataLen;
   \                     tempDataLen:
   \   000000                DS 1
   \   000001                REQUIRE __INIT_XDATA_Z
     84          #endif //ZTOOL
     85          
     86          #if defined (ZAPP_P1) || defined (ZAPP_P2)
     87          uint16  SPIMgr_MaxZAppBufLen;
     88          bool    SPIMgr_ZAppRxStatus;
     89          #endif
     90          
     91          
     92          /***************************************************************************************************
     93           *                                          LOCAL FUNCTIONS
     94           ***************************************************************************************************/
     95          
     96          /***************************************************************************************************
     97           * @fn      SPIMgr_Init
     98           *
     99           * @brief
    100           *
    101           * @param   None
    102           *
    103           * @return  None
    104          ***************************************************************************************************/

   \                                 In  segment BANKED_CODE, align 1, keep-with-next
    105          void SPIMgr_Init ()
   \                     SPIMgr_Init:
    106          {
   \   000000   C082         PUSH    DPL
   \   000002   C083         PUSH    DPH
   \   000004                ; Saved register size: 2
   \   000004                ; Auto size: 29
   \   000004   74E3         MOV     A,#-0x1d
   \   000006   12....       LCALL   ?ALLOC_XSTACK8
    107            halUARTCfg_t uartConfig;
    108          
    109            /* Initialize APP ID */
    110            App_TaskID = 0;
   \   000009   E4           CLR     A
   \   00000A   90....       MOV     DPTR,#App_TaskID
   \   00000D   F0           MOVX    @DPTR,A
    111          
    112            /* UART Configuration */
    113            uartConfig.configured           = TRUE;
   \   00000E   7401         MOV     A,#0x1
   \   000010   85..82       MOV     DPL,?XSP + 0
   \   000013   85..83       MOV     DPH,?XSP + 1
   \   000016   F0           MOVX    @DPTR,A
    114            uartConfig.baudRate             = SPI_MGR_DEFAULT_BAUDRATE;
   \   000017   12....       LCALL   ?XSTACK_DISP0_8
   \   00001A   7406         MOV     A,#0x6
   \   00001C   F0           MOVX    @DPTR,A
    115            uartConfig.flowControl          = 0;//SPI_MGR_DEFAULT_OVERFLOW;
   \   00001D   7402         MOV     A,#0x2
   \   00001F   12....       LCALL   ?XSTACK_DISP0_8
   \   000022   E4           CLR     A
   \   000023   F0           MOVX    @DPTR,A
    116            uartConfig.flowControlThreshold = SPI_MGR_DEFAULT_THRESHOLD;
   \   000024   7403         MOV     A,#0x3
   \   000026   12....       LCALL   ?XSTACK_DISP0_8
   \   000029   7430         MOV     A,#0x30
   \   00002B   F0           MOVX    @DPTR,A
   \   00002C   A3           INC     DPTR
   \   00002D   E4           CLR     A
   \   00002E   F0           MOVX    @DPTR,A
    117            uartConfig.rx.maxBufSize        = SPI_MGR_DEFAULT_MAX_RX_BUFF;
   \   00002F   740A         MOV     A,#0xa
   \   000031   12....       LCALL   ?XSTACK_DISP0_8
   \   000034   7480         MOV     A,#-0x80
   \   000036   F0           MOVX    @DPTR,A
   \   000037   A3           INC     DPTR
   \   000038   E4           CLR     A
   \   000039   F0           MOVX    @DPTR,A
    118            uartConfig.tx.maxBufSize        = SPI_MGR_DEFAULT_MAX_TX_BUFF;
   \   00003A   7412         MOV     A,#0x12
   \   00003C   12....       LCALL   ?XSTACK_DISP0_8
   \   00003F   E4           CLR     A
   \   000040   F0           MOVX    @DPTR,A
   \   000041   A3           INC     DPTR
   \   000042   7404         MOV     A,#0x4
   \   000044   F0           MOVX    @DPTR,A
    119            uartConfig.idleTimeout          = SPI_MGR_DEFAULT_IDLE_TIMEOUT;
   \   000045   7405         MOV     A,#0x5
   \   000047   12....       LCALL   ?XSTACK_DISP0_8
   \   00004A   7406         MOV     A,#0x6
   \   00004C   F0           MOVX    @DPTR,A
    120            uartConfig.intEnable            = TRUE;
   \   00004D   7416         MOV     A,#0x16
   \   00004F   12....       LCALL   ?XSTACK_DISP0_8
   \   000052   7401         MOV     A,#0x1
   \   000054   F0           MOVX    @DPTR,A
    121          #if defined (ZTOOL_P1) || defined (ZTOOL_P2)
    122            uartConfig.callBackFunc         = UART_MsgRevCB;
   \   000055   741B         MOV     A,#0x1b
   \   000057   12....       LCALL   ?XSTACK_DISP0_8
   \   00005A   74..         MOV     A,#(??UART_MsgRevCB?relay & 0xff)
   \   00005C   F0           MOVX    @DPTR,A
   \   00005D   A3           INC     DPTR
   \   00005E   74..         MOV     A,#((??UART_MsgRevCB?relay >> 8) & 0xff)
   \   000060   F0           MOVX    @DPTR,A
    123          #elif defined (ZAPP_P1) || defined (ZAPP_P2)
    124            uartConfig.callBackFunc         = UART_MsgRevCB;
    125          #else
    126            uartConfig.callBackFunc         = UART_MsgRevCB;
    127          #endif
    128          
    129            /* Start UART */
    130          #if defined (SPI_MGR_DEFAULT_PORT)
    131            HalUARTOpen (SPI_MGR_DEFAULT_PORT, &uartConfig);
   \   000061                ; Setup parameters for call to function HalUARTOpen
   \   000061   85..82       MOV     DPL,?XSP + 0
   \   000064   85..83       MOV     DPH,?XSP + 1
   \   000067   AA82         MOV     R2,DPL
   \   000069   AB83         MOV     R3,DPH
   \   00006B   7900         MOV     R1,#0x0
   \   00006D   12....       LCALL   ??HalUARTOpen?relay
    132          #else
    133            /* Silence IAR compiler warning */
    134            (void)uartConfig;
    135          #endif
    136          
    137            /* Initialize for ZApp */
    138          #if defined (ZAPP_P1) || defined (ZAPP_P2)
    139            /* Default max bytes that ZAPP can take */
    140            SPIMgr_MaxZAppBufLen  = 1;
    141            SPIMgr_ZAppRxStatus   = SPI_MGR_ZAPP_RX_READY;
    142          #endif
    143          
    144          
    145          }
   \   000070   741D         MOV     A,#0x1d
   \   000072   12....       LCALL   ?DEALLOC_XSTACK8
   \   000075                REQUIRE ?Subroutine5
   \   000075                ; // Fall through to label ?Subroutine5

   \                                 In  segment BANKED_CODE, align 1, keep-with-next
   \                     ?Subroutine5:
   \   000000   D083         POP     DPH
   \   000002   D082         POP     DPL
   \   000004   02....       LJMP    ?BRET
    146          
    147          /***************************************************************************************************
    148           * @fn      MT_SerialRegisterTaskID
    149           *
    150           * @brief
    151           *
    152           *   This function registers the taskID of the application so it knows
    153           *   where to send the messages whent they come in.
    154           *
    155           * @param   void
    156           *
    157           * @return  void
    158           ***************************************************************************************************/

   \                                 In  segment BANKED_CODE, align 1, keep-with-next
    159          void SPIMgr_RegisterTaskID( byte taskID )
   \                     SPIMgr_RegisterTaskID:
    160          {
   \   000000   C082         PUSH    DPL
   \   000002   C083         PUSH    DPH
   \   000004                ; Saved register size: 2
   \   000004                ; Auto size: 0
    161            App_TaskID = taskID;
   \   000004   E9           MOV     A,R1
   \   000005   90....       MOV     DPTR,#App_TaskID
   \   000008   F0           MOVX    @DPTR,A
    162          }
   \   000009   80..         SJMP    ?Subroutine5
    163          
    164          /***************************************************************************************************
    165           * @fn      SPIMgr_CalcFCS
    166           *
    167           * @brief
    168           *
    169           *   Calculate the FCS of a message buffer by XOR'ing each byte.
    170           *   Remember to NOT include SOP and FCS fields, so start at the CMD
    171           *   field.
    172           *
    173           * @param   byte *msg_ptr - message pointer
    174           * @param   byte len - length (in bytes) of message
    175           *
    176           * @return  result byte
    177           ***************************************************************************************************/

   \                                 In  segment BANKED_CODE, align 1, keep-with-next
    178          byte SPIMgr_CalcFCS( uint8 *msg_ptr, uint8 len )
   \                     SPIMgr_CalcFCS:
    179          {
   \   000000   74F7         MOV     A,#-0x9
   \   000002   12....       LCALL   ?BANKED_ENTER_XDATA
   \   000005                ; Saved register size: 9
   \   000005                ; Auto size: 0
   \   000005   E9           MOV     A,R1
   \   000006   FC           MOV     R4,A
    180            byte x;
    181            byte xorResult;
    182          
    183            xorResult = 0;
   \   000007   7900         MOV     R1,#0x0
    184          
    185            for ( x = 0; x < len; x++, msg_ptr++ )
   \   000009   7D00         MOV     R5,#0x0
   \   00000B   800E         SJMP    ??SPIMgr_CalcFCS_0
    186              xorResult = xorResult ^ *msg_ptr;
   \                     ??SPIMgr_CalcFCS_1:
   \   00000D   8A82         MOV     DPL,R2
   \   00000F   8B83         MOV     DPH,R3
   \   000011   E0           MOVX    A,@DPTR
   \   000012   C9           XCH     A,R1
   \   000013   69           XRL     A,R1
   \   000014   F9           MOV     R1,A
   \   000015   0D           INC     R5
   \   000016   A3           INC     DPTR
   \   000017   AA82         MOV     R2,DPL
   \   000019   AB83         MOV     R3,DPH
   \                     ??SPIMgr_CalcFCS_0:
   \   00001B   ED           MOV     A,R5
   \   00001C   C3           CLR     C
   \   00001D   9C           SUBB    A,R4
   \   00001E   40ED         JC      ??SPIMgr_CalcFCS_1
    187          
    188            return ( xorResult );
   \   000020   7F01         MOV     R7,#0x1
   \   000022   02....       LJMP    ?BANKED_LEAVE_XDATA
    189          }
    190          
    191          
    192          #if defined (ZTOOL_P1) || defined (ZTOOL_P2)
    193          /***************************************************************************************************
    194           * @fn      SPIMgr_ProcessZToolRxData
    195           *
    196           * @brief   | SOP | CMD  |   Data Length   | FSC  |
    197           *          |  1  |  2   |       1         |  1   |
    198           *
    199           *          Parses the data and determine either is SPI or just simply serial data
    200           *          then send the data to correct place (MT or APP)
    201           *
    202           * @param   pBuffer  - pointer to the buffer that contains the data
    203           *          length   - length of the buffer
    204           *
    205           *
    206           * @return  None
    207           ***************************************************************************************************/

   \                                 In  segment BANKED_CODE, align 1, keep-with-next
    208          void SPIMgr_ProcessZToolData ( uint8 port, uint8 event )
   \                     SPIMgr_ProcessZToolData:
    209          {
   \   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
    210            uint8  ch;
    211          
    212            /* Verify events */
    213            if (event == HAL_UART_TX_FULL)
   \   00000A   7408         MOV     A,#0x8
   \   00000C   6A           XRL     A,R2
   \   00000D   6005         JZ      ??SPIMgr_ProcessZToolData_0
    214            {
    215              // Do something when TX if full
    216              return;
    217            }
    218          
    219            if (event & (HAL_UART_RX_FULL | HAL_UART_RX_ABOUT_FULL | HAL_UART_RX_TIMEOUT))
   \   00000F   7407         MOV     A,#0x7
   \   000011   5A           ANL     A,R2
   \   000012   701B         JNZ     ??SPIMgr_ProcessZToolData_1
   \                     ??SPIMgr_ProcessZToolData_0:
   \   000014   7401         MOV     A,#0x1
   \   000016   12....       LCALL   ?DEALLOC_XSTACK8
   \   000019   7F02         MOV     R7,#0x2
   \   00001B   02....       LJMP    ?BANKED_LEAVE_XDATA
    220            {
    221              while (Hal_UART_RxBufLen(SPI_MGR_DEFAULT_PORT))
    222              {
    223                HalUARTRead (SPI_MGR_DEFAULT_PORT, &ch, 1);
    224          
    225                switch (state)
    226                {
    227                  case SOP_STATE:
    228                    if (ch == SOP_VALUE)
    229                      state = CMD_STATE1;
    230                    break;
    231          
    232                  case CMD_STATE1:
    233                    CMD_Token[0] = ch;
   \                     ??SPIMgr_ProcessZToolData_2:
   \   00001E   85..82       MOV     DPL,?XSP + 0
   \   000021   85..83       MOV     DPH,?XSP + 1
   \   000024   E0           MOVX    A,@DPTR
   \   000025   90....       MOV     DPTR,#CMD_Token
   \   000028   F0           MOVX    @DPTR,A
    234                    state = CMD_STATE2;
   \   000029   7402         MOV     A,#0x2
   \                     ??SPIMgr_ProcessZToolData_3:
   \   00002B   90....       MOV     DPTR,#state
   \                     ??SPIMgr_ProcessZToolData_4:
   \   00002E   F0           MOVX    @DPTR,A
   \                     ??SPIMgr_ProcessZToolData_1:
   \   00002F                ; Setup parameters for call to function Hal_UART_RxBufLen
   \   00002F   7900         MOV     R1,#0x0
   \   000031   12....       LCALL   ??Hal_UART_RxBufLen?relay
   \   000034   EA           MOV     A,R2
   \   000035   7001         JNZ     ??SPIMgr_ProcessZToolData_5
   \   000037   EB           MOV     A,R3
   \                     ??SPIMgr_ProcessZToolData_5:
   \   000038   60DA         JZ      ??SPIMgr_ProcessZToolData_0
   \   00003A                ; Setup parameters for call to function HalUARTRead
   \   00003A   7C01         MOV     R4,#0x1
   \   00003C   7D00         MOV     R5,#0x0
   \   00003E   85..82       MOV     DPL,?XSP + 0
   \   000041   85..83       MOV     DPH,?XSP + 1
   \   000044   AA82         MOV     R2,DPL
   \   000046   AB83         MOV     R3,DPH
   \   000048   7900         MOV     R1,#0x0
   \   00004A   12....       LCALL   ??HalUARTRead?relay
   \   00004D   90....       MOV     DPTR,#state
   \   000050   E0           MOVX    A,@DPTR
   \   000051   12....       LCALL   ?UC_SWITCH_DENSE
   \                     `?<Jumptable for SPIMgr_ProcessZToolData>_0`:
   \   000054   00           DB        0
   \   000055   05           DB        5
   \   000056   ....         DW        ??SPIMgr_ProcessZToolData_1
   \   000058   ....         DW        ??SPIMgr_ProcessZToolData_6
   \   00005A   ....         DW        ??SPIMgr_ProcessZToolData_2
   \   00005C   ....         DW        ??SPIMgr_ProcessZToolData_7
   \   00005E   ....         DW        ??SPIMgr_ProcessZToolData_8
   \   000060   ....         DW        ??SPIMgr_ProcessZToolData_9
   \   000062   ....         DW        ??SPIMgr_ProcessZToolData_10
   \                     ??SPIMgr_ProcessZToolData_6:
   \   000064   85..82       MOV     DPL,?XSP + 0
   \   000067   85..83       MOV     DPH,?XSP + 1
   \   00006A   E0           MOVX    A,@DPTR
   \   00006B   6402         XRL     A,#0x2
   \   00006D   70C0         JNZ     ??SPIMgr_ProcessZToolData_1
   \   00006F   7401         MOV     A,#0x1
   \   000071   80B8         SJMP    ??SPIMgr_ProcessZToolData_3
    235                    break;
    236          
    237                  case CMD_STATE2:
    238                    CMD_Token[1] = ch;
   \                     ??SPIMgr_ProcessZToolData_7:
   \   000073   85..82       MOV     DPL,?XSP + 0
   \   000076   85..83       MOV     DPH,?XSP + 1
   \   000079   E0           MOVX    A,@DPTR
   \   00007A   90....       MOV     DPTR,#(CMD_Token + 1)
   \   00007D   F0           MOVX    @DPTR,A
    239                    state = LEN_STATE;
   \   00007E   7403         MOV     A,#0x3
   \   000080   80A9         SJMP    ??SPIMgr_ProcessZToolData_3
    240                    break;
    241          
    242                  case LEN_STATE:
    243                    LEN_Token = ch;
   \                     ??SPIMgr_ProcessZToolData_8:
   \   000082   85..82       MOV     DPL,?XSP + 0
   \   000085   85..83       MOV     DPH,?XSP + 1
   \   000088   E0           MOVX    A,@DPTR
   \   000089   90....       MOV     DPTR,#LEN_Token
   \   00008C   F0           MOVX    @DPTR,A
    244                    if (ch == 0)
   \   00008D   85..82       MOV     DPL,?XSP + 0
   \   000090   85..83       MOV     DPH,?XSP + 1
   \   000093   E0           MOVX    A,@DPTR
   \   000094   7004         JNZ     ??SPIMgr_ProcessZToolData_11
    245                      state = FCS_STATE;
   \   000096   7405         MOV     A,#0x5
   \   000098   8002         SJMP    ??SPIMgr_ProcessZToolData_12
    246                    else
    247                      state = DATA_STATE;
   \                     ??SPIMgr_ProcessZToolData_11:
   \   00009A   7404         MOV     A,#0x4
   \                     ??SPIMgr_ProcessZToolData_12:
   \   00009C   90....       MOV     DPTR,#state
   \   00009F   F0           MOVX    @DPTR,A
    248          
    249                    tempDataLen = 0;
   \   0000A0   E4           CLR     A
   \   0000A1   90....       MOV     DPTR,#tempDataLen
   \   0000A4   F0           MOVX    @DPTR,A
    250          
    251                    /* Allocate memory for the data */
    252                    SPI_Msg = (mtOSALSerialData_t *)osal_msg_allocate( sizeof ( mtOSALSerialData_t ) + 2+1+LEN_Token );
   \   0000A5                ; Setup parameters for call to function osal_msg_allocate
   \   0000A5   90....       MOV     DPTR,#LEN_Token
   \   0000A8   E0           MOVX    A,@DPTR
   \   0000A9   F8           MOV     R0,A
   \   0000AA   7407         MOV     A,#0x7
   \   0000AC   28           ADD     A,R0
   \   0000AD   FA           MOV     R2,A
   \   0000AE   E4           CLR     A
   \   0000AF   3400         ADDC    A,#0x0
   \   0000B1   FB           MOV     R3,A
   \   0000B2   12....       LCALL   ??osal_msg_allocate?relay
   \   0000B5   90....       MOV     DPTR,#SPI_Msg
   \   0000B8   EA           MOV     A,R2
   \   0000B9   F0           MOVX    @DPTR,A
   \   0000BA   A3           INC     DPTR
   \   0000BB   EB           MOV     A,R3
   \   0000BC   F0           MOVX    @DPTR,A
    253          
    254                    if (SPI_Msg)
   \   0000BD   90....       MOV     DPTR,#SPI_Msg
   \   0000C0   E0           MOVX    A,@DPTR
   \   0000C1   7002         JNZ     ??SPIMgr_ProcessZToolData_13
   \   0000C3   A3           INC     DPTR
   \   0000C4   E0           MOVX    A,@DPTR
   \                     ??SPIMgr_ProcessZToolData_13:
   \   0000C5   6044         JZ      ??SPIMgr_ProcessZToolData_14
    255                    {
    256                      /* Fill up what we can */
    257                      SPI_Msg->hdr.event = CMD_SERIAL_MSG;
   \   0000C7   12....       LCALL   ?Subroutine4 & 0xFFFF
   \                     ??CrossCallReturnLabel_8:
   \   0000CA   7401         MOV     A,#0x1
   \   0000CC   F0           MOVX    @DPTR,A
    258                      SPI_Msg->msg = (uint8*)(SPI_Msg+1);
   \   0000CD   90....       MOV     DPTR,#SPI_Msg
   \   0000D0   E0           MOVX    A,@DPTR
   \   0000D1   2404         ADD     A,#0x4
   \   0000D3   F8           MOV     R0,A
   \   0000D4   A3           INC     DPTR
   \   0000D5   E0           MOVX    A,@DPTR
   \   0000D6   3400         ADDC    A,#0x0
   \   0000D8   F9           MOV     R1,A
   \   0000D9   12....       LCALL   ?Subroutine2 & 0xFFFF
   \                     ??CrossCallReturnLabel_4:
   \   0000DC   E8           MOV     A,R0
   \   0000DD   F0           MOVX    @DPTR,A
   \   0000DE   A3           INC     DPTR
   \   0000DF   E9           MOV     A,R1
   \   0000E0   F0           MOVX    @DPTR,A
    259                      SPI_Msg->msg[0] = CMD_Token[0];
   \   0000E1   90....       MOV     DPTR,#CMD_Token
   \   0000E4   E0           MOVX    A,@DPTR
   \   0000E5   C0E0         PUSH    A
   \   0000E7   12....       LCALL   ?Subroutine1 & 0xFFFF
   \                     ??CrossCallReturnLabel_2:
   \   0000EA   12....       LCALL   ??Subroutine4_0 & 0xFFFF
   \                     ??CrossCallReturnLabel_9:
   \   0000ED   D0E0         POP     A
   \   0000EF   F0           MOVX    @DPTR,A
    260                      SPI_Msg->msg[1] = CMD_Token[1];
   \   0000F0   90....       MOV     DPTR,#(CMD_Token + 1)
   \   0000F3   E0           MOVX    A,@DPTR
   \   0000F4   C0E0         PUSH    A
   \   0000F6   12....       LCALL   ?Subroutine0 & 0xFFFF
   \                     ??CrossCallReturnLabel_0:
   \   0000F9   D0E0         POP     A
   \   0000FB   F0           MOVX    @DPTR,A
    261                      SPI_Msg->msg[2] = LEN_Token;
   \   0000FC   90....       MOV     DPTR,#LEN_Token
   \   0000FF   E0           MOVX    A,@DPTR
   \   000100   C0E0         PUSH    A
   \   000102   12....       LCALL   ?Subroutine0 & 0xFFFF
   \                     ??CrossCallReturnLabel_1:
   \   000105   A3           INC     DPTR
   \   000106   D0E0         POP     A
   \   000108   02....       LJMP    ??SPIMgr_ProcessZToolData_4 & 0xFFFF
    262                    }
    263                    else
    264                    {
    265                      state = SOP_STATE;
   \                     ??SPIMgr_ProcessZToolData_14:
   \   00010B   E4           CLR     A
   \   00010C   90....       MOV     DPTR,#state
   \   00010F   F0           MOVX    @DPTR,A
    266                      return;
   \   000110   02....       LJMP    ??SPIMgr_ProcessZToolData_0 & 0xFFFF
    267                    }
    268          
    269                    break;
    270          
    271                  case DATA_STATE:
    272                      SPI_Msg->msg[3 + tempDataLen++] = ch;
   \                     ??SPIMgr_ProcessZToolData_9:
   \   000113   85..82       MOV     DPL,?XSP + 0
   \   000116   85..83       MOV     DPH,?XSP + 1
   \   000119   E0           MOVX    A,@DPTR
   \   00011A   C0E0         PUSH    A
   \   00011C   90....       MOV     DPTR,#tempDataLen
   \   00011F   E0           MOVX    A,@DPTR
   \   000120   F8           MOV     R0,A
   \   000121   12....       LCALL   ?Subroutine2 & 0xFFFF
   \                     ??CrossCallReturnLabel_5:
   \   000124   E0           MOVX    A,@DPTR
   \   000125   28           ADD     A,R0
   \   000126   FA           MOV     R2,A
   \   000127   A3           INC     DPTR
   \   000128   E0           MOVX    A,@DPTR
   \   000129   3400         ADDC    A,#0x0
   \   00012B   8A82         MOV     DPL,R2
   \   00012D   F583         MOV     DPH,A
   \   00012F   A3           INC     DPTR
   \   000130   A3           INC     DPTR
   \   000131   A3           INC     DPTR
   \   000132   D0E0         POP     A
   \   000134   F0           MOVX    @DPTR,A
   \   000135   90....       MOV     DPTR,#tempDataLen
   \   000138   E0           MOVX    A,@DPTR
   \   000139   04           INC     A
   \   00013A   F0           MOVX    @DPTR,A
    273                      if ( tempDataLen == LEN_Token )
   \   00013B   FA           MOV     R2,A
   \   00013C   90....       MOV     DPTR,#LEN_Token
   \   00013F   E0           MOVX    A,@DPTR
   \   000140   6A           XRL     A,R2
   \   000141   6003         JZ      $+5
   \   000143   02....       LJMP    ??SPIMgr_ProcessZToolData_1 & 0xFFFF
    274                        state = FCS_STATE;
   \   000146   7405         MOV     A,#0x5
   \   000148   02....       LJMP    ??SPIMgr_ProcessZToolData_3 & 0xFFFF
    275                    break;
    276          
    277                  case FCS_STATE:
    278          
    279                    FSC_Token = ch;
   \                     ??SPIMgr_ProcessZToolData_10:
   \   00014B   85..82       MOV     DPL,?XSP + 0
   \   00014E   85..83       MOV     DPH,?XSP + 1
   \   000151   E0           MOVX    A,@DPTR
   \   000152   90....       MOV     DPTR,#FSC_Token
   \   000155   F0           MOVX    @DPTR,A
    280          
    281                    /* Make sure it's correct */
    282                    if ((SPIMgr_CalcFCS ((uint8*)&SPI_Msg->msg[0], 2 + 1 + LEN_Token) == FSC_Token))
   \   000156                ; Setup parameters for call to function SPIMgr_CalcFCS
   \   000156   90....       MOV     DPTR,#LEN_Token
   \   000159   E0           MOVX    A,@DPTR
   \   00015A   2403         ADD     A,#0x3
   \   00015C   F9           MOV     R1,A
   \   00015D   12....       LCALL   ?Subroutine1 & 0xFFFF
   \                     ??CrossCallReturnLabel_3:
   \   000160   FA           MOV     R2,A
   \   000161   A3           INC     DPTR
   \   000162   E0           MOVX    A,@DPTR
   \   000163   FB           MOV     R3,A
   \   000164   12....       LCALL   ??SPIMgr_CalcFCS?relay
   \   000167   E9           MOV     A,R1
   \   000168   FA           MOV     R2,A
   \   000169   90....       MOV     DPTR,#FSC_Token
   \   00016C   E0           MOVX    A,@DPTR
   \   00016D   6A           XRL     A,R2
   \   00016E   90....       MOV     DPTR,#SPI_Msg
   \   000171   700F         JNZ     ??SPIMgr_ProcessZToolData_15
    283                    {
    284                      osal_msg_send( MT_TaskID, (byte *)SPI_Msg );
   \   000173                ; Setup parameters for call to function osal_msg_send
   \   000173   E0           MOVX    A,@DPTR
   \   000174   FA           MOV     R2,A
   \   000175   A3           INC     DPTR
   \   000176   E0           MOVX    A,@DPTR
   \   000177   FB           MOV     R3,A
   \   000178   90....       MOV     DPTR,#MT_TaskID
   \   00017B   E0           MOVX    A,@DPTR
   \   00017C   F9           MOV     R1,A
   \   00017D   12....       LCALL   ??osal_msg_send?relay
   \   000180   8008         SJMP    ??SPIMgr_ProcessZToolData_16
    285                    }
    286                    else
    287                    {
    288                      /* deallocate the msg */
    289                      osal_msg_deallocate ( (uint8 *)SPI_Msg);
   \                     ??SPIMgr_ProcessZToolData_15:
   \   000182                ; Setup parameters for call to function osal_msg_deallocate
   \   000182   E0           MOVX    A,@DPTR
   \   000183   FA           MOV     R2,A
   \   000184   A3           INC     DPTR
   \   000185   E0           MOVX    A,@DPTR
   \   000186   FB           MOV     R3,A
   \   000187   12....       LCALL   ??osal_msg_deallocate?relay
    290                    }
    291          
    292                    /* Reset the state, send or discard the buffers at this point */
    293                    state = SOP_STATE;
   \                     ??SPIMgr_ProcessZToolData_16:
   \   00018A   E4           CLR     A
   \   00018B   02....       LJMP    ??SPIMgr_ProcessZToolData_3 & 0xFFFF
    294          
    295                    break;
    296          
    297                  default:
    298                   break;
    299                }
    300          
    301          
    302              }
    303            }
    304          }

   \                                 In  segment BANKED_CODE, align 1, keep-with-next
   \                     ?Subroutine2:
   \   000000   90....       MOV     DPTR,#SPI_Msg
   \   000003   E0           MOVX    A,@DPTR
   \   000004   FA           MOV     R2,A
   \   000005   A3           INC     DPTR
   \   000006   E0           MOVX    A,@DPTR
   \   000007   F583         MOV     DPH,A
   \   000009   8A82         MOV     DPL,R2
   \   00000B   A3           INC     DPTR
   \   00000C   A3           INC     DPTR
   \   00000D   22           RET

   \                                 In  segment BANKED_CODE, align 1, keep-with-next
   \                     ?Subroutine1:
   \   000000   12....       LCALL   ?Subroutine3 & 0xFFFF
   \                     ??CrossCallReturnLabel_7:
   \   000003   22           RET

   \                                 In  segment BANKED_CODE, align 1, keep-with-next
   \                     ?Subroutine3:
   \   000000   12....       LCALL   ?Subroutine4 & 0xFFFF
   \                     ??CrossCallReturnLabel_11:
   \   000003   A3           INC     DPTR
   \   000004   A3           INC     DPTR
   \   000005   E0           MOVX    A,@DPTR
   \   000006   22           RET

   \                                 In  segment BANKED_CODE, align 1, keep-with-next
   \                     ?Subroutine0:
   \   000000   12....       LCALL   ?Subroutine3 & 0xFFFF
   \                     ??CrossCallReturnLabel_6:
   \   000003   12....       LCALL   ??Subroutine4_0 & 0xFFFF
   \                     ??CrossCallReturnLabel_10:
   \   000006   A3           INC     DPTR
   \   000007   22           RET

   \                                 In  segment BANKED_CODE, align 1, keep-with-next
   \                     ?Subroutine4:
   \   000000   90....       MOV     DPTR,#SPI_Msg
   \   000003   E0           MOVX    A,@DPTR
   \                     ??Subroutine4_0:
   \   000004   F8           MOV     R0,A
   \   000005   A3           INC     DPTR
   \   000006   E0           MOVX    A,@DPTR
   \   000007   F583         MOV     DPH,A
   \   000009   8882         MOV     DPL,R0
   \   00000B   22           RET

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

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

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

   \                                 In  segment BANK_RELAYS, align 1
   \                     ??SPIMgr_ProcessZToolData?relay:
   \   000000   12....       LCALL   ?BDISPATCH
   \   000003   ......       DC24    SPIMgr_ProcessZToolData
    305          #endif //ZTOOL
    306          
    307          #if defined (ZAPP_P1) || defined (ZAPP_P2)
    308          /***************************************************************************************************
    309           * @fn      SPIMgr_ProcessZAppRxData
    310           *
    311           * @brief   | SOP | CMD  |   Data Length   | FSC  |
    312           *          |  1  |  2   |       1         |  1   |
    313           *
    314           *          Parses the data and determine either is SPI or just simply serial data
    315           *          then send the data to correct place (MT or APP)
    316           *
    317           * @param   pBuffer  - pointer to the buffer that contains the data
    318           *          length   - length of the buffer
    319           *
    320           *
    321           * @return  None
    322           ***************************************************************************************************/
    323          void SPIMgr_ProcessZAppData ( uint8 port, uint8 event )
    324          {
    325          
    326            osal_event_hdr_t  *msg_ptr;
    327            uint16 length = 0;
    328            uint16 rxBufLen  = Hal_UART_RxBufLen(SPI_MGR_DEFAULT_PORT);
    329          
    330            /*
    331               If maxZAppBufferLength is 0 or larger than current length
    332               the entire length of the current buffer is returned.
    333            */
    334            if ((SPIMgr_MaxZAppBufLen != 0) && (SPIMgr_MaxZAppBufLen <= rxBufLen))
    335            {
    336              length = SPIMgr_MaxZAppBufLen;
    337            }
    338            else
    339            {
    340              length = rxBufLen;
    341            }
    342          
    343            /* Verify events */
    344            if (event == HAL_UART_TX_FULL)
    345            {
    346              // Do something when TX if full
    347              return;
    348            }
    349          
    350            if (event & ( HAL_UART_RX_FULL | HAL_UART_RX_ABOUT_FULL | HAL_UART_RX_TIMEOUT))
    351            {
    352              if ( App_TaskID )
    353              {
    354                /*
    355                   If Application is ready to receive and there is something
    356                   in the Rx buffer then send it up
    357                */
    358                if ((SPIMgr_ZAppRxStatus == SPI_MGR_ZAPP_RX_READY ) && (length != 0))
    359                {
    360                  /* Disable App flow control until it processes the current data */
    361                   SPIMgr_AppFlowControl ( SPI_MGR_ZAPP_RX_NOT_READY );
    362          
    363                  /* 2 more bytes are added, 1 for CMD type, other for length */
    364                  msg_ptr = (osal_event_hdr_t *)osal_msg_allocate( length + sizeof(osal_event_hdr_t) );
    365                  if ( msg_ptr )
    366                  {
    367                    msg_ptr->event = SPI_INCOMING_ZAPP_DATA;
    368                    msg_ptr->status = length;
    369          
    370                    /* Read the data of Rx buffer */
    371                    HalUARTRead( SPI_MGR_DEFAULT_PORT, (uint8 *)(msg_ptr + 1), length );
    372          
    373                    /* Send the raw data to application...or where ever */
    374                    osal_msg_send( App_TaskID, (uint8 *)msg_ptr );
    375                  }
    376                }
    377              }
    378            }
    379          }
    380          
    381          /***************************************************************************************************
    382           * @fn      SPIMgr_ZAppBufferLengthRegister
    383           *
    384           * @brief
    385           *
    386           * @param   maxLen - Max Length that the application wants at a time
    387           *
    388           * @return  None
    389           *
    390           ***************************************************************************************************/
    391          void SPIMgr_ZAppBufferLengthRegister ( uint16 maxLen )
    392          {
    393            /* If the maxLen is larger than the RX buff, something is not right */
    394            if (maxLen <= SPI_MGR_DEFAULT_MAX_RX_BUFF)
    395              SPIMgr_MaxZAppBufLen = maxLen;
    396            else
    397              SPIMgr_MaxZAppBufLen = 1; /* default is 1 byte */
    398          }
    399          
    400          /***************************************************************************************************
    401           * @fn      SPIMgr_AppFlowControl
    402           *
    403           * @brief
    404           *
    405           * @param   status - ready to send or not
    406           *
    407           * @return  None
    408           *
    409           ***************************************************************************************************/
    410          void SPIMgr_AppFlowControl ( bool status )
    411          {
    412          
    413            /* Make sure only update if needed */
    414            if (status != SPIMgr_ZAppRxStatus )
    415            {
    416              SPIMgr_ZAppRxStatus = status;
    417            }
    418          
    419            /* App is ready to read again, ProcessZAppData have to be triggered too */
    420            if (status == SPI_MGR_ZAPP_RX_READY)
    421            {
    422              SPIMgr_ProcessZAppData ( SPI_MGR_DEFAULT_PORT, HAL_UART_RX_TIMEOUT );
    423            }
    424          
    425          }
    426          
    427          #endif //ZAPP
    428          
    429          /***************************************************************************************************
    430          ***************************************************************************************************/

   Maximum stack usage in bytes:

     Function                 ISTACK PSTACK XSTACK
     --------                 ------ ------ ------
     SPIMgr_CalcFCS               0      0     20
     SPIMgr_Init                  3      0     29
       -> HalUARTOpen             4      0     58
     SPIMgr_ProcessZToolData      1      0     11
       -> Hal_UART_RxBufLen       0      0     22
       -> HalUARTRead             0      0     22
       -> osal_msg_allocate       0      0     22
       -> SPIMgr_CalcFCS          0      0     22
       -> osal_msg_send           0      0     22
       -> osal_msg_deallocate     0      0     22
     SPIMgr_RegisterTaskID        2      0      0


   Segment part sizes:

     Function/Label                 Bytes
     --------------                 -----
     App_TaskID                        1
     state                             1
     CMD_Token                         2
     LEN_Token                         1
     FSC_Token                         1
     SPI_Msg                           2
     tempDataLen                       1
     SPIMgr_Init                     117
     ?Subroutine5                      7
     SPIMgr_RegisterTaskID            11
     SPIMgr_CalcFCS                   37
     SPIMgr_ProcessZToolData         398
     ?Subroutine2                     14
     ?Subroutine1                      4
     ?Subroutine3                      7
     ?Subroutine0                      8
     ?Subroutine4                     12
     ??SPIMgr_Init?relay               6
     ??SPIMgr_RegisterTaskID?relay     6
     ??SPIMgr_CalcFCS?relay            6
     ??SPIMgr_ProcessZToolData?relay
                                       6

 
 615 bytes in segment BANKED_CODE
  24 bytes in segment BANK_RELAYS
   9 bytes in segment XDATA_Z
 
 639 bytes of CODE  memory
   9 bytes of XDATA memory

Errors: none
Warnings: none
