I have manageg to implement a simulation timeout in VHDL. If processes are running longer the MaxRuntime they get 'killed'.
Unfortunately, this does not work the other way around. If my simulation is finished before MaxRuntime, everything is waiting for the last wait statement on MaxRuntime.
I found that it's possible to combine wait on
, wait for
and wait until
statements into one.
My current code in snippets. A full example is quite to long...
package sim is
shared variable IsFinalized : BOOLEAN := FALSE;
procedure initialize(MaxRuntime : TIME := TIME'high);
procedure finalize;
end package;
package body sim is
procedure initialize(MaxRuntime : TIME := TIME'high) is
begin
-- do init stuff
if (MaxRuntime = TIME'high) then
wait on IsFinalized for MaxRuntime;
finalize;
end if;
end procedure;
procedure finalize;
begin
if (not IsFinalized) then
IsFinalized := TRUE;
-- do finalize stuff:
-- -> stop all clocks
-- write a report
end if;
end procedure;
end package body;
entity test is
end entity;
architecture tb of test is
begin
initialize(200 us);
process
begin
-- simulate work
wait for 160 us;
finalize;
end process;
end architecture;
The wait statement is not exited if IsFinalized
changed. My simulation runs for circa 160 us. If I set MaxRuntime
to 50 us, the simulation stops at circa 50 us (plus some extra cycles until each process noticed the stop condition). When I set MaxRuntime
to 200 us, the simulation exits at 200 us and not after 162 us.
- How can I exit/abort the wait statement?
- Why can't I wait on a variable?
I don't want to use a command line switch for a simulator to set the max execution time.