A simple perl script, to count the number of data
valid pulses in each packet, in a VCD wave
file.
-
I needed today a script, that counts the number of times RX data valid is
asserted in VCD wave format.
The script implements a counter, which is cleared every time that start of
packet is rising (0 to 1 edge detect in VCD wave file). Once detected and if the counter is not zero,
its value is printed.
The counter is incremented each time a rising edge is encountered on the valid signal in the VCD
wave file.
Last, but not least, a time variable is updated too, when ever a time statement,
in the VCD file is seen. This enables to print the time together with the
pulse count information.
-
In VCD every signal is represented by an alias. This is defined in the first
part of the VCD wave file. The second part is for data change values and time. In my
case, I have identified, that start of packet is aliased to
va and valid to
wa.
The script is invoked from within vim by :
:% !perl ~/bin/vim_vcd_count.pl
-
The script is listed below:
- #!/bin/perl
- $rxdv=0;
- $sop=0;
- $time=0;
- $cnt=0;
- #sop va rxdv wa
- while (<STDIN>) {
- chomp($_);
- print("$_\n");
- if($_ =~ /^#([0-9]*)/) { $time=$1; }
- else {
- $len=length($_);
- if($len == 3) { #update sop
- $flg=0;
- $ix=index($_, "va");
- if($ix == 1) {$sop_n = substr($_, 0, 1); $flg=1;}
- }
- if($sop == 0 && $sop_n == 1) {
- if($cnt > 0) {print("count rxdv $cnt at $time\n");}
- $cnt=0;
- }
- if($flg == 1) { $sop = $sop_n; }
- if($len == 3) { #update rxdv
- $flg=0;
- $ix=index($_, "wa");
- if($ix == 1) {$rxdv_n = substr($_, 0, 1); $flg=1;}
- }
- if($rxdv == 0 && $rxdv_n == 1) {
- $cnt++;
- }
- if($flg == 1) { $rxdv = $rxdv_n; }
- }
- }#while
-
If your GTKWAVE supports TCL, you may select to extract values using the TCL.
For instance this TCL script will print to screen some values of a signal:
- set signal sys.cpp_fft_i_chip_Re
- set start_time 127370
- foreach {time value} [gtkwave::signalChangeList $signal -start_time $start_time -max 100] {
- puts "Sim Time:: $time val: $value"
- }
|