我应该在哪里调用 VHDL 中受保护类型的初始化函数?
Where should I call an initializer function of a protected type in VHDL?
我在 VHDL 中有一个受保护的类型,它实现了一个初始化函数或过程。
这是我的带有初始化程序的代码:
type T_SIM_STATUS is protected
procedure init;
procedure fail(Message : in STRING := "") ;
procedure simAssert(condition : BOOLEAN; Message : STRING := "") ;
procedure simReport;
end protected;
type T_SIM_STATUS is protected body
variable NotImplemented : BOOLEAN := TRUE;
variable Passed : BOOLEAN := TRUE;
procedure init is
begin
NotImplemented := FALSE;
end procedure;
procedure fail(Message : in STRING := "") is
begin
if (Message'length > 0) then
report Message severity error;
end if;
Passed := FALSE;
end procedure;
procedure simAssert(condition : BOOLEAN; Message : STRING := "") is
begin
if (condition = FALSE) then
fail(Message);
end if;
end procedure;
procedure simReport is
variable l : LINE;
begin
write(l, STRING'("SIMULATION RESULT = "));
if (NotImplemented = TRUE) then
write(l, STRING'("NOT IMPLEMENTED"));
elsif (Passed = TRUE) then
write(l, STRING'("PASSED"));
else
write(l, STRING'("FAILED"));
end if;
end procedure;
end protected body;
shared variable simStatus : T_SIM_STATUS;
我应该在哪里调用 init
过程?
我当前的解决方案在测试台架构主体的单独进程中调用 init
:
architecture rtl of test is
-- ...
begin
procInit : process
begin
simStatus.init;
wait;
end process;
procGenerator : process
begin
-- generate stimuli
wait;
end process;
procTester : process
begin
-- check results by using simStatus.simAssert
simStatus.simReport;
wait;
end process;
end architecture;
有更好的解决方案吗?
根据您的代码,假设 init
的效果应该在受保护类型中使用其他过程(方法)之前产生,看起来 init
过程可以被删除,如果 NotImplemented
如果给定初始值 FALSE
而不是 TRUE
.
否则,如果要先调用init
,只要确保共享变量的其他用途没有在时间0被调用,在这种情况下可以调用init
作为并发,因此没有 process
包装器,但就像:
simStatus.init;
如果必须通过 init
调用完成更复杂的设置,那么在实例化共享变量时可以自动调用它,如果 init
是一个函数,然后从内部调用共享变量的主体,如:
type T_SIM_STATUS is protected
-- No init function is made public
procedure fail(Message : in STRING := "") ;
procedure simAssert(condition : BOOLEAN; Message : STRING := "") ;
procedure simReport;
end protected;
type T_SIM_STATUS is protected body
variable NotImplemented : BOOLEAN := TRUE;
variable Passed : BOOLEAN := TRUE;
... # Other code
impure function init return boolean is
begin
NotImplemented := FALSE;
... -- Or other more complex code
return TRUE;
end function;
variable dummy : boolean := init; -- Calling init with side effects
end protected body;
我在 VHDL 中有一个受保护的类型,它实现了一个初始化函数或过程。
这是我的带有初始化程序的代码:
type T_SIM_STATUS is protected
procedure init;
procedure fail(Message : in STRING := "") ;
procedure simAssert(condition : BOOLEAN; Message : STRING := "") ;
procedure simReport;
end protected;
type T_SIM_STATUS is protected body
variable NotImplemented : BOOLEAN := TRUE;
variable Passed : BOOLEAN := TRUE;
procedure init is
begin
NotImplemented := FALSE;
end procedure;
procedure fail(Message : in STRING := "") is
begin
if (Message'length > 0) then
report Message severity error;
end if;
Passed := FALSE;
end procedure;
procedure simAssert(condition : BOOLEAN; Message : STRING := "") is
begin
if (condition = FALSE) then
fail(Message);
end if;
end procedure;
procedure simReport is
variable l : LINE;
begin
write(l, STRING'("SIMULATION RESULT = "));
if (NotImplemented = TRUE) then
write(l, STRING'("NOT IMPLEMENTED"));
elsif (Passed = TRUE) then
write(l, STRING'("PASSED"));
else
write(l, STRING'("FAILED"));
end if;
end procedure;
end protected body;
shared variable simStatus : T_SIM_STATUS;
我应该在哪里调用 init
过程?
我当前的解决方案在测试台架构主体的单独进程中调用 init
:
architecture rtl of test is
-- ...
begin
procInit : process
begin
simStatus.init;
wait;
end process;
procGenerator : process
begin
-- generate stimuli
wait;
end process;
procTester : process
begin
-- check results by using simStatus.simAssert
simStatus.simReport;
wait;
end process;
end architecture;
有更好的解决方案吗?
根据您的代码,假设 init
的效果应该在受保护类型中使用其他过程(方法)之前产生,看起来 init
过程可以被删除,如果 NotImplemented
如果给定初始值 FALSE
而不是 TRUE
.
否则,如果要先调用init
,只要确保共享变量的其他用途没有在时间0被调用,在这种情况下可以调用init
作为并发,因此没有 process
包装器,但就像:
simStatus.init;
如果必须通过 init
调用完成更复杂的设置,那么在实例化共享变量时可以自动调用它,如果 init
是一个函数,然后从内部调用共享变量的主体,如:
type T_SIM_STATUS is protected
-- No init function is made public
procedure fail(Message : in STRING := "") ;
procedure simAssert(condition : BOOLEAN; Message : STRING := "") ;
procedure simReport;
end protected;
type T_SIM_STATUS is protected body
variable NotImplemented : BOOLEAN := TRUE;
variable Passed : BOOLEAN := TRUE;
... # Other code
impure function init return boolean is
begin
NotImplemented := FALSE;
... -- Or other more complex code
return TRUE;
end function;
variable dummy : boolean := init; -- Calling init with side effects
end protected body;