2016-04-06 173 views
2

我試圖將一個接口傳遞給一個接口數組。systemverilog - >從實例化另一個接口的接口傳遞參數

interface front_port #(parameter DATA_WIDTH = 4); 
     logic [DATA_WIDTH - 1 : 0] data; 
     logic       acknowledge; 

     modport f_interface(input data, output acknowledge); 
endinterface 

interface front_interface #(parameter NO_OF_IN_PORTS = 3); 
     front_port front_ports[NO_OF_IN_PORTS](); 
endinterface 

module A #(parameter NO_OF_IN_PORTS = 3) 
(
    interface front_port; 
); 

module testbench; 
    font_interface #(.NO_OF_IN_PORTS(3)) my_front_interface(); 

    A #(.NO_OF_IN_PORTS(3)) (.front_port(my_front_interface)); 
endmodule 

所以,我的問題是,可以my_front_interface的數組元素有DATA_WIDTH的不同值。如果是這樣,怎麼樣?在my_front_interface的所有數組元素上面定義的代碼有4

感謝

+0

您能夠確保使用嵌套模塊?實例化模塊'A'時,輸入參數是'front_interface'類型的'my_front_interface',而實例'my_front_interface'是'front_interface'類型,模塊聲明可能類似於'module A ...(front_interface fr_if)'。 – sharvil111

+0

關於變量'DATA_WIDTH',而不是簡單地創建實例數組,您需要一個'generate'模塊來創建具有不同數據寬度參數的多個實例。請參閱[此鏈接](http://www.asic-world.com/verilog/verilog2k2.html)和[此問題](http://stackoverflow.com/questions/17734329/system-verilog-parameters-in-生成「塊)的」生成「塊示例。 – sharvil111

+0

好的。謝謝。如果是這種情況,我如何將生成的具有不同數據寬度參數的實例分配給front_interface? –

回答

3

從我的意見繼默認DATA_WIDTH,似乎有很多編譯錯誤在給定的代碼。然而,根據我的理解,我試圖解決它們。

爲了營造不同DATA_WIDTH情況下,接口front_interface必須得到有關在各種情況下DATA_WIDTH信息。所以,添加一個參數front_interface實體的數組。該陣列的大小NO_OF_IN_PORTS參數確定。

此外,您必須使用generate塊創建多個實例front_port。每個實例從front_interface實體的參數陣列中拾取一個元素。

我已經創建以下代碼覆蓋缺省值DATA_WIDTH並創建獨特數據寬度實例。

interface front_port #(parameter DATA_WIDTH = 4); 
    logic [DATA_WIDTH - 1 : 0] data; 
    logic       acknowledge; 

    modport f_interface(input data, output acknowledge); 

    initial 
    begin : DEBUG_DISPLAY 
     $display("DATA_WIDTH for %m is %0d",DATA_WIDTH); 
    end 
endinterface 

// Use array DATA_WIDTH here, for varying data widths. 
interface front_interface #(parameter NO_OF_IN_PORTS = 3, int DATA_WIDTH[NO_OF_IN_PORTS] = '{1,2,3}); 
    genvar i; 
    generate // generate block for multiple instances 
    begin : MULTIPLE_INSTANCES 
     for(i=0;i<NO_OF_IN_PORTS;i++) 
     begin : UNIQUE_DATA_WIDTH 
      // Pick up each element from array to create varying DATA_WIDTH instances 
      front_port #(.DATA_WIDTH(DATA_WIDTH[i])) front_ports(); 
     end 
    end 
    endgenerate 
endinterface 

module A #(parameter NO_OF_IN_PORTS = 3) 
      (front_interface fi_if); 
endmodule 

module testbench; 

    // Override DATA_WIDTH here for different instances 
    front_interface #(.NO_OF_IN_PORTS(3), .DATA_WIDTH('{4,5,6})) my_front_interface(); 

    A #(.NO_OF_IN_PORTS(3)) a1(my_front_interface); 

endmodule 

輸出

DATA_WIDTH for testbench.my_front_interface.MULTIPLE_INSTANCES.UNIQUE_DATA_WIDTH[0].front_ports.DEBUG_DISPLAY is 4 
DATA_WIDTH for testbench.my_front_interface.MULTIPLE_INSTANCES.UNIQUE_DATA_WIDTH[1].front_ports.DEBUG_DISPLAY is 5 
DATA_WIDTH for testbench.my_front_interface.MULTIPLE_INSTANCES.UNIQUE_DATA_WIDTH[2].front_ports.DEBUG_DISPLAY is 6 

參見this page傳遞的參數陣列中的一個實體。另外,SystemVerilog IEEE 1800-2012第27部分對generate塊有幫助。

+0

解決了我的問題。非常感謝。 –

+0

我很努力地訪問模塊A中的front_interface(fi_if)。什麼是語法?它不應該是** fi_if.MULTIPLE_INSTANCES.UNIQUE_DATA_WIDTH [0] .front_ports.data **? –

+0

哦,是的。在[2.5節Sutherland論文](http://www.sutherland-hdl.com/papers/2006-SNUG-Boston_standard_gotchas_paper.pdf)中討論過的未命名的生成塊範圍似乎存在**錯誤。從'testbench'中刪除'begin:MULTIPLE_INSTANCES ..end',並使用'my_front_interface.UNIQUE_DATA_WIDTH [i] .front_ports.DATA_WIDTH'。對於從模塊A訪問,'fi_if.UNIQUE_DATA_WIDTH [i] .front_ports.DATA_WIDTH'應該可以工作,但我很困惑,爲什麼它不工作**。 – sharvil111

0

是的,它會根據DATA_WIDTH創建data,默認爲4位。

檢查下面的代碼,輸出它。 (在代碼中,2個接口陣列具有不同的參數值,f & f5被實例化在front_interface,讓事情更加清楚

interface front_port #(parameter DATA_WIDTH = 4); 
    logic [DATA_WIDTH - 1 : 0] data; 
    logic acknowledge; 

    modport f_interface(input data, output acknowledge); 
endinterface 

interface front_interface #(parameter NO_OF_IN_PORTS = 3); 
    // To create array of front_port 
    front_port f[NO_OF_IN_PORTS - 1 : 0](); // data should be 4 bits wide 
    front_port #(5) f5[NO_OF_IN_PORTS - 1 : 0](); // data should be 5 bits wide 
endinterface 

module A #(parameter NO_OF_IN_PORTS = 3) (front_interface x); 
    initial 
    begin 
     $display ("Size of x.f[%0d].data = %0d", 0, $size(x.f[0].data)); 
     $display ("Size of x.f[%0d].data = %0d", 1, $size(x.f[1].data)); 
     $display ("Size of x.f[%0d].data = %0d", 2, $size(x.f[2].data)); 

     $display ("Size of x.f5[%0d].data = %0d", 0, $size(x.f5[0].data)); 
     $display ("Size of x.f5[%0d].data = %0d", 1, $size(x.f5[1].data)); 
     $display ("Size of x.f5[%0d].data = %0d", 2, $size(x.f5[2].data)); 
    end 
endmodule 


module testbench(); 
    front_interface #(3) my_front_interface(); 

    A #(3) (my_front_interface); 
endmodule 

和代碼的輸出:

Size of x.f[0].data = 4 
Size of x.f[1].data = 4 
Size of x.f[2].data = 4 
Size of x.f5[0].data = 5 
Size of x.f5[1].data = 5 
Size of x.f5[2].data = 5 
+0

'front_port'的實例數將由參數NUM_OF_IN_PORTS控制。 – rahulcodesinverilog

+0

是的,這正是我所做的。 'front_port#(5)f5 [NO_OF_IN_PORTS - 1:0]()'將根據參數NO_OF_IN_PORTS創建front_port的實例 –

+0

my_front_interface的數組**元素**是否具有不同的DATA_WIDTH值?根據OP的問題?我認爲這將會創建一個DAAT_WIDTH值相同的實例數組(4)。然後你又用DATA_WIDTH(5)創建了一個不同的實例數組。 OP的意圖是具有不同數據寬度的單個數組實例。 – rahulcodesinverilog