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

C:\medusa\i2cswitch.c
      1          #include "archinc.h"
      2          #include "cli.h"
      3          #include "i2cmaster.h"
      4          #include "i2cswitch.h"
      5          
      6          #include <stdio.h>
      7          #include <stdlib.h>
      8          
      9          #if (defined(CONFIG_INCLUDE_LPC210X_I2C) && defined(CONFIG_INCLUDE_I2C_SWITCH))
     10          
     11          static unsigned char slaveAddr;
     12          
     13          static int i2cbusHandler(int argc, char * argv[], int flags);
     14          
     15          int i2cswitchInit(unsigned char switchAddr)
     16          {
     17            cliRegisterCommand("i2cbus",i2cbusHandler,"i2cbus [d(isable all)] [bus number 0-3 to enable]");
     18            slaveAddr = switchAddr;
     19            return i2cmasterProbe(slaveAddr);
     20          }
     21          
     22          int i2cswitchSetBus(int bus)
     23          {
     24            unsigned char writeMask;
     25          
     26            if ((bus < 0) || (bus > 3))
     27              return -1;
     28          
     29            writeMask = (0x1 << bus);
     30          
     31            return i2cmasterSendOne(slaveAddr, writeMask, true);
     32          }
     33          
     34          int i2cswitchDisable(void)
     35          {
     36            return i2cmasterSendOne(slaveAddr, 0x00, true);
     37          }
     38          
     39          
     40          static int i2cbusHandler(int argc, char * argv[], int flags)
     41          {
     42            int retVal = -1;
     43            int busEntry;
     44            int bufLen;
     45            char * pOutBuf;
     46          
     47            pOutBuf = clicharGetOutputBuffer(&bufLen);
     48            
     49            if (argc < 2)
     50              return -1;
     51          
     52            if (*argv[1] == 'd') {
     53              if (i2cswitchDisable() == 0)
     54                sprintf(pOutBuf, "i2cbus: bus switch disabled\n");
     55              else
     56                sprintf(pOutBuf, "i2cbus: error disabling bus switch\n");
     57              }
     58            else {
     59              
     60              busEntry = atoi((const char *)argv[1]);
     61          
     62              if ((busEntry < 0) || (busEntry > 3))
     63                return -1;
     64          
     65              if (i2cswitchSetBus(busEntry) == 0)
     66                sprintf(pOutBuf, "i2cbus: bus set to [%d]\n", busEntry);
     67              else
     68                sprintf(pOutBuf, "i2cbus: error setting bus to [%d]\n", busEntry);
     69          
     70               retVal = 0;
     71              }
     72            
     73            clicharSendOutputBuffer(pOutBuf, bufLen);
     74              
     75            return retVal;
     76          }
     77          
     78          #endif /* (defined(CONFIG_INCLUDE_LPC210X_I2C) && defined(CONFIG_INCLUDE_I2C_SWITCH)) */

   Maximum stack usage in bytes:

     Function         CSTACK
     --------         ------
     atoi                 8
     i2cbusHandler       32
     i2cswitchDisable     4
     i2cswitchInit        8
     i2cswitchSetBus     12


   Segment part sizes:

     Function/Label                 Bytes
     --------------                 -----
     atoi                             28
     slaveAddr                         1
     i2cswitchInit                    60
     i2cswitchSetBus                  76
     i2cswitchDisable                 28
     i2cbusHandler                   252
     ??DataTable3                      4
     ?<Constant "i2cbus">              8
     ?<Constant "i2cbus [d(isable all)...">
                                      52
     ?<Constant "i2cbus: bus switch di...">
                                      32
     ?<Constant "i2cbus: error disabli...">
                                      36
     ?<Constant "i2cbus: bus set to [%d]\n">
                                      28
     ?<Constant "i2cbus: error setting...">
                                      36
      Others                         108

 
 544 bytes in segment CODE
 192 bytes in segment DATA_C
   1 byte  in segment DATA_Z
  12 bytes in segment INITTAB
 
 420 bytes of CODE  memory (+ 136 bytes shared)
 192 bytes of CONST memory
   1 byte  of DATA  memory

Errors: none
Warnings: none
