1

I tried to write an automatic script for modelsim, where I would go through each possible malfunction in the circuit one by one, and then analyze it. For one malfunction, I did everything, and it works, however when I tried to make a loop where I did the same with everyone one by one, I had several problems at once.

  1. Can do files be called from tcl scripts? Since the actions for one malfunction are performed using the do file, and the loop for iterating over them is already a Tcl script.

  2. When trying to run the whole thing, modelsim gave an execution result of 0 and that's all, despite the fact that it did not swear at syntax errors.

Here is the do file for one fault (fault.do):

vmap work work
vcom -reportprogress 300 -work work {sheme.vhd}
vcom -reportprogress 300 -work work {testbench.vhd}
vsim -wav simwave.wlf work.device_tb
env sim:/device_tb/uut
view signals
.signals.tree write signalfile.txt
add wave sim:/device_tb/uut/*
add list sim:/device_tb/uut/*
run  5000 ns
quit -sim

quietly WaveActivateNextPane  {} 0 
dataset open ./simwave.wlf simwave
add wave simwave:/device_tb/uut/*
add list simwave:/device_tb/uut/*
vsim work.device_tb
env sim:/device_tb/uut
view signals
quietly WaveActivateNextPane 
add wave sim:/device_tb/uut/*
add list sim:/device_tb/uut/*
source forc.tcl
tosignal 1
quietly WaveActivateNextPane 

compare start simwave sim
compare options -track
compare add -wave -recursive -tolL {0 ns} -tolT {0 ns} simwave:/device_tb/uut sim:/device_tb/uut
compare add -list -recursive -tolL {0 ns} -tolT {0 ns} simwave:/device_tb/uut sim:/device_tb/uut
compare run
view wave
view list
compare info -write C:/Modeltech_5.7f/examples/dip/compare.txt
source analys.tcl
comp 2

And here are my attempts to make a loop for all such faults:

set fp [open "signalfile.txt" r]
set cnts 0
set cntoth 0
while { [gets $fp data] >= 0 } {
    if {[string match $data s?] == 1} {
    incr cnts } else {
    incr cntoth }
}

for {set i 0} {$i < $cnts} {incr i} {
    set var $env($i)
    source fault.do
    exec $var }

set fn [open "errors.txt" r]
set er 0
while { [gets $fn data] >= 0 } {
    incr er }
set per [expr $er/[expr $cntoth + $cnts]]
puts $per

Can anyone suggest how best to implement this? I'll be very thankful)

Donal Fellows
  • 133,037
  • 18
  • 149
  • 215
artkuv
  • 11
  • 1
  • As far as I'm aware (as someone who doesn't use Modelsim _at all)_ you can just `source` that `do` file. It _looks_ like a Tcl script so it probably is one. The second problem is absolutely the main one here. – Donal Fellows May 18 '21 at 07:22

0 Answers0