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

 

ASIC/FPGA Design and Verification Out Source Services

Simple PERL script, which checks SD data write to flash.



  1. For an SD slave project I needed to check, that during SD write transaction, the data is written to a flash correctly. The VHDL test-bench generates valid SD traffic. When it writes data, I print it to the simulation log. The DUT then writes to flash. The flash FMF VHDL model prints a message also to the log, when it is written.

  2. The log print messages are of the following format:
    k9f1208_ghdl.vhd:1869:44:@1234199903ps:(assertion warning): FL: mem write of location 0 Pg 32 Ad 0 Da 5
    T:SD write data DA3 00001010...011111111 DA2 00001010...011111111 DA2 ...

  3. The PERL script scans the log file. When it detects a SD write message, it creates an array of expected data. Each time, that the PERL script finds a flash write message, it checks that it was written as expected.

  4. The PERL script main loop is simple, because of subroutine usage.


    1. #!/bin/perl

    2. $fi="ghdl.log";

    3. open(FPR, $fi) || die("open fail $fi\n");
    4. #typical line to work on


    5. $ix=0;
    6. @sd_a = (); #sd array
    7. while(eof(FPR) != 1) {
    8.   $line=; chomp($line);
    9.   #SD 4 bits
    10.   if($line =~ /SD write data DA3 ([0-1]*) DA2 ([0-1]*) DA1 ([0-1]*) DA0 ([0-1]*)/) {
    11.     $b3=$1;
    12.     $b2=$2;
    13.     $b1=$3;
    14.     $b0=$4;
    15.     &sd_4($b3, $b2, $b1, $b0);
    16.   }
    17.   #SD 1 bit
    18.   elsif($line =~ /SD write data DA0 ([0-1]*)/) {
    19.     $b0=$1;
    20.     &sd_1($b0);
    21.   }
    22.   #read flash data and check
    23.   elsif($line =~ /FL: mem write of location ([0-9]*) Pg ([0-9]*) Ad ([0-9]*) Da ([0-9]*)/) {
    24.     $loc=$1; $page=$2; $addr=$3; $dat=$4;
    25.     $data=sprintf("%02X", $dat);
    26.     if($data != $sd_a[$ix]) {
    27.       print("flash loc $loc page $page addr $addr data $data sd $sd_a[$ix] $ix ko\n");
    28.     }
    29.     else {
    30.       print("flash loc $loc page $page addr $addr data $data sd $sd_a[$ix] $ix ok\n");
    31.     }
    32.     $ix++;
    33.   }
    34. }#while

    35. close(FPR);

  5. The subroutines use sprintf to convert from binary to hex.
    The subroutines use substr to work on bits.
    The subroutines are shown below:


    1. sub sd_1 {
    2.   my $a="";
    3.   my $l="";
    4.   my $s="";
    5.   my $is="";

    6.   $a=$_[0];
    7.   $l=length($a);
    8.   for($i=0; $i < $l; $i+=8) {
    9.     $s=substr($a, $i, 8);
    10.     $is="";
    11.     for($j=0; $j < 8; $j++) {$is=$is . substr($s, 7-$j, 1);}
    12.     $s=substr($is, 4, 4) . substr($is, 0, 4);
    13.     $hex = sprintf('%02X', oct("0b$s"));
    14.     #print("dbg sd 1 bit $hex\n");
    15.     push(@sd_a, $hex);
    16.   }#for
    17. }#sub sd_1

    18. sub sd_4 {
    19.   my $a3=$_[0];
    20.   my $a2=$_[1];
    21.   my $a1=$_[2];
    22.   my $a0=$_[3];
    23.   my $l3="";
    24.   my $sd_byte="";
    25.   my $sz=0;
    26.   my $l8="";

    27.   print("$a3\n");
    28.   print("$a2\n");
    29.   print("$a1\n");
    30.   print("$a0\n");
    31.   $l3=length($a3); print("Collected $l3 bits per channel\n");
    32.   #build a byte and check it
    33.   $sd_byte="";
    34.   for($i = 0; $i < $l3; $i++) {
    35.     $sd_byte=$sd_byte . substr($a3, $i, 1);
    36.     $sd_byte=$sd_byte . substr($a2, $i, 1);
    37.     $sd_byte=$sd_byte . substr($a1, $i, 1);
    38.     $sd_byte=$sd_byte . substr($a0, $i, 1);
    39.     $l8=length($sd_byte);
    40.     if($l8 == 8) {
    41.       $hex = sprintf('%02X', oct("0b$sd_byte"));
    42.       #print("dbg sd 4 bits $sd_byte $hex $sz\n");
    43.       push(@sd_a, $hex);
    44.       $sz++;
    45.       $sd_byte="";
    46.     }
    47.   }#for
    48. }#sd_4


Home

VHDL IP Stack






Search This Site


Feedback This Site




new pages on this site