ASIC/FPGA Design and Verification Out Source Services

Run a perl script from vim on a specman e-code, to help in a register field process.

  1. In this web site many scripts are presented. Some of them are targeted to be run from within the vim editor. It can also be invoked from the command line, by printing the file (for example by using cat command) and piping the output to the script. Using the vim run option is better. You see the in and out text using vim via its powerful syntax coloring feature.

  2. I used the script in a verification specman project. It was a very short contract project. The host register handler in the verification specman e-code did not handle single field write operations properly. You write one field and all the rest are cleared. Till the issue was solved, I used this little script.

  3. To operate you need to mark an area. This is done using vim's mark command. An input can be as the following example:


  4. reg_def GENESIS__BMCR {
      reg_fld kuku_rst : uint(bits : 1) : RW : 0x0000 : cov; -- Rreturns0s, WSelfClr
      reg_fld kuku_lp : uint(bits : 1) : RW : 0x0000 : cov;
      reg_fld kuku_speed : uint(bits : 1) : RW : 0x0000 : cov;
      reg_fld kuku_nc : uint(bits : 1) : RW : 0x0000 : cov;
      reg_fld kuku_pwr : uint(bits : 1) : R : 0x0000 : cov;
      reg_fld kuku_lpi : uint(bits : 1) : RW : 0x0000 : cov;
      reg_fld kuku_dd : uint(bits : 1) : RW : 0x0000 : cov; -- Rreturns0s, WSelfClr
      reg_fld kuku_id : uint(bits : 1) : RW : 0x0000 : cov;
      reg_fld kuku_fd : uint(bits : 1) : RW : 0x0000 : cov;
      reg_fld kuku_rd : uint(bits : 1) : RW : 0x0000 : cov;
      reg_fld kuku_rese : uint(bits : 6) : R : 0x0000;
    };
  5. The output of the script is:

  6. reg_def GENESIS__BMCR {
      --:'a,'b !perl ~/bin/vim_reg_fld_to_bits.pl
        .kuku_rst   = (read_val >> 15) & 0x01;
        .kuku_lp    = (read_val >> 14) & 0x01;
        .kuku_speed = (read_val >> 13) & 0x01;
        .kuku_nc    = (read_val >> 12) & 0x01;
      --.kuku_pwr   = (read_val >> 11) & 0x01;
        .kuku_lpi   = (read_val >> 10) & 0x01;
        .kuku_dd    = (read_val >>  9) & 0x01;
        .kuku_id    = (read_val >>  8) & 0x01;
        .kuku_fd    = (read_val >>  7) & 0x01;
        .kuku_rd    = (read_val >>  6) & 0x01;
      --.kuku_rese  = (read_val >>  0) & 0x3f;
    };
  7. To run it, do the following:

  8. :'a,'bg !perl ~/bin/vim_reg_fld_to_bits.pl

  9. All that left is to edit the required fields and leave the rest untouched, with the value that was read. The the script is shown below:

    1. #!/bin/perl
    2. @a_f = (); #field
    3. @b_f = (); #bit index
    4. @d_f = (); #read / write
    5. $space=" ";
    6. $max=0;
    7. $shift=0;
    8. while (<STDIN>) {
    9.   chomp($_);
    10.   $bit_ix=0;
    11.   if($_ =~ /reg_fld ([a-zA-Z_0-9]*) .*bits .*: ([0-9]*)\).*RW/) {
    12.     $field=$1; $bits=$2;
    13.     push(@a_f, $field);
    14.     push(@b_f, $bits);
    15.     push(@d_f, "W");
    16.     $max = $max < length($field) ? length($field) : $max;
    17.     $shift+=$bits;
    18.   } else {
    19.     if($_ =~ /reg_fld ([a-zA-Z_0-9]*) .*bits .*: ([0-9]*)\).*R/) {
    20.       $field=$1; $bits=$2;
    21.       push(@a_f, $field);
    22.       push(@b_f, $bits);
    23.       push(@d_f, "R");
    24.       $max = $max < length($field) ? length($field) : $max;
    25.       $shift+=$bits;
    26.     } else {
    27.       #print("$_\n");
    28.     }
    29.   }
    30. }
    31. $i=0;
    32. print("$space");
    33. print("--:'a,'b !perl ~/bin/vim_reg_fld_to_bits.pl\n");
    34. foreach $it ( @a_f ) {
    35.   $m=1;
    36.   for($j=0; $j < $b_f[$i]; $j++) { $m *= 2; }
    37.   $m--;
    38.   $h=sprintf("%02x", $m);
    39.   print("$space");
    40.   if($d_f[$i] eq "W") {
    41.     print(" ");
    42.     $p_f=$a_f[$i]; while(length($p_f) < $max) {$p_f=$p_f . " ";}
    43.     $s1=$shift-$b_f[$i];
    44.     $s=$s1 < 10 ? " " . $s1 : $s1;
    45.     print(".$p_f = (read_val >> $s) & 0x$h;\n");
    46.   }
    47.   else {
    48.     print("--");
    49.     $p_f=$a_f[$i]; while(length($p_f) < $max) {$p_f=$p_f . " ";}
    50.     $s1=$shift-$b_f[$i];
    51.     $s=$s1 < 10 ? " " . $s1 : $s1;
    52.     print(".$p_f = (read_val >> $s) & 0x$h;\n");
    53.   }
    54.   $shift -= $b_f[$i];
    55.   $i++;
    56. }
 


Also available on this project:


Home

Set of scripts indent a code, which is written in e (specman) or verilog or vhdl.

Some tips for controlling the xterm title






Search This Site


Feedback This Site




new pages on this site