【问题标题】:Systemverilog Testbench how to deal with configurable number of interfacesSystemverilog Testbench如何处理可配置数量的接口
【发布时间】:2016-12-29 19:30:39
【问题描述】:

我有一个设计要验证。该设计类似于网络路由器。它具有多个FIFO输入接口和多个FIFO输出接口。所以同一组接口会一遍又一遍地重复。 被测设备示例:

module router(
    input logic [0:NUM_IN] sop_i,
    input logic [0:NUM_IN] eop_i,
    input logic [0:NUM_IN][128:0] data_i,

    output logic [0:NUM_OUT] sop_o,
    output logic [0:NUM_OUT] eop_o,
    output logic [0:NUM_OUT][128:0] data_o,
)
......
endmodule

所以我认为在我的测试平台中,驱动程序的数量也应该是可配置的,因为我想分别驱动每个 FIFO 接口。

interface fifo_intf;
    logic sop;
    logic eop;
    logic [128:0] data
endinterface

所以第一个问题是如何将此接口连接到 DUT。我在看类似的东西

module tb_top;
...
top_intf top_if();

router dut (.sop_i(top_if.connect_if.sop)
            .eop_i(top_if.connect_if.eop),
            .data_i(top_if.connect_if.data))
endmodule

interface connect_intf #(NUM);
    logic [0:NUM-1] sop;
    logic [0:NUM-1] eop;
    logic [0:NUM-1][128:0] data;
endinterface

我还认为将顶级接口包装器传递给 env 可能更容易,因为 FIFO 接口的数量是参数化的。 所以,

interface top_intf:
    fifo_intf fifo_if_input[`NUM_IN]();
    fifo_intf fifo_if_output[`NUM_OUT]();
    connect_intf #(`NUM_IN)connect_if();
endinterface

然后我需要做一些从connect接口到fifo接口的路由

   genvar i;
    generate
        for (i = 0; i < NUM_IN; i++) begin
            assign connect_if.sop[i]   = fifo_if_i[i].sop;
    endgenerate

但是当我将 top_intf 传递到 testbench 环境时会出现一些问题。

class env;
// local interfaces to avoid hierarchical reference??
virtual fifo_intf fifo_if_i[`NUM_IN];
virtual fifo_intf fifo_if_o[`NUM_OUT];

function env::new(virtual top_intf top_vif);
    this.top_vif = top_vif;
    fifo_if_i[0:`NUM_IN-1] = top_vif.fifo_if_input[0:`NUM_IN-1];
    fifo_if_o[0:`NUM_OUT-1] = top_vif.fifo_if_output[0:`NUM_OUT-1];
endfunction: new
endclass;

这适用于NUM_In andNUM_OUT 大于 1。但是当 NUM 为 1 时会出现一些问题。错误是

  Incompatible complex type assignment
  Type of source expression is incompatible with type of target expression. 
  Mismatching types cannot be used in assignments, initializations and 
  instantiations. The type of the target is 'virtual interface 
  fifo_intf$[0:0]', while the type of the source is 'interface fifo_intf'.
  Source Expression: this.top_vif.fifo_if_input[0]

我现在正在做的是设置一些定义来指示 NUM_IN 值是什么,例如

`ifdef PROJ_A
    `define NUM_IN_IS_1
`elsif PROJ_B
    `define NUM_IN_IS_2
`endif

然后

在另一个包含文件中

`ifdef NUM_IN_IS_1
    fifo_if_i[0] = top_vif.fifo_if_input[0];
`elsif NUM_IN_IS_2
    fifo_if_i[0] = top_vif.fifo_if_input[0];
    fifo_if_i[1] = top_vif.fifo_if_input[1];  
`endif 

我认为我们可以使用一些脚本来生成测试台代码,但我正在尝试寻找一种无需编写脚本的方法。我愿意接受建议。您如何处理您的测试平台中的这种设计情况?

非常感谢!

【问题讨论】:

    标签: system-verilog test-bench object-test-bench


    【解决方案1】:

    为避免数组到数组的赋值,请将它们卷入for 循环:

    function env::new(virtual top_intf top_vif);
        this.top_vif = top_vif;
    
        foreach (fifo_if_i[i])
          fifo_if_i[i] = top_vif.fifo_if_input[i];
    
        foreach (fifo_if_o[i])
          fifo_if_o[i] = top_vif.fifo_if_output[i];
    endfunction: new
    

    【讨论】:

    • 感谢您的回答,但我认为这行不通。我以前试过。它报告“在接口 top_intf 中找不到成员 fifo_if_input。我认为您不能索引接口数组。
    • @Shuo 这是合法的语法。您应该向您的工具供应商提出一个案例。
    • 我认为@dave_59 的回答解释了为什么不能使用变量来索引接口数组:stackoverflow.com/questions/40839419/…
    • 我认为如果这种用法很普遍,VCS 应该已经支持它了。
    • @Shao 但答案并没有说不允许。它说明了为什么允许 OP 显示的代码。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多