I came across a query on the possibility of passing info to modelsim's do file.
The first thing that I thought was it is possible by using command line arguments. Since do file is nothing but a Tcl file (ModelSim uses Tcl as its command language), info as arguments can be passed from the command line.
ex: # tcl <filename.tcl> arg1 arg2 ... argn
Then we can use Tcl's global variables argc and argv to access these arguments inside the tcl file.
So by passing the info as arguments to the do file while invoking vsim command, info can be passed on to the do file.
That is: vsim ... -do "<filename.do> arg1 arg2 ... argn"
But when tried with this logic, the arguments passed were not passed on to the file. But instead I saw the vsim arguments echoed on the screen.
echo "No of command line arguments passed are: $argc"
set i 0
foreach index $argv {
echo "argument #$i: $index"
incr i
}
Adding the above lines of code in the do file (run_def.do) and then passing this file as a -do switch option to vsim command as,
vsim {other switch options} -do "run_def.do test1 test2" &
where test1 and test2 are arguments passed on to the do file. Instead of displaying argc as 3 and test1 and test2 as the arguments, it showed 21 as the argc and echoed the arguments of entire vsim command!
Since ModelSim uses Tcl as its command language, vsim invocation too is like running a tcl script with its switch options as command line arguments. The do file passed as -do switch option is taken to be as an argument passed. The script vsim doesn't consider the do file as a separate script file but as a part of vsim script itself. (It can be assumed that the contents of do file gets appended to vsim script at the end). So it is vsim script that reads the do file and executes the commands within it.
This is why argc and argv displayed the results as detailed above. Now it became simple to pass the info to do file. The info can be passed as a generic option of vsim command (-G switch option), which can then be searched for in the do file if the info is known in prior.
For my requirement, the do file had to execute different set of commands according to the category of testcase to be executed. So the do file needed to know the category of the testcase and based on this info selects the branch (if-else) for execution. Also if no category is passed then no branch is to be selected but run as normal.
If a testcase was part of a category then this info was passed as a generic parameter (with -G switch option) of vsim command. The do file searched for this prior defined generic parameter (in top level TB) within the argument list (argv) and then select the branch for execution.
TX_CATEGORY and RX_CATEGORY were defined as generics of boolean type in the top level TB file and the do file searched for either of these strings for the branch selection.
vsim -GTX_CATEGORY=TRUE {....} -do "<run_def.do>"
In the run_def.do file:
set x [lsearch $argv -GTX_CATEGORY=TRUE ]
set y [lsearch $argv -GRX_CATEGORY=TRUE ]
if "$x != -1" { #TX_Category...
}
if "$y != -1" { #RX_CATEGORY
...
}
run -all
quit -f
The result of lsearch if successful in finding the string is the index of the argument list, argv, and -1 if it fails in finding the string. Each branch contains different set of commands to be run in prior to run -all command. If neither of the the generics are passed, then no branch gets selected, which is the required case.
Reference : Tcl tutorial
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Basic Idea on the use of do file:
Do file is basically a script file for modelsim to automate tasks like repetitive simulations for debugging purposes. All the commands that can be run on a ModelSim command prompt can be saved in a macro file (usually named with .do extension), and this file can be passed as an argument to vsim command with -do switch option. Once the ModelSim launches and loads the design, this file will be executed as "do <file.do>" automatically.
Since ModelSim uses Tcl for its command language, the do file can have simulation-specific commands as well as Tcl commands which can include graphic interface features, and a general programming interface for building up complex command procedures.
Idea2:
Use vsim command's generic argument switch (-G) to pass a generic to the design (The design is in VHDL.) This generic value can be used in the top level test-bench to create an event by turning high one of the signal meant only for this purpose. Based on the signal event going high, a particular branch should get selected in the do file.
Using 'when' command of Tcl to wait on an event and executing the branch statement is not possible because of Tcl's sequential execution. If the first when statement doesn't trigger then the execution doesn't proceed further. The execution of the further statements/commands never happens.
______________________________________________________
3 comments:
Try
vsim ... -do "do arg1 arg2 ... argn"
Try
vsim ... -do "do arg1 arg2 ... argn"
Thank you very much.
Post a Comment