2016-01-02 34 views
1

我有一個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; 

有沒有更好的辦法呢?基於您的代碼

回答

2

,並假設應任何使用在受保護的種類等程序(方法)之前進行的init效果,它看起來像如果NotImplemented如果給定的FALSE的初始值,而不是init過程可以被移除的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; 
相關問題