##############################################################################
#                                                                            #
# IAR ARM ANSI C/C++ Compiler V4.11A/W32               20/Jul/2004  18:58:47 #
# Copyright 1999-2004 IAR Systems. All rights reserved.                      #
#                                                                            #
#    Cpu mode        =  arm                                                  #
#    Endian          =  little                                               #
#    Stack alignment =  4                                                    #
#    Source file     =  C:\medusa\spiprot.c                                  #
#    Command line    =  -I "C:\Program Files\IAR Systems\Embedded Workbench  #
#                       4.0\ARM\INC\" -lc C:\medusa\Debug\List\ -la          #
#                       C:\medusa\Debug\List\ -o C:\medusa\Debug\Obj\ -s2    #
#                       --no_cse --no_unroll --no_inline --no_code_motion    #
#                       --no_tbaa --no_clustering --no_scheduling --debug    #
#                       --cpu_mode arm --endian little --cpu ARM7TDMI-S      #
#                       --stack_align 4 -e --fpu None                        #
#                       "-D_DLIB_CONFIG_FILE=C:\Program Files\IAR            #
#                       Systems\Embedded Workbench                           #
#                       4.0\ARM\LIB\dl4tpannl8n.h" C:\medusa\spiprot.c       #
#    List file       =  C:\medusa\Debug\List\spiprot.lst                     #
#    Object file     =  C:\medusa\Debug\Obj\spiprot.r79                      #
#                                                                            #
#                                                                            #
##############################################################################

C:\medusa\spiprot.c
      1          #include "archinc.h"
      2          #include "spiprot.h"
      3          
      4          #if 0
      5          
      6          typedef enum { expectSync, expectFrameType, expectParamCount, expectParamTag, espectParamData, expectTerm } receiveState;
      7          
      8          // registered handlers from upper level
      9          spiprotFrameValidatorType frameValidator;
     10          
     11          static receiveState rcvState;
     12          static int unexpectedFrameTypeCount;
     13          static int currentParamCount;
     14          static int currentFrameType;
     15          
     16          #define CONFIG_SPIPROT_NUM_RECV_FRAMES (4)
     17          #define CONFIG_SPIPROT_RECV_FRAME_SIZE (128)
     18          
     19          static char receivedFrames[CONFIG_SPIPROT_NUM_RECV_FRAMES][CONFIG_SPIPROT_RECV_FRAME_SIZE];
     20          
     21          // bit = frame number, 0 = frame free, 1 = frame in use
     22          static int receivedFrameStatus;
     23          
     24          int spiprotInit(void)
     25          {
     26            rcvState = expectSync;
     27            unexpectedFrameTypeCount = 0;
     28          
     29            /*
     30             * Since we are a slave, load a sync character right away. This character will get sent back to the 
     31             * master while we are (hopefully) receiving the sync character from the master. Since we have configured
     32             * the interface as a slave, it should not begin a transaction
     33             */
     34          
     35            spiPut(SPIPROT_SYNC_CHAR);  
     36            return 0;
     37          }
     38          
     39          // release a message frame sent to the upper layer
     40          int spiprotReleaseFrame(int frameNumber)
     41          {
     42          }
     43          
     44          // register callbacks in the upper level stack
     45          int spiprotRegisterProtocol(spiprotFrameValidatorType myFrameValidator)
     46          {
     47            frameValidator = myFrameValidator;
     48            return 0;
     49          }
     50          
     51          static int bytesExpected = 0;
     52          
     53          #ifdef CONFIG_TOOLCHAIN_IAR
     54          #pragma inline
     55          #endif
     56          static void INLINE_KEYWORD updateReceiveState(char receivedData)
     57          {
     58            if (rcvState == expectSync) {
     59              // when we are expecting sync, throw away all chars until sync is received
     60              if (receivedData == SPIPROT_SYNC_CHAR) {
     61                rcvState = expectFrameType;
     62                }
     63              }
     64            else if (rcvState == expectFrameType) {
     65              // call frame type validator
     66              if (frameValidator != NULL) {
     67                switch((*frameValidator)(receivedData)) {
     68                  case SPIPROT_FRAME_TYPE_INVALID:
     69                    // reset the receive state machine
     70                    rcvState = expectSync;
     71                    break;
     72                  case SPIPROT_FRAME_TYPE_VALID_NO_PARAM_COUNT:
     73                    rcvState = expectTerm;
     74                    break;
     75                  case SPIPROT_FRAME_TYPE_VALID:
     76                    rcvState = expectParamCount;
     77                    break;
     78                  default:
     79                    break;
     80                  } // switch
     81                } // if (validator)
     82              }
     83            else if (rcvState == expectParamCount) {
     84              // get 
     85              currentParamCount = (int)receivedData;
     86              if (currentParamCount == 0) {
     87                rcvState = expectTerm;
     88                }
     89              else {
     90                rcvState = expectParamTag;
     91                }
     92              }
     93            else if (rcvState == expectParamTag) {
     94              if (sizeofParam != NULL) {
     95                }
     96              }
     97            else if (rcvState == expectParamData) {
     98              if (bytesExpected == 0) {
     99                if (--currentParamCount <= 0) {
    100                  rcvState = expectTerm;
    101                  }
    102                else {
    103                  rcvState = expectParamTag;
    104                  }
    105                }
    106              }    
    107            else if (rcvState == expectTerm) {
    108              if (receivedChar == SPIPROT_TERMINATOR) {
    109                // mark the frame as complete and pass to the upper layer
    110                // get another frame
    111                rcvState = expectSync;
    112                }
    113              else {
    114                // buffer the character in the current frame
    115                // TODO: update frame data checksum
    116                }
    117              }
    118            else {
    119              // unknown state -- toss packet and goto expectSync
    120              rcvState = expectSync;
    121              }
    122            }
    123          
    124          // 'Simple' in this case means no parameters
    125          
    126          int spiprotSendSimpleCommand(unsigned char cmdByte)
    127          {
    128            spiPut(SPIPROT_SYNC);
    129            spiPut(cmdByte);
    130            spiPut(SPIPROT_TERMINATOR);
    131            return 0;
    132          }
    133          
    134          void spiprotEventHandler(void)
    135          {
    136            char ch;
    137          
    138          #ifdef CONFIG_ARCH_MSP430
    139            while ((retVal = usart1RxOne(&ch)) != -1)
    140              spiprotProcessByte(ch);
    141          #endif /* CONFIG_ARCH_MSP430 */
    142          
    143          #ifdef CONFIG_ARCH_LPC2XXX
    144            while ((retVal = spiGet(&ch)) != -1)
    145              spiprotProcessByte(ch);
    146          #endif /* CONFIG_ARCH_LPC2XXX */
    147          }
    148          
    149          #ifdef CONFIG_TOOLCHAIN_IAR
    150          #pragma inline
    151          #endif
    152          int INLINE_KEYWORD spiprotProcessByte(char nextByte)
    153          {
    154            updateReceiveState(nextByte);
    155            return 0;
    156          }
    157          
    158          #endif
    159          
    160          


   Segment part sizes:

     Function/Label Bytes
     -------------- -----

 
 
 0 bytes of memory

Errors: none
Warnings: none
