2016-03-31 8 views
3

ここでは、2つのAPBインタフェースの配列を持っています:apb_if m_apb_if[0:1]はTBのハーネスとのインタフェースに使用されています。当初、私はこのようなタスクを書いた:インスタンス配列のインデックスが不定

task foo; 
input string DUT_name; 
if (DUT_name == "DUT1") 
    ##1 m_apb_if[0].write... 
else if (DUT_name == "DUT2") 
    ##1 m_apb_if[1].write... 

作品上記のコードが、それの50%が(あれば20に同じことを想像する)冗長です。私はタスクのコードの長さを減らしたかった。私が試した:.WRITEを起動しようとすると、入力としてタスクに

task foo; 
input string DUT_name; 
int dut_number; 
dut_number = set_name_number(DUT_name);//function returning int 
##1 m_apb_if[dut_number].write... //this line fails 

渡すintは同じエラーを与える:

input int dut_name; 

は、配列のインデックスは、それが知らなければならないため、一定でなければならいシミュレーションの開始時に?目標を達成するにはどうすればいいですか?

答えて

3

モジュールとインターフェイスの配列へのインデックスは、定数である必要があります。回避策は、仮想インターフェイスであり、動的インデックスを持ち、実際のインターフェイスを指し示すことができます。

apb_if m_apb_if[0:1](); 
virtual apb_if m_apb_vif[0:1]; 
initial begin : map_physical2virtual 
    m_apb_vif[0] = m_apb_if[0]; // Note: for-loop does not work here 
    m_apb_vif[1] = m_apb_if[1]; // Index to phy-if must a constant 
end : map_physical2virtual 
... 
task foo (input string DUT_name); 
    int dut_number; 
    dut_number = set_name_number(DUT_name);//function returning int 
    ##1 m_apb_vif[dut_number].write... // should work 
endtask : foo 

あなたの仮想インターフェイスは、インデックスちょうどグレッグの答えに追加するDUTの名前

apb_if m_apb_if[0:1](); 
virtual apb_if m_apb_vif[string]; 
initial begin : map_physical2virtual 
    m_apb_vif["DUT1"] = m_apb_if[0]; // Note: for-loop does not work here 
    m_apb_vif["DUT2"] = m_apb_if[1]; // Index to phy-if must a constant 
end : map_physical2virtual 
... 
task foo (input string DUT_name); 
    if(!m_apb_vif.exists(DUT_name) begin 
    // throw error or something 
    end 
    else begin 
    ##1 m_apb_vif[dut_number].write... // should work 
    end 
endtask : foo 
+4

ていると連想配列にすることができます。インスタンスの配列は、各要素が同一の特性を持つ真の配列ではないため、定数で索引付けする必要があります。 'defparam'や' generate'のような構文は、各インデックスを非常に異なるものにすることができます。 Verilog elaborationプロセスは、基本的にすべての階層を平坦化し、配列インデックスのように見える名前を作成しますが、それらは平坦な名前の一部に過ぎません。 –

関連する問題