##############################################################################
#                                                                            #
# 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\zl_util.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\zl_util.c       #
#    List file       =  C:\medusa\Debug\List\zl_util.lst                     #
#    Object file     =  C:\medusa\Debug\Obj\zl_util.r79                      #
#                                                                            #
#                                                                            #
##############################################################################

C:\medusa\zl_util.c
      1          #include "archinc.h"
      2          #include "cli.h"
      3          #include "strutil.h"
      4          #include "zarlink.h"
      5          
      6          #ifdef CONFIG_INCLUDE_ZARLINK
      7          
      8          #include <stdio.h>
      9          #include <stdlib.h>
     10          
     11          static unsigned char cpuMacAddr[6];
     12          
     13          
     14          unsigned short byteSwap16(unsigned short swapData16)
     15          {
     16            unsigned char temp;
     17            union {
     18              unsigned short uint16;
     19              unsigned char uint8[2];
     20              } u;
     21          
     22            u.uint16 = swapData16;
     23          
     24            temp = u.uint8[0];
     25            u.uint8[0] = u.uint8[1];
     26            u.uint8[1] = temp;
     27          
     28            return u.uint16;
     29          }
     30          
     31          void swapMac(unsigned char * pMac)
     32          {
     33            int i;
     34            unsigned char temp;
     35          
     36            if (pMac == NULL)
     37              return;
     38          
     39            for(i=0;i<3;i++) {
     40              temp = pMac[i];
     41              pMac[i] = pMac[(5-i)];
     42              pMac[(5-i)] = temp;
     43              }
     44            
     45          }
     46          
     47          static char * foo[4];
     48          
     49          // parses a 'dotted quad' v4 IP address (i.e. "192.168.0.1") into 4 bytes
     50          int parseDottedQuadV4(char * pDottedQuad, unsigned char * pIpAddr)
     51          {
     52            int count = 0;
     53          
     54            if ((pDottedQuad == NULL) || (pIpAddr == NULL))
     55              return -1;
     56          
     57            foo[count++] = pDottedQuad;
     58          
     59            while((count < 4) && (*pDottedQuad != '\0')) {
     60              if (*pDottedQuad == '.') {
     61                *pDottedQuad++ = '\0';
     62                foo[count++] = pDottedQuad;
     63                }
     64              else {
     65                pDottedQuad++;
     66                }
     67              }
     68          
     69            // did we find three dots?
     70            if (count < 4)
     71              return -1;
     72          
     73            for(count = 0; (count < 5); count++) {
     74              pIpAddr[count] = (unsigned char)strtol(foo[count], (char **)NULL, 10);
     75              }
     76            
     77            return 0;
     78          }
     79          
     80          static int zarlinkHandler(int argc, char * argv[], int flags)
     81          {
     82            int retVal = -1;
     83            int regIndex;
                       ^
Warning[Pe177]: variable "regIndex" was declared but never referenced
     84            unsigned short zlData;
     85            unsigned short zlIndex;
     86            unsigned char blah;
     87            char * pOutBuf;
     88            int bufLen;
     89          
     90            pOutBuf = clicharGetOutputBuffer(&bufLen);
     91            
     92            // TODO: put this in a while loop to process a list of op/data pairs
     93          
     94            // write gets two parameters [index] [data], read gets one
     95            SKIPDASH(argv[1]);
     96          
     97            switch(*argv[1]) {
     98              case 'q':
     99              case 'Q':
    100                // read (query) [index] reduced output for parsing
    101                zlIndex = (unsigned short)strtol(argv[2], NULL, 16);
    102                blah = (unsigned char)zarlinkIndexedRead(zlIndex);
    103                sprintf(pOutBuf, "0x%02x\n", blah);
    104                clicharSendOutputBuffer(pOutBuf, bufLen);
    105                retVal = 0;
    106                break;
    107              case 'r':
    108              case 'R':
    109                // read [index]
    110                zlIndex = (unsigned short)strtol(argv[2], NULL, 16);
    111                blah = (unsigned char)zarlinkIndexedRead(zlIndex);
    112                sprintf(pOutBuf, "zl reg[%04x] = %02x\n", zlIndex, blah);
    113                clicharSendOutputBuffer(pOutBuf, bufLen);
    114                retVal = 0;
    115                break;
    116              case 's':
    117              case 'S':
    118                // get status
    119                sprintf(pOutBuf, "zl status[%02x]\r\n", zarlinkStatusRead());
    120                clicharSendOutputBuffer(pOutBuf, bufLen);
    121                retVal = 0;
    122                break;
    123              case 'w':
    124              case 'W':
    125                // write [index] [data]
    126                zlIndex = (unsigned short)strtol(argv[2], NULL, 16);
    127                zlData = (unsigned short)strtol(argv[3], NULL, 16);
    128                blah = (unsigned char)(zlData & 0x00ff);
    129                zarlinkIndexedWrite(zlIndex, blah);
    130                sprintf(pOutBuf, "zl reg[%04x] <-- %02x\n", zlIndex, blah);
    131                clicharSendOutputBuffer(pOutBuf, bufLen);
    132                retVal = 0;
    133                break;
    134              default:
    135                break;
    136              }
    137              
    138            return retVal;
    139          }
    140          
    141          static unsigned char qStats[10];
    142          
    143          static char yesBlar[] = {'F', 'D', 'S', 'D', 'A', '.', '.', 'M'};
    144          static char noBlar[]  = {'f', 'd', 's', 'd', 'a', '.', '.', 'm'};
    145          
    146          static int quickStatHandler(int argc, char *argv[], int flags)
    147          {
    148            int bufLen;
    149            char * pOutBuf, * foo;
    150            int port;
                       ^
Warning[Pe177]: variable "port" was declared but never referenced
    151            volatile int i;
    152            volatile int j;
    153          
    154            pOutBuf = clicharGetOutputBuffer(&bufLen);
    155          
    156            sprintf(pOutBuf, "%s: Flow Ctrl[f]  FDX[d]  Fast[s]  Link Down[d]  Autoneg[a]  Module[m]\r\n",argv[0]);
    157            clicharSendOutputBuffer(pOutBuf, bufLen);
    158          
    159            for(i=0;i<10;i++) {
    160              zarlinkIndexedWrite(0xf03, (unsigned char)i);
    161              qStats[i] = zarlinkIndexedRead(0xf04);
    162              }
    163          
    164            for(i=0;i<10;i++) {
    165              if (i == 8)
    166                sprintf(pOutBuf, "_cpu[%02x]  ", i);
    167              else if (i == 9) 
    168                sprintf(pOutBuf, "mmac[%02x]  ", i);
    169              else
    170                sprintf(pOutBuf, "port[%02x]  ", i);
    171          
    172              foo = pOutBuf;
    173              while(*foo != ' ') {
    174                foo++;
    175                }
    176              foo += 2;
    177              for(j=0;j<8;j++) {
    178                if (((qStats[i] >> j) & 0x01) != 0) {
    179                  *foo++ = yesBlar[j];
    180                  }
    181                else {
    182                  *foo++ = noBlar[j];
    183                  }
    184                }
    185              *foo++ = '\r'; *foo++ = '\n'; *foo = '\0';
    186              clicharSendOutputBuffer(pOutBuf, bufLen);
    187              }
    188          
    189            return 0;
    190          }
    191          
    192          int zarlinkCpuMacAddrSet(unsigned char *setMacAddr)
    193          {
    194            int i;
    195          
    196            if (setMacAddr == NULL)
    197              return -1;
    198          
    199            for(i=0;i<6;i++) {
    200              zarlinkIndexedWrite( (0x300+i), setMacAddr[(5-i)] );
    201              }
    202          
    203            return 0;
    204          }
    205          
    206          int zarlinkCpuMacAddrGet(unsigned char *getMacAddr)
    207          {
    208            int i;
    209          
    210            if (getMacAddr == NULL)
    211              return -1;
    212          
    213            for(i=0;i<6;i++)
    214              getMacAddr[(5-i)] = zarlinkIndexedRead(0x300+i);
    215          
    216            return 0;
    217          }
    218          
    219          static int setmacHandler(int argc, char *argv[], int flags)
    220          {
    221            int bufLen;
    222            char * pOutBuf;
    223          
    224            pOutBuf = clicharGetOutputBuffer(&bufLen);
    225          
    226            if (argc == 4) {
    227              cpuMacAddr[5] = 0x00;
    228              cpuMacAddr[4] = 0x0c;
    229              cpuMacAddr[3] = 0x6a;
    230              cpuMacAddr[2] = (unsigned char)strtol(argv[1], (char **)NULL, 16);
    231              cpuMacAddr[1] = (unsigned char)strtol(argv[2], (char **)NULL, 16);
    232              cpuMacAddr[0]  = (unsigned char)strtol(argv[3], (char **)NULL, 16);
    233              sprintf(pOutBuf, "%s: setting cpu MAC address to %02x:%02x:%02x:%02x:%02x:%02x\r\n",
    234                argv[0], cpuMacAddr[5], cpuMacAddr[4], cpuMacAddr[3], cpuMacAddr[2], cpuMacAddr[1], cpuMacAddr[0]);
    235              zarlinkCpuMacAddrSet(cpuMacAddr);
    236              }
    237            else if (argc == 1) {
    238              zarlinkCpuMacAddrGet(cpuMacAddr);
    239              sprintf(pOutBuf, "%s: cpu MAC address is %02x:%02x:%02x:%02x:%02x:%02x\r\n",
    240                argv[0], cpuMacAddr[5], cpuMacAddr[4], cpuMacAddr[3], cpuMacAddr[2], cpuMacAddr[1], cpuMacAddr[0]);
    241              }
    242            else {
    243              return -1;
    244              }
    245          
    246            clicharSendOutputBuffer(pOutBuf, bufLen);
    247          
    248            return 0;
    249          }
    250          
    251          static int pupHandler(int argc, char *argv[], int flags)
    252          {
    253            int bufLen;
    254            char * pOutBuf;
    255            unsigned char port;
    256          
    257            if (argc < 2)
    258              return -1;
    259          
    260            port = (unsigned char)strtol(argv[1], (char **)NULL, 16);
    261            port &= 0x0f;
    262          
    263            pOutBuf = clicharGetOutputBuffer(&bufLen);
    264          
    265            sprintf(pOutBuf, "%s: forcing port [%02x] up at 100MBps/FDX\r\n",
    266              argv[0], port);
    267          
    268            clicharSendOutputBuffer(pOutBuf, bufLen);
    269          
    270            zarlinkIndexedWrite((port*2),0xd8);
    271          
    272            return 0;
    273          }
    274          
    275          static int pdownHandler(int argc, char *argv[], int flags)
    276          {
    277            int bufLen;
    278            char * pOutBuf;
    279            unsigned char port;
    280          
    281            if (argc < 2)
    282              return -1;
    283          
    284            port = (unsigned char)strtol(argv[1], (char **)NULL, 16);
    285            port &= 0x0f;
    286          
    287            pOutBuf = clicharGetOutputBuffer(&bufLen);
    288          
    289            sprintf(pOutBuf, "%s: forcing port [%02x] down\r\n",
    290              argv[0], port);
    291          
    292            clicharSendOutputBuffer(pOutBuf, bufLen);
    293          
    294            zarlinkIndexedWrite((port*2),0xd0);
    295          
    296            return 0;
    297          }
    298          
    299          
    300          static unsigned char pdqTestArray[4];
    301          
    302          static int pdqTestHandler(int argc, char * argv[], int flags)
    303          {
    304            int retVal = -1;
    305            int regIndex;
                       ^
Warning[Pe177]: variable "regIndex" was declared but never referenced
    306            unsigned short zlData;
                                  ^
Warning[Pe177]: variable "zlData" was declared but never referenced
    307            unsigned short zlIndex;
                                  ^
Warning[Pe177]: variable "zlIndex" was declared but never referenced
    308            unsigned char blah;
                                 ^
Warning[Pe177]: variable "blah" was declared but never referenced

        if (((qStats[i] >> j) & 0x01) != 0) {
        ^
"C:\medusa\zl_util.c",178  Warning[Pa082]: undefined behavior: the order of
          volatile accesses is undefined in this statement
    309            char * pOutBuf;
    310            int bufLen;
    311          
    312            if (argc != 2) {
    313              return -1;
    314              }
    315          
    316            pOutBuf = clicharGetOutputBuffer(&bufLen);
    317          
    318            if (parseDottedQuadV4(argv[1], pdqTestArray) == 0) {
    319              sprintf(pOutBuf, "%s: IP Addr is [%02x] [%02x] [%02x] [%02x]\r\n",
    320                argv[0], pdqTestArray[0], pdqTestArray[1], pdqTestArray[2], pdqTestArray[3]);
    321              clicharSendOutputBuffer(pOutBuf, bufLen);
    322              retVal = 0;
    323              }
    324            else {
    325              retVal = -2;
    326              }
    327          
    328            return retVal;
    329          }
    330          
    331          int zarlinkUtilInit(void)
    332          { 
    333            cliRegisterCommand("zl", zarlinkHandler, "zl [read <index>] [write <index> <hex data>]");
    334            cliRegisterCommand("quick", quickStatHandler, "qstat [port] - retrieve quick port status from switch");
    335            cliRegisterCommand("setmac", setmacHandler, "setmac [m2] [m1] [m0] - sets CPU MAC address to 00:0c:6a:m2:m1:m0");
    336            cliRegisterCommand("getmac", setmacHandler, "getmac - displays the current CPU MAC address ");
    337            cliRegisterCommand("pup", pupHandler, "pup [port] - forces port up at 100Mbps/FDX");
    338            cliRegisterCommand("pdown", pdownHandler, "pdown [port] - forces port up at 100Mbps/FDX");
    339            cliRegisterCommand("pdqtest", pdqTestHandler, "pdqtest [dotted quad IP addr] - test IP Addr parsing");
    340            return 0;
    341          }
    342          
    343          #endif
    344          
    345          
    346          

   Maximum stack usage in bytes:

     Function             CSTACK
     --------             ------
     byteSwap16               4
     parseDottedQuadV4       16
     pdownHandler            28
     pdqTestHandler          52
     pupHandler              28
     quickStatHandler        44
     setmacHandler           44
     swapMac                  0
     zarlinkCpuMacAddrGet    12
     zarlinkCpuMacAddrSet    12
     zarlinkHandler          44
     zarlinkUtilInit          4


   Segment part sizes:

     Function/Label                 Bytes
     --------------                 -----
     cpuMacAddr                        8
     byteSwap16                       44
     swapMac                          72
     foo                              16
     parseDottedQuadV4               224
     zarlinkHandler                  524
     qStats                           12
     yesBlar                           8
     noBlar                            8
     quickStatHandler                480
     zarlinkCpuMacAddrSet             88
     zarlinkCpuMacAddrGet             88
     setmacHandler                   424
     pupHandler                      156
     pdownHandler                    156
     pdqTestArray                      4
     pdqTestHandler                  200
     zarlinkUtilInit                 204
     ?<Initializer for yesBlar>        8
     ?<Initializer for noBlar>         8
     ?<Constant "%s: forcing port [%02...">
                                      44
     ?<Constant "pup">                 4
     ?<Constant "pup [port] - forces p...">
                                      44
     ?<Constant "pdown">               8
     ?<Constant "pdown [port] - forces...">
                                      48
     ?<Constant "pdqtest">             8
     ?<Constant "0x%02x\n">            8
     ?<Constant "zl reg[%04x] = %02x\n">
                                      24
     ?<Constant "zl status[%02x]\r\n">
                                      20
     ?<Constant "zl reg[%04x] <-- %02x\n">
                                      24
     ?<Constant "%s: Flow Ctrl[f]  FDX...">
                                      76
     ?<Constant "_cpu[%02x]  ">       16
     ?<Constant "mmac[%02x]  ">       16
     ?<Constant "port[%02x]  ">       16
     ?<Constant "%s: setting cpu MAC a...">
                                      64
     ?<Constant "%s: cpu MAC address i...">
                                      56
     ?<Constant "pdqtest [dotted quad ...">
                                      56
     ?<Constant "%s: forcing port [%02...">_1
                                      32
     ?<Constant "%s: IP Addr is [%02x]...">
                                      48
     ?<Constant "zl">                  3
     ?<Constant "zl [read <index>] [wr...">
                                      48
     ?<Constant "quick">               8
     ?<Constant "qstat [port] - retrie...">
                                      56
     ?<Constant "setmac">              8
     ?<Constant "setmac [m2] [m1] [m0]...">
                                      68
     ?<Constant "getmac">              8
     ?<Constant "getmac - displays the...">
                                      48
      Others                         120

 
 2 756 bytes in segment CODE
   859 bytes in segment DATA_C
    16 bytes in segment DATA_I
    16 bytes in segment DATA_ID
    40 bytes in segment DATA_Z
    24 bytes in segment INITTAB
 
 2 660 bytes of CODE  memory (+ 120 bytes shared)
   875 bytes of CONST memory
    56 bytes of DATA  memory

Errors: none
Warnings: 7
