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

C:\medusa\sfp.c
      1          #include "archinc.h"
      2          #include "cli.h"
      3          #include "clichar.h"
      4          #include "i2cmaster.h"
      5          #include "i2cport.h"
      6          #include "i2cswitch.h"
      7          #include "sfp.h"
      8          
      9          #include <stdio.h>
     10          #include <stdlib.h>
     11          
     12          boolean modulePresent[4];
     13          
     14          #if (defined(CONFIG_INCLUDE_LPC210X_I2C) && defined(CONFIG_INCLUDE_I2C_SFP))
     15          
     16          // SFP diagnostic address is hardwired to 0xa2
     17          
     18          // unsigned char sfpSlaveAddr = 0xa2;
     19          
     20          static int sfpHandler(int argc, char * argv[], int flags);
     21          
     22          int sfpInit(void)
     23          {
     24            int retVal = -1;
     25            int i;
     26          
     27            for(i=0;i<3;i++)
     28                modulePresent[i] = ((sfpProbe(i) == 0) ? true : false);
     29          
     30            retVal = cliRegisterCommand("sfp", sfpHandler, "sfp [probe | (-)enable | (-)txenable] [bus number 0-3]");
     31          
     32            return retVal;
     33          }
     34          
     35          int sfpModulePresent(int bus, boolean *pModulePresent)
     36          {
     37            if ((bus < 0) || (bus > 3))
     38              return -1;
     39          
     40            *pModulePresent = modulePresent[bus];
     41            return 0;
     42          }
     43          
     44          int sfpProbe(int bus)
     45          {
     46            int retVal;
     47            
     48            // setup the bus mux
     49            retVal = i2cswitchSetBus(bus);
     50          
     51            if (retVal == -1)
     52              return -1;
     53          
     54            retVal = i2cmasterProbe(0xa2);
     55          
     56            i2cswitchDisable();
     57          
     58            return retVal;
     59          }
     60          
     61          int sfpTransmitDisable(int bus, boolean txDisable)
     62          {
     63            unsigned short txEnaMask;
     64            int retVal;
     65          
     66            // TODO: do some sort of checking on channel num
     67            txEnaMask = (unsigned short)(1 << (bus+4));
     68          
     69            if (txDisable == true) 
     70              retVal = i2cportSet(1, txEnaMask);
     71            else
     72              retVal = i2cportClear(1, txEnaMask);
     73          
     74            return retVal;
     75          }
     76          
     77          int sfpEnable(int bus, boolean sfpEnable)
     78          {
     79            unsigned short sfpEnaMask;
     80            int retVal;
     81          
     82            // TODO: do some sort of checking on channel num
     83            sfpEnaMask = (unsigned short)(1 << bus);
     84          
     85            if (sfpEnable == true) 
     86              retVal = i2cportSet(1, sfpEnaMask);
     87            else
     88              retVal = i2cportClear(1, sfpEnaMask);
     89          
     90            return retVal;
     91          
     92          }
     93          
     94          static int sfpHandler(int myArgc, char * myArgv[], int flags)
     95          {
     96            int retVal = -1;
     97          
     98          
     99            int probeBus;
    100            int bufLen;
    101            char * pOutBuf;
    102            boolean doDisable;
    103            char * pSprintfFormat;
    104            char * pCh;
    105          
    106            pOutBuf = clicharGetOutputBuffer(&bufLen);
    107          
    108            if (myArgc < 3)
    109              return -1;
    110          
    111            probeBus = atoi(myArgv[2]);
    112          
    113            if ((probeBus < 0) || (probeBus > 3))
    114              return -1;
    115          
    116            doDisable = true;
    117            pCh = myArgv[1];
    118            if (*pCh == '-') {
    119              doDisable = false;
    120              pCh++;
    121              }
    122          
    123            switch(*pCh) {
    124              case 'e':
    125              case 'E':
    126                if ((retVal = sfpEnable(probeBus, doDisable)) == 0) {
    127                  if (doDisable == true) {
    128                    pSprintfFormat = "enable: channel [%d] enabled\n";
    129                    }
    130                  else {
    131                    pSprintfFormat = "enable: channel [%d] disabled\n";
    132                    }
    133                  sprintf(pOutBuf, pSprintfFormat, probeBus);
    134                  }
    135                else {
    136                  sprintf(pOutBuf, "enable: channel [%d] not found\n", probeBus);
    137                  }
    138                clicharSendOutputBuffer(pOutBuf, bufLen);
    139                break;
    140              case 'p':
    141              case 'P': 
    142                if ((retVal = sfpProbe(probeBus)) == 0) {
    143                  sprintf(pOutBuf, "probe: found SFP on bus [%d]\n", probeBus);
    144                  }
    145                else {
    146                  sprintf(pOutBuf, "probe: error SFP not found on bus [%d]\n", probeBus);
    147                  }
    148                clicharSendOutputBuffer(pOutBuf, bufLen);
    149                break;
    150              case 't':
    151              case 'T':
    152                if ((retVal = sfpTransmitDisable(probeBus, doDisable)) == 0) {
    153                  if (doDisable == true) {
    154                    pSprintfFormat = "txdisable: channel [%d] tx disabled\n";
    155                    }
    156                  else {
    157                    pSprintfFormat = "txdisable: channel [%d] tx enabled\n";
    158                    }
    159                  sprintf(pOutBuf, pSprintfFormat, probeBus);
    160                  }
    161                else {
    162                  sprintf(pOutBuf, "txenable: channel [%d] not found\n", probeBus);
    163                  }
    164                clicharSendOutputBuffer(pOutBuf, bufLen);
    165              default:
    166                break;
    167              }
    168          
    169          
    170            return retVal;
    171          
    172          }
    173          
    174          #endif /* (defined(CONFIG_INCLUDE_LPC210X_I2C) && defined(CONFIG_INCLUDE_I2C_SFP)) */

   Maximum stack usage in bytes:

     Function           CSTACK
     --------           ------
     atoi                   8
     sfpEnable             20
     sfpHandler            44
     sfpInit               12
     sfpModulePresent       0
     sfpProbe              12
     sfpTransmitDisable    20


   Segment part sizes:

     Function/Label                 Bytes
     --------------                 -----
     atoi                             28
     modulePresent                    16
     sfpInit                         120
     sfpModulePresent                 56
     sfpProbe                         60
     sfpTransmitDisable              100
     sfpEnable                        96
     sfpHandler                      528
     ??DataTable1                      4
     ?<Constant "sfp">                 4
     ?<Constant "sfp [probe | (-)enabl...">
                                      56
     ?<Constant "enable: channel [%d] ...">
                                      32
     ?<Constant "enable: channel [%d] ...">_1
                                      32
     ?<Constant "enable: channel [%d] ...">_2
                                      32
     ?<Constant "probe: found SFP on b...">
                                      32
     ?<Constant "probe: error SFP not ...">
                                      40
     ?<Constant "txdisable: channel [%...">
                                      40
     ?<Constant "txdisable: channel [%...">_1
                                      36
     ?<Constant "txenable: channel [%d...">
                                      36
      Others                         144

 
 1 124 bytes in segment CODE
   340 bytes in segment DATA_C
    16 bytes in segment DATA_Z
    12 bytes in segment INITTAB
 
 964 bytes of CODE  memory (+ 172 bytes shared)
 340 bytes of CONST memory
  16 bytes of DATA  memory

Errors: none
Warnings: none
