Beruflich Dokumente
Kultur Dokumente
Testbench Tasks
with Tcl
Webinar 7 Aug 2008
Jonathan Bromley
Senior Consultant, Doulos
As presented
Copyright at the
2004-7 by Doulos Ltd. AllWebinar,
Rights Reservedwith minor corrections to slides 9 and 10 1
Automating Testbench Tasks with Tcl
AGENDA
Why scripting?
Automation of breakpoints
Why Scripting?
Repeatability:
Compilation order is important in both VHDL and Verilog
Wrong order can give mysterious errors or wrong functionality
Run options are important
Convenience:
GUI/Project systems are fine, but...
Some users are not familiar with tool intricacies -
hide details in a script, make all users productive
AGENDA
Why scripting?
Automation of breakpoints
Tcl in the Aldec Simulators
Native command language in Aldec tools is not Tcl
Tcl for programmability, manipulation of external files, ...
Tcl script must be in a file with .tcl suffix or use do -tcl
Square brackets -
Create and set a Tcl variable use result of command
Display to console
Filename .tcl -
use Tcl automatically
puts A_silly_string
puts A_silly_string
A_silly_string
set AA test
set test $ works inside quotes!
puts "A;
puts "A; set
set AA junk;
junk; puts
puts $A"
$A"
A; set A junk; puts test
AGENDA
Why scripting?
Automation of breakpoints
Simple Flow Automation Macros
Tcl script (macro) replaces repetitive GUI or command-line actions
set source_file_list
set source_file_list {{
newline or space
webinar_Tcl/dut/fsm.v
webinar_Tcl/dut/fsm.v separates list elements
webinar_Tcl/testbench/vector_fsmtf.v
webinar_Tcl/testbench/vector_fsmtf.v
}}
list to scan - use $
scan the list foreach
foreach source
source $source_file_list
$source_file_list {{
vlog
vlog $source
$source
braces enclose code
}}
loop variable -
note use of $
set
set source_file
source_file webinar_Tcl/dut/fsm.v
webinar_Tcl/dut/fsm.v Linux-style filenames
puts
puts [file normalize $source_file]
[file normalize $source_file] get absolute pathname
/home/verilog0/webinar_Tcl/dut/fsm.v
set
set vectors_file
vectors_file webinar_Tcl/vectors.txt
webinar_Tcl/vectors.txt
file copy $vectors_file
file copy $vectors_file temp.txt
temp.txt copy the file
set
set f_id
f_id [open
[open user.txt
user.txt w]
w] open file for writing
puts $f_id "Using
puts $f_id "Using $vectors_file"
$vectors_file" write one line to file
close $f_id
close $f_id close the file
move file to
file rename user.txt
file rename user.txt webinar_Tcl/user.txt
webinar_Tcl/user.txt
another directory
puts
puts $env(LM_LICENSE_FILE)
$env(LM_LICENSE_FILE)
1700@artemis
puts
puts [pwd]
[pwd]
/home/verilog0
puts
puts $tcl_platform(user)
$tcl_platform(user)
verilog0
env, tcl_platform are Tcl array variables - see any Tcl text for details
do show_args.tcl
do show_args.tcl First
First Second
Second
puts
puts "start
"start show_args"
show_args" show_args.tcl
puts
puts "first
"first arg
arg is
is $1"
$1" start show_args
puts
puts "second
"second arg
arg is
is $2"
$2" first arg is First
second arg is Second
AGENDA
Why scripting?
Automation of breakpoints
Example: Simulation Control
Our project has two Verilog source files
fsm.v, vector_fsmtf.v
The testbench expects a file of test vectors vectors.txt
The testbench creates a results file results.txt both in simulator's
current directory
fdV
fdV == $fopen("vectors.txt",
$fopen("vectors.txt", "r");
"r"); Verilog testbench
if
if (!fdV)
(!fdV) begin
begin
$display("Could
$display("Could not
not open
open vectors.txt");
vectors.txt");
$stop; Verilog cannot do anything about this error
$stop;
end
end
fdR
fdR == $fopen("results.txt", "a"); Open output file
$fopen("results.txt", "a");
in append mode
## Check
Check arguments
arguments
if
if {![file
{![file exists
exists $1]}
$1]} {{
error
error "Can't
"Can't read
read vectors
vectors file
file $1"
$1" Tcl generates error
}}
set
set vectors_file
vectors_file [file
[file normalize
normalize $1]
$1]
Tcl copies the user's vector file to where Verilog can find it
file
file copy
copy -force
-force $1
$1 vectors.txt
vectors.txt copy to simulator's
current directory
asim
asim vectors_fsmtf
vectors_fsmtf
run
run Riviera commands invoked in Tcl macro
file
file copy
copy -force
-force results.txt
results.txt $results_file
$results_file
puts
puts "SIMULATION
"SIMULATION RESULTS IN $results_file"
RESULTS IN $results_file"
AGENDA
Why scripting?
Automation of breakpoints
Example: Custom Breakpoints
Riviera has when command:
Interrupt simulation on any change of a specified signal
Useful and powerful, but needs filtering
Most transitions on a signal are not interesting
proc countOnes
proc countOnes {{ vector
vector }} {{
set
set nBits
nBits 00 local variable
Tcl has all the usual while
while {$vector
{$vector !=
!= 0}
0} {
{
control constructs if {$vector
if {$vector && 1} 1} {{
incr nBits
incr nBits increment a variable
}}
set
set vector
vector [expr {$vector >>
[expr {$vector >> 1}]
1}]
}} compute C-style expression
return $nBits
return $nBits
}} return the result
Simulator message
from when breakpoint