我已经设法在VHDL中实现模拟超时.如果进程运行时间更长,则MaxRuntime会被"杀死".
不幸的是,这不相反.如果我的模拟在MaxRuntime之前完成,那么一切都在等待MaxRuntime上的最后一个等待语句.
我发现,这是可能的结合wait on,wait for并wait until声明为一体.
我目前的代码片段.一个完整的例子很长......
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;
Run Code Online (Sandbox Code Playgroud)
如果IsFinalized更改,则不退出等待语句.我的模拟运行大约160 us.如果我设置MaxRuntime为50 us,模拟将停止在大约50 us(加上一些额外的循环,直到每个过程都注意到停止条件).当我设置MaxRuntime为200 us时,模拟退出200 us,而不是162 us.
我不想使用命令行开关来模拟器来设置最大执行时间.
由于 user1155120 给出的原因,您无法等待变量。因此,您需要使用信号。(包中的信号是全局信号)。
不幸的是,即使全局信号在范围内,它仍然需要是过程的输出参数,这很丑陋。不仅如此,在您的代码中,您将从多个位置驱动信号,该全局信号需要是一种解析类型,例如 std_logic。这也有点难看。
这是代码的一个版本,其中共享变量被信号替换,布尔类型被 std_logic 替换,全局信号添加为输出参数:
library IEEE;
use IEEE.std_logic_1164.all;
package sim is
signal IsFinalized : std_logic := '0';
procedure initialize(signal f : out std_logic; MaxRuntime : TIME := TIME'high);
procedure finalize (signal f : out std_logic);
end package;
package body sim is
procedure initialize(signal f : out std_logic; MaxRuntime : TIME := TIME'high) is
begin
-- do init stuff
if (MaxRuntime = TIME'high) then
wait on IsFinalized for MaxRuntime;
finalize(f);
end if;
end procedure;
procedure finalize (signal f : out std_logic) is
begin
if (IsFinalized = '0') then
f <= '1';
-- do finalize stuff:
-- -> stop all clocks
-- write a report
report "Finished!";
end if;
end procedure;
end package body;
use work.sim.all;
entity test is
end entity;
architecture tb of test is
begin
initialize(IsFinalized, 200 us);
process
begin
-- simulate work
wait for 160 us;
finalize(IsFinalized);
wait;
end process;
end architecture;
Run Code Online (Sandbox Code Playgroud)
http://www.edaplayground.com/x/VBK