2

I am trying to get a ModelSim simulation to stop when a particular event occurs, or after a timeout, whichever comes first.

I have tried a purely software approach, using a while loop and issuing a run 1 ns command at every iteration and checking if the condition has been met:

set clockCycles 0
set clockCycleLimit 200
while {/some_signal != 1 && $clockCycles < $clockCycleLimit} {
    run 1 ns
    set clockCycles [expr {$clockCycles + 1}]
}

This works, but is somewhat slow. Therefore, I tried a new approach using a when command instead.

when {/some_signal == '1'} {
    stop
}
run 200 ns

This runs very quickly and is more elegant. The only problem I have with it is that it displays an annoying message in the Transcript window: "Simulation stop requested" every time this code runs.

I am using this code as part of an interactive ModelSim session, and theses messages constantly showing up ruin the user experience. I am trying to find a way to disable them. So far I haven't found anything that works.

Would someone be able to help?

Thanks!

2 Answers2

1

To configure the Modelsim to not generate this kind of messages (available from the version 5.6) type the next TCL command:

set PrefMain(noRunMsg) 1
Nathaniel Ford
  • 20,545
  • 20
  • 91
  • 102
0

Everything that uses stop or the breakpoint mechanism seems to generate that message; it may even be coming out of the simulation engine itself. There doesn't seem to be a way to tell stop to be silent (short of contacting Customer Support and hoping, of course).

That means that the only way I can think of — and this is an ugly hack — is to launch another copy of the Tcl event loop inside the when's callback script (with vwait or tkwait) to support the GUI interaction. The code is pretty short, but you really must not let the simulation continue to run or be killed off except by finishing this internal event loop and then letting the when callback finish (or calling the noisy stop). Think “run a modal dialog” instead of “run the entire GUI”.

And it still might not work, if the simulation engine is itself using the Tcl event loop to manage the scheduling of things. It probably isn't… but I really can't tell so you'll have to proceed with caution (and no, I'm definitely not a licensee so I can't test for you). Getting this wrong can blow up the C stack and cause real problems, so be cautious.

Donal Fellows
  • 133,037
  • 18
  • 149
  • 215
  • @KevinCadieux Caution is merited. Modelsim includes some custom hacking on the Tcl event loop to implement it's breakpoint capability which is why there is different behavior between the Tcl `source` command and its extended `do` command. – Kevin Thibedeau Feb 22 '15 at 08:16