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

 

ASIC/FPGA Design and Verification Out Source Services

Some tips to work on bits, using perl.

  1. In a VHDL SD slave, project I needed to work on bits. The script was used in post simulation processing. It read messages from the simulation log to verify data integrity.

  2. While the messages from the end target, the flash FMF VHDL model, were in decimal (VHDL integer print), the messages on the SD side were binary.
    To extract the bit stream was easy:

  3. if($line =~ /SD write data DA3 ([0-1]*) DA2 ([0-1]*) ...
      $b3=$1;
      $b2=$2;
      $b1=$3;
      $b0=$4;
      &sd_4($b3, $b2, $b1, $b0);


  4. To construct bytes out of bits, I used substr:

  5. $l3=length($a3); print("Collected $l3 bits per channel\n");
    #build a byte and check it
    $sd_byte="";
    for($i = 0; $i < $l3; $i++) {
      $sd_byte=$sd_byte . substr($a3, $i, 1);
      $sd_byte=$sd_byte . substr($a2, $i, 1);
      $sd_byte=$sd_byte . substr($a1, $i, 1);
      $sd_byte=$sd_byte . substr($a0, $i, 1);
      $l8=length($sd_byte);
      if($l8 == 8) {
        $hex = sprintf('%02X', oct("0b$sd_byte"));
    ...

  6. Note: that binary to hex conversion, formated with two digits, is done using sprintf.

  7. To summarize conversions are easy in perl:
    hex to binary
    #from hex to decimal and then to binary with 16 bits leading zero pad.
    $b_num=sprintf('%016b', hex $h_nem);

    binary to hex
    Note the hex number is three digits and ob prefix.
    $h_num=sprintf('%03X', oct("0b$b_num"));



I would be happy to offer my services. Call ASAP !


Home

Download Area






Search This Site


Feedback This Site




new pages on this site