我应该在哪里调用VHDL中受保护类型的初始化函数?

时间:2016-01-02 21:18:18

标签: initialization vhdl simulation

我在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程序?

我当前的解决方案在testbench架构体中的单独进程中调用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;

有更好的解决方案吗?

1 个答案:

答案 0 :(得分:2)

根据您的代码,假设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;