Email: bknpk@hotmail.com Phone: +972-54-7649119


V

 

perl script to parse a VR_AD file and generate write operation commands.

  1. This script works on a VR_AD file and generates write operation commands. In my case on each RW register, a VR_AD write command is generated.
    There is also an option to generate a list of registers only (if a parameter is given to the script). This script was used in a very specific case. In most cases one would use a code style as shown in: vr_ad get_all_regs

  2. The input might look like:

    reg_def KUKU_REG {
      reg_fld KUKU_PAGE_1_A1 : uint(bits : 1) : R : 0x0000 : cov;
      reg_fld KUKUOWLEDGE_1_A1 : uint(bits : 1) : R : 0x0000 : cov;
      reg_fld KUKUTE_FAULT_A1 : uint(bits : 1) : R : 0x0000 : cov;
      reg_fld KUKURVED__012_012 : uint(bits : 1) : RW : 0x0000;
      reg_fld KUKUMETRIC_PAUSE_A1 : uint(bits : 1) : R : 0x0000 : cov;
      reg_fld KUKUE_A1 : uint(bits : 1) : R : 0x0000 : cov;
      reg_fld KUKU0BT4_A1 : uint(bits : 1) : R : 0x0000 : cov;
      reg_fld KUKU0BTX_FD_A1 : uint(bits : 1) : R : 0x0000 : cov;
      reg_fld KUKU0BTX_HD_A1 : uint(bits : 1) : R : 0x0000 : cov;
      reg_fld KUKUBT_FD_A1 : uint(bits : 1) : R : 0x0000 : cov;
      reg_fld KUKUBT_HD_A1 : uint(bits : 1) : R : 0x0000 : cov;
      reg_fld KUKUCTOR_FIELD_A1 : uint(bits : 5) : R : 0x0000 : cov;
    };


  3. The script is invoked from within vim by:
    %! perl ~/bin/vim_vr_ad_wr_rd.pl


    The output is:
    var N_0_KUKURVED__012_012_gen : uint(bits : 1);
    gen N_0_KUKURVED__012_012_gen;
    PKFASTFREQ_REG_WRITE KUKU_REG {
      .KUKURVED__012_012=N_0_KUKURVED__012_012_gen;
    };


  4. The script is listed below:

    1. #!/bin/perl
    2. #%! perl ~/bin/vim_vr_ad_wr_rd.pl
    3. #%! perl ~/bin/vim_vr_ad_wr_rd.pl list
    4. #to avoid same field naming each field is also given a
    5. #number, so the specm aribtrary variable has a uniqe name.
    6. $field_no=0;
    7. #some registers shall not be written randomally.
    8. @no_write_a = ();
    9. push(@no_write_a, "REG_FAST");
    10. push(@no_write_a, "REG_SLOW");
    11. push(@no_write_a, "REG_PARALLEL");
    12. #it is possible to generate only a list of registers
    13. $gen_list_only=index($ARGV[0], "list");
    14. $reg_name="";
    15. while (<STDIN>) {
    16.   chomp($_);
    17.   if($_ =~ /^reg_def[ \s\t]*([A-Za-z][A-Za-z0-9_]*)[ \s\t]*{.*/) {
    18.     $reg_name=$1;
    19.     $ignore_flg=0;
    20.     foreach $ignore ( @no_write_a ) {
    21.       $cmpix=index($reg_name, $ignore);
    22.       if($cmpix == 0) {
    23.         $ignore_flg=1;
    24.         last;
    25.       }
    26.     }
    27.     if($ignore_flg == 0 && $gen_list_only == 0) {
    28.       print(" permitted_to_wr_l.push($reg_name);\n");
    29.     }
    30.   }
    31.   elsif($_ =~ /[ \s\t]*reg_fld[ \s\t]*([A-Za-z][A-Za-z0-9_]*)[ \s\t]*:[ \s\t]*(uint\(bits[ \s\t]*:[ \s\t]*[0-9]*\))/) {
    32.     #get reg_fields
    33.     $reg_fld=$1;
    34.     $reg_fld_uint=$2;
    35.     $skip_on_RESERVED=index($reg_fld, "RESERVED");
    36.     if($ignore_flg == 0 && $skip_on_RESERVED < 0 && $gen_list_only != 0) {
    37.       if($_ =~ /:[ \s\t]*RW[ \s\t]*/) {
    38.         &wr_reg($reg_name, $reg_fld, $reg_fld_uint);
    39.       }
    40.     }
    41.   }
    42. }#while
    43. sub wr_reg {
    44.   #0 reg name
    45.   #1 reg field
    46.   #2 uint(bits:n)
    47.   my $var_name;
    48.   $var_name="N_" . $field_no . "_" . $_[1] . "_gen";
    49.   print("var $var_name : $_[2];\n");
    50.   print("gen $var_name;\n");
    51.   print("PKFASTFREQ_REG_REG_WRITE $_[0] {\n");
    52.   print(" ."); print("$_[1]"); print("=$var_name;\n");
    53.   print("};\n");
    54.   $field_no++;
    55. }

  ...


Home

How to change the default bash internal field space separator.

A simple c-code program to read a memory array from verilog RTL, using VPI.






Search This Site


Feedback This Site




new pages on this site