##############################################################################
#                                                                            #
# IAR ARM ANSI C/C++ Compiler V4.11A/W32               20/Jul/2004  18:58:52 #
# Copyright 1999-2004 IAR Systems. All rights reserved.                      #
#                                                                            #
#    Cpu mode        =  arm                                                  #
#    Endian          =  little                                               #
#    Stack alignment =  4                                                    #
#    Source file     =  C:\medusa\i2cport.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\i2cport.c       #
#    List file       =  C:\medusa\Debug\List\i2cport.lst                     #
#    Object file     =  C:\medusa\Debug\Obj\i2cport.r79                      #
#                                                                            #
#                                                                            #
##############################################################################

C:\medusa\i2cport.c
      1          #include "archinc.h"
      2          #include "cli.h"
      3          #include "clichar.h"
      4          #include "i2cmaster.h"
      5          #include "i2cport.h"
      6          
      7          #include <stdio.h>
      8          #include <stdlib.h>
      9          
     10          #if (defined(CONFIG_INCLUDE_LPC210X_I2C) && defined(CONFIG_INCLUDE_I2C_PORT))
     11          
     12          static unsigned char slaveAddr[CONFIG_I2CPORT_MAX_PORTS] = {0x40, 0x48};
     13          
     14          static unsigned short outputShadow[CONFIG_I2CPORT_MAX_PORTS];
     15          
     16          static unsigned char busWriteData[4];
     17          
     18          static int i2cportHandler(int argc, char * argv[], int flags);
     19          
     20          static int writeConfig(int portId, unsigned char offset, unsigned short writeData)
     21          {
     22            busWriteData[0] = offset;
     23            busWriteData[1] = (unsigned char)(writeData & 0xff);
     24            busWriteData[2] = (unsigned char)((writeData >> 8) & 0xff);
     25          
     26            return i2cmasterSendMult(slaveAddr[portId], busWriteData, 3, true); 
     27          }
     28          
     29          static int readConfig(int portId, unsigned char offset, unsigned short * pReadData)
     30          {
     31            int retStat;
     32            unsigned char dummyAddr;
     33            unsigned char tmpByte;
     34          
     35            if (pReadData == NULL)
     36              return -1;
     37          
     38            // first write the offset, no stop bit
     39            retStat = i2cmasterSendOne(slaveAddr[portId], offset, false);
     40          
     41            // receive 2 bytes
     42            if (retStat != -1) {
     43              retStat = i2cmasterReceive(slaveAddr[portId], 2, true);
     44              }
     45          
     46            // read the bytes
     47            if (retStat != -1) {
     48              retStat = i2cmasterGet(&dummyAddr, &tmpByte);
     49              }
     50          
     51            *pReadData = (unsigned short)(tmpByte & 0x00ff);
     52          
     53            if (retStat != -1) {
     54              retStat = i2cmasterGet(&dummyAddr, &tmpByte);
     55              }
     56          
     57            *pReadData |= ((tmpByte << 8) & 0xff00);
     58          
     59            return retStat;
     60          }
     61          
     62          int i2cportInit(void)
     63          {
     64            int retVal = 0;
     65            int i;
     66          
     67            cliRegisterCommand("i2cport", i2cportHandler, "i2cport [in] [out <16-bit hex value>]");
     68          
     69            for(i=0;i<CONFIG_I2CPORT_MAX_PORTS;i++)
     70              outputShadow[i] = (unsigned short)0;
     71          
     72            for(i=0;((retVal == 0) && (i<CONFIG_I2CPORT_MAX_PORTS));i++)
     73              retVal = i2cmasterProbe(slaveAddr[i]);
     74          
     75            return retVal;
     76          }
     77          
     78          int i2cportDirConfig(int portId, unsigned short iobitMask)
     79          {
     80            return writeConfig(portId, 6, iobitMask);
     81          }
     82          
     83          int i2cportAssign(int portId, unsigned short iobitMask)
     84          {
     85            outputShadow[portId] = iobitMask;
     86            return writeConfig(portId, 2, iobitMask);
     87          }
     88          
     89          int i2cportSet(int portId, unsigned short iobitMask)
     90          {
     91            unsigned short tmpReg = outputShadow[portId];
     92            tmpReg |= iobitMask;
     93            outputShadow[portId] = tmpReg;
     94            return writeConfig(portId, 2, tmpReg);
     95          }
     96          
     97          int i2cportClear(int portId, unsigned short iobitMask)
     98          {
     99            unsigned short tmpReg = outputShadow[portId];
    100            tmpReg &= ~iobitMask;
    101            outputShadow[portId] = tmpReg;
    102            return writeConfig(portId, 2, tmpReg);
    103          }
    104          
    105          int i2cportGet(int portId, unsigned short * pIobitMask)
    106          {
    107            return readConfig(portId, 0, pIobitMask);
    108          }
    109          
    110          static int i2cportHandler(int argc, char * argv[], int flags)
    111          {
    112            int retVal = -1;
    113            int bufLen;
    114            int portNum;
                       ^
Warning[Pe177]: variable "portNum" was declared but never referenced
    115            unsigned short portData;
    116            char * pOutBuf;
    117          
    118            pOutBuf = clicharGetOutputBuffer(&bufLen);
    119          
    120            if (argc < 2)
    121              return -1;
    122          
    123            // TODO: put this in a while loop to process a list of op/data pairs
    124          
    125            // write gets two parameters [index] [data], read gets one
    126            switch(*argv[1]) {
    127              case 'i':
    128                // input
    129                if (i2cportGet(0, &portData) == 0) {
    130                  sprintf(pOutBuf, "i2cport: port 0 [%04X]\n", portData);
    131                  retVal = 0;
    132                  }
    133                else {
    134                  sprintf(pOutBuf, "i2cport: error reading port 0 addr[%02X]\n", slaveAddr[0]);
    135                  }
    136                clicharSendOutputBuffer(pOutBuf, bufLen);
    137                break;
    138              case 'o':
    139                // output [mask]
    140                portData = (unsigned short)strtol(argv[2], NULL, 16);
    141                
    142                if (i2cportAssign(1, portData) == 0) {
    143                  sprintf(pOutBuf, "i2cport: port 1 <-- [%04X]\n", portData);
    144                  retVal = 0;
    145                  }
    146                else {
    147                  sprintf(pOutBuf, "i2cport: error writing port 1 addr[%02X]\n", slaveAddr[1]);
    148                  }
    149                clicharSendOutputBuffer(pOutBuf, bufLen);
    150                break;
    151              default:
    152                break;
    153              }
    154              
    155            return retVal;
    156          }
    157          
    158          
    159          
    160          #endif /* (defined(CONFIG_INCLUDE_LPC210X_I2C) && defined(CONFIG_INCLUDE_I2C_PORT)) */
    161          

   Maximum stack usage in bytes:

     Function         CSTACK
     --------         ------
     i2cportAssign       12
     i2cportClear        16
     i2cportDirConfig    12
     i2cportGet          12
     i2cportHandler      36
     i2cportInit         12
     i2cportSet          16
     readConfig          24
     writeConfig         16


   Segment part sizes:

     Function/Label                 Bytes
     --------------                 -----
     slaveAddr                         2
     outputShadow                      4
     busWriteData                      4
     writeConfig                      88
     readConfig                      188
     i2cportInit                     140
     i2cportDirConfig                 40
     i2cportAssign                    56
     i2cportSet                       80
     i2cportClear                     96
     i2cportGet                       32
     i2cportHandler                  324
     ??DataTable9                      4
     ??DataTable11                     4
     ?<Initializer for slaveAddr>      2
     ?<Constant "i2cport">             8
     ?<Constant "i2cport [in] [out <16...">
                                      40
     ?<Constant "i2cport: port 0 [%04X]\n">
                                      24
     ?<Constant "i2cport: error readin...">
                                      44
     ?<Constant "i2cport: port 1 <-- [...">
                                      28
     ?<Constant "i2cport: error writin...">
                                      44
      Others                         144

 
 1 172 bytes in segment CODE
   188 bytes in segment DATA_C
     2 bytes in segment DATA_I
     2 bytes in segment DATA_ID
     8 bytes in segment DATA_Z
    24 bytes in segment INITTAB
 
 1 052 bytes of CODE  memory (+ 144 bytes shared)
   190 bytes of CONST memory
    10 bytes of DATA  memory

Errors: none
Warnings: 1
