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.
-
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.
-
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.
-
To operate you need to mark an area. This is done using vim's mark command. An
input can be as the following example:
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;
};
-
The output of the script is:
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;
};
-
To run it, do the following:
:'a,'bg !perl ~/bin/vim_reg_fld_to_bits.pl
-
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:
- #!/bin/perl
- @a_f = (); #field
- @b_f = (); #bit index
- @d_f = (); #read / write
- $space=" ";
- $max=0;
- $shift=0;
- while (<STDIN>) {
- chomp($_);
- $bit_ix=0;
- if($_ =~ /reg_fld ([a-zA-Z_0-9]*) .*bits .*: ([0-9]*)\).*RW/) {
- $field=$1; $bits=$2;
- push(@a_f, $field);
- push(@b_f, $bits);
- push(@d_f, "W");
- $max = $max < length($field) ? length($field) : $max;
- $shift+=$bits;
- } else {
- if($_ =~ /reg_fld ([a-zA-Z_0-9]*) .*bits .*: ([0-9]*)\).*R/) {
- $field=$1; $bits=$2;
- push(@a_f, $field);
- push(@b_f, $bits);
- push(@d_f, "R");
- $max = $max < length($field) ? length($field) : $max;
- $shift+=$bits;
- } else {
- #print("$_\n");
- }
- }
- }
- $i=0;
- print("$space");
- print("--:'a,'b !perl ~/bin/vim_reg_fld_to_bits.pl\n");
- foreach $it ( @a_f ) {
- $m=1;
- for($j=0; $j < $b_f[$i]; $j++) { $m *= 2; }
- $m--;
- $h=sprintf("%02x", $m);
- print("$space");
- if($d_f[$i] eq "W") {
- print(" ");
- $p_f=$a_f[$i]; while(length($p_f) < $max) {$p_f=$p_f . " ";}
- $s1=$shift-$b_f[$i];
- $s=$s1 < 10 ? " " . $s1 : $s1;
- print(".$p_f = (read_val >> $s) & 0x$h;\n");
- }
- else {
- print("--");
- $p_f=$a_f[$i]; while(length($p_f) < $max) {$p_f=$p_f . " ";}
- $s1=$shift-$b_f[$i];
- $s=$s1 < 10 ? " " . $s1 : $s1;
- print(".$p_f = (read_val >> $s) & 0x$h;\n");
- }
- $shift -= $b_f[$i];
- $i++;
- }
|
|
Also available on this project:
|
|