参数化的Interfaces和可重用VIP(3/3)

本篇是讨论SystemVerilog接口和接口参数化处理策略的三部分系列的第三部分。

在本系列的第一部分中,介绍了SystemVerilog接口的基本概念,并描述了这些接口的参数化会引入testbench代码的问题。在第二部分,描述了使用访问者类来屏蔽VIP代码与参数化效果的方法,但是该解决方案对VIP访问该接口施加了新的限制。在本系列的最后一篇文章中,介绍了一个允许测试平台使用参数化接口的过程,而不对VIP可以访问其提供的接口的方式施加任何限制。

最大足迹:两全其美

使用当今现有的SystemVerilog功能无法解决参数化接口引入动态测试平台代码的问题。因此,我们必须设计一种方法来避免将这些参数暴露给VIP代码。本系列的前一篇文章介绍了实现此目的的accessor类。另一种解决方案是定义VIP可以与之交互的最大占用空间样式接口,以及一个参数化接口,它包装最大占用空间接口并连接到最大占用空间接口所需的信号。

最大占用空间类型接口定义每个信号的最大宽度,并且可以配置各个VIP组件以利用来自这些信号的切片。这允许多个具有不同宽度的VIP实例,并且不需要参数化类来使用参数化接口。以下代码段演示了这些概念。

首先,我们定义最大足迹样式接口。请注意,此接口未参数化,因为这是VIP代码将与之交互的接口:

// Redefinable max footprint
`ifndef MAX_DATA_WIDTH
 `define MAX_DATA_WIDTH 32
`endif
 
interface max_footprint_if;
  logic clk;
  logic[`MAX_DATA_WIDTH-1:0] data_in;
  logic[`MAX_DATA_WIDTH-1:0] data_out;
 
  clocking active_cb @(posedge clk);
    default input #1 output #1;
    input data_in;
    output data_out;
  endclocking
 
  modport active_mp (clocking active_cb);
endinterface
 
typedef virtual max_footprint_if max_footprint_vif;

接下来,定义参数化接口,用于包装最大足迹接口:

interface param_if#(int width = 8);
  logic clk;
  logic[width-1:0] data_in;
  logic[width-1:0] data_out;
 
  max_footprint_if internal_if();
 
  assign internal_if.clk = clk;
 
  // Z values driven on unused inputs of the max footprint
  assign internal_if.data_in = {`MAX_DATA_WIDTH'hz, data_in};
 
  // Only selected output values used from the max footprint
  assign data_out = internal_if.data_out[width-1:0];
endinterface

在此之后,实现VIP代码以使用最大足迹接口而不是参数化接口。下面显示的另一个类(未在前面的帖子中显示)是配置类,用于定义每个VIP实例的信号宽度。该解决方案产生的另一个复杂因素是VIP在采样和驱动信号时必须使用比特技术。这很不幸,但SystemVerilog语法强大,可以解决这个问题。

  //=======================================================================
  class cust_cfg extends uvm_object;
    rand int data_width;
    constraint valid_data_width {
      data_width inside {8, 16, 32};
    }
…
 
  //=======================================================================
  class cust_driver extends uvm_driver#(cust_data);
    max_footprint_vif vif;
    cust_cfg cfg;
 
    `uvm_component_utils(cust_driver)
 
    function void build_phase(uvm_phase phase);
      if (!uvm_config_db#(max_footprint_vif)::get(this, "", "vif", vif))
        `uvm_fatal("build", "A valid virtual interface was not received.");
      if (!uvm_config_db#(cust_cfg)::get(this, "", "cfg", cfg))
        `uvm_fatal("build", "A valid configuration was not received.");
…
 
    task consume_from_seq_item_port();
        seq_item_port.get_next_item(req);
        vif.active_cb.prop_out <= ((req.prop <> (`MAX_DATA_WIDTH-cfg.data_width));
        @(vif.active_cb);
…
 
    task sample_signals();
        bit[31:0] sampled_prop_in = ((vif.active_cb.prop_in <> (`MAX_DATA_WIDTH-cfg.data_width));
VM_LOW);
        @(vif.active_cb);
…
 
  //=======================================================================
  class cust_agent extends uvm_agent;
    `uvm_component_utils(cust_agent)
 
    max_footprint_vif vif;
    cust_driver driver;
 
    function void build_phase(uvm_phase phase);
      if (!uvm_config_db#(max_footprint_vif)::get(this, "", "vif", vif))
        `uvm_fatal("build", "A valid virtual interface was not received.");
      if (!uvm_config_db#(cust_cfg)::get(this, "", "cfg", cfg))
        `uvm_fatal("build", "A valid configuration was not received.");
 
      uvm_config_db#(max_footprint_vif)::set(this, "driver", "vif", vif);
      uvm_config_db#(cust_cfg)::set(this, "driver", "cfg", cfg);
      driver = cust_driver::type_id::create("driver", this);
…

最后,介绍了测试平台代码。测试用例可以在不参数化的情况下访问VIP,并且实例化接口的顶层模块可以使用参数化接口。还显示了为每个VIP实例创建配置对象的附加步骤(这不是一个额外的步骤,因为早期的解决方案也需要这样做,但为了简洁而省略了)。

利用最大足迹样式接口进行VIP访问信号,可以创建VIP代码,而无需参数化VIP代码。定义参数化接口允许测试平台利用它们启用的改进的集成功能。使用参数化接口来包装最大足迹接口的策略可以实现两种样式的优势。

//=======================================================================
class cust_test extends uvm_test;
  cust_cfg cfg8;
  cust_cfg cfg16;
  cust_cfg cfg32;
 
  cust_agent agent8;
  cust_agent agent16;
  cust_agent agent32;
 
  virtual function void build_phase(uvm_phase phase);
    cfg8 = new("cfg8");
    cfg8.data_width = 8;
    uvm_config_db#(cust_cfg)::set(this, "agent8", "cfg", cfg8);
    agent8 = cust_agent::type_id::create("agent8", this);
 
    cfg16 = new("cfg16");
    cfg16.data_width = 16;
    uvm_config_db#(cust_cfg)::set(this, "agent16", "cfg", cfg16);
    agent16 = cust_agent::type_id::create("agent16", this);
 
    cfg32 = new("cfg32");
    cfg32.data_width = 32;
    uvm_config_db#(cust_cfg)::set(this, "agent32", "cfg", cfg32);
    agent32 = cust_agent::type_id::create("agent32", this);
  endfunction
endclass
 
//=======================================================================
module test_top;
  param_if#(8) if8();
  param_if#(16) if16();
  param_if#(32) if32();
 
  initial begin
 
    uvm_config_db#(max_footprint_vif)::set(uvm_root::get(), "uvm_test_top.agent8", "vif", if8.internal_if);
    uvm_config_db#(max_footprint_vif)::set(uvm_root::get(), "uvm_test_top.agent16", "vif", if16.internal_if);
    uvm_config_db#(max_footprint_vif)::set(uvm_root::get(), "uvm_test_top.agent32", "vif", if32.internal_if);
 
    run_test("cust_test");
  end
endmodule

 

  • 0
    点赞
  • 16
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值