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

C:\medusa\zl_mirror.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          /* for 'ingressEgress', 0=mirror disabled, 1=ingress, 2=egress */
     12          
     13          static struct {
     14            int port;
     15            int ctrlReg;
     16            int ingressEgress;
     17            int reflectPort;
     18            } mirrors[2];
     19          
     20          static int addMirror(int port, int ingressEgress, int reflectPort)
     21          {
     22            int i;
     23            unsigned char mirrorReg;
     24          
     25            if (!((ingressEgress == 1) || (ingressEgress == 2)))
     26              return -1;
     27          
     28            for(i=0;i<2;i++) {
     29              if (mirrors[i].ingressEgress == 0)
     30                break;
     31              }
     32          
     33            if (i==2) 
     34              return -1;
     35          
     36            mirrorReg = (unsigned char)0x80; // start by activating mirror
     37            mirrorReg |= (unsigned char)(port & 0x07);
     38            mirrorReg |= (unsigned char)((reflectPort & 0x07) << 4);
     39          
     40            if (ingressEgress == 1)
     41              mirrorReg &= ~(0x08);
     42            else if (ingressEgress == 2)
     43              mirrorReg |= 0x08;
     44          
     45            mirrors[i].port = port;
     46            mirrors[i].ingressEgress = ingressEgress;
     47            mirrors[i].reflectPort = reflectPort;
     48          
     49            zarlinkIndexedWrite(mirrors[i].ctrlReg, mirrorReg);
     50          
     51            return 0;
     52          }
     53          
     54          static int removeMirror(int port, int ingressEgress)
     55          {
     56            int i;
     57          
     58            if (!((ingressEgress == 1) || (ingressEgress == 2)))
     59              return -1;
     60          
     61            for(i=0;i<2;i++) {
     62              if ((mirrors[i].port == port) && (mirrors[i].ingressEgress == ingressEgress)) {
     63                mirrors[i].ingressEgress = 0;
     64                break;
     65                }
     66              }
     67          
     68            if (i==2) 
     69              return -1;
     70          
     71            zarlinkIndexedWrite(mirrors[i].ctrlReg, (unsigned char)0);
     72          
     73            return 0;
     74          }
     75          
     76          static void printAllMirrors(void)
     77          {
     78            int bufLen;
     79            char * pOutBuf;
     80            int i;
     81          
     82            pOutBuf = clicharGetOutputBuffer(&bufLen);
     83            
     84            for(i=0;i<2;i++) {
     85              if (mirrors[i].ingressEgress != 0) {
     86                sprintf(pOutBuf, "mirror[%d] port[%d] %s reflected to port[%d]\r\n",
     87                  i, 
     88                  mirrors[i].port, 
     89                  ((mirrors[i].ingressEgress == 1) ? "ingress" : "egress"), 
     90                  mirrors[i].reflectPort);
     91                }
     92              else {
     93                sprintf(pOutBuf, "mirror[%d] not enabled\r\n", i);
     94                }
     95              // output buffer
     96              clicharSendOutputBuffer(pOutBuf, bufLen);
     97              } // for loop
     98          }
     99          
    100          static int mirrorHandler(int argc, char * argv[], int flags)
    101          {
    102            int retVal = -1;
    103            int foo;
    104            int port, reflect;
    105            int ingrEgr;
    106            int i;
    107          
    108          
    109            if (argc == 1) {
    110              retVal = 0;
    111              printAllMirrors();
    112              }
    113            else if (argc == 4) {
    114              // grab the 'subject' port
    115              port = (int)strtol(argv[1], (char **)NULL, 10);
    116          
    117              // figure out ingress or egress
    118              switch(*argv[2]) {
    119                case 'i':
    120                case 'I':
    121                  ingrEgr = 1;
    122                  break;
    123                case 'e':
    124                case 'E':
    125                  ingrEgr = 2;
    126                  break;
    127                default:
    128                  return -1;
    129                  break;
                         ^
Warning[Pe111]: statement is unreachable

    int foo;
        ^
"C:\medusa\zl_mirror.c",103  Warning[Pe177]: variable "foo" was declared but
          never referenced

    int i;
        ^
"C:\medusa\zl_mirror.c",106  Warning[Pe177]: variable "i" was declared but
          never referenced
    130                }
    131          
    132              if ((*argv[3] == 'd') || (*argv[3] == 'D')) {
    133                retVal = removeMirror(port, ingrEgr);
    134                printAllMirrors();
    135                }
    136              else {
    137                reflect = (int)strtol(argv[3], (char **)NULL, 10);
    138                retVal = addMirror(port, ingrEgr, reflect);
    139                printAllMirrors();
    140                }
    141              }
    142            else {
    143              retVal = -1;
    144              }
    145          
    146            return retVal;
    147          }
    148          
    149          
    150          int zarlinkMirrorInit(void)
    151          {
    152            mirrors[0].ctrlReg = 0x710;
    153            mirrors[0].ingressEgress = 0;
    154          
    155            mirrors[1].ctrlReg = 0x711;
    156            mirrors[1].ingressEgress = 0;
    157          
    158            // disable the mirrors to start with
    159            zarlinkIndexedWrite(mirrors[0].ctrlReg, (unsigned char)0);
    160            zarlinkIndexedWrite(mirrors[1].ctrlReg, (unsigned char)0);
    161          
    162            cliRegisterCommand("mirror", mirrorHandler, "mirror [port] [ingress | egress] [reflectionPort | (d)isable] - replicate port traffic");
    163            return 0;
    164          }
    165          
    166          #endif
    167          

   Maximum stack usage in bytes:

     Function          CSTACK
     --------          ------
     addMirror            24
     mirrorHandler        40
     printAllMirrors      24
     removeMirror         16
     zarlinkMirrorInit     4


   Segment part sizes:

     Function/Label                 Bytes
     --------------                 -----
     mirrors                          32
     addMirror                       252
     removeMirror                    188
     printAllMirrors                 216
     mirrorHandler                   280
     zarlinkMirrorInit               140
     ??DataTable18                     4
     ?<Constant "mirror[%d] port[%d] %...">
                                      48
     ?<Constant "egress">              8
     ?<Constant "ingress">             8
     ?<Constant "mirror[%d] not enabled\r\n">
                                      28
     ?<Constant "mirror">              8
     ?<Constant "mirror [port] [ingres...">
                                      88
      Others                          84

 
 1 152 bytes in segment CODE
   188 bytes in segment DATA_C
    32 bytes in segment DATA_Z
    12 bytes in segment INITTAB
 
 1 080 bytes of CODE  memory (+ 84 bytes shared)
   188 bytes of CONST memory
    32 bytes of DATA  memory

Errors: none
Warnings: 3
