The following article presents the easiest technique of
attaching an interactive GUI to Verilog simulation. Instead of PLI we are using
$system task and communication through files. Using simple examples, we
demonstrate a bi-directional intercommunication between Verilog domain and
Graphical forms.
1.
In.tcl : TCL Entry form
The following TC/TK code creates a simple GUI entry form.
Using this form, we can pass any information to Verilog domain as well as
control simulation run.
#---------------------------------------------------------------------------
#!/usr/local/bin/wish
label .l1 -text
"Enter the number:"
pack .l1 -side top
-fill x
entry .e1 -bd 1
-textvariable num
pack .e1 -side top
-fill x
button .run -text
Run -command {save $num; destroy .}
pack .run -fill x
-expand 1
button .stop -text
Finish -command {finish; destroy .}
pack .stop -fill x
-expand 1
proc save {num} {
set IF [open "infile" w]
puts $IF $num
close $IF
}
proc finish {} {
set IF [open "infile" a]
puts $IF 0
close $IF
}
#---------------------------------------------------------------------------
Running in.tcl file, the following window pops up:

Clicking on “Run” buton, we write entered number into the
“infile” file.
Clicking on “Stop” button, we write “0” in second line the this file.
2.
Out.tcl : TCL display form
The following simple form displays the number written into
the “outfile” file:
#---------------------------------------------------------------------------
#!/usr/local/bin/wish
set OF [open
"outfile" r]
gets $OF line
close $OF
label .l1 -text
"The number is: $line"
pack .l1
button .exit -text
Continue -command {destroy .}
pack .exit -fill x
-expand 1
#---------------------------------------------------------------------------
This code creates the following window:

3.
Test.v : Verilog Test file
Verilog Test file uses $system task to call TCL
applications, $readmemb task to read information from the “infile” and $fdisplay
task to write information into the “outfile”. See line comments for more
descriptions.
#---------------------------------------------------------------------------
module test;
integer i, file;
reg [0:31] num
[0:1];
initial
for (i=0; i<5;
i=i+1) begin
$system("in.tcl"); // Launch in.tcl application
$readmemh("infile", num); //
Read infile data into “num”
if (num[1] == 0) $finish; //
if second line contains 0, finish
$display("Number is equal to %x",
num[0]);
file = $fopen("outfile"); // Write the same variable into outfile
$fdisplay(file, "%x", num[0]);
$fclose(file);
$system("out.tcl"); // Launch out.tcl application
end
endmodule
#---------------------------------------------------------------------------
4.
Instalation and Run
Copy example files from the
current article or download in one of compressed
file.
In order to run this example, put test.v, in.tcl and out.tcl
files into the same directory. Make in.tcl and out.tcl files to be executable
and check that their first lines point to existing “wish” command. Then, run
test.v example with your favorite simulator.