使用在包内的接口中声明的任务

问题描述

我正在尝试创建一个简单的 SV 测试平台,但当我无法使用在包内的接口中声明的任务时遇到了一个问题,因为无法在包内声明接口。我有以下几点:

定义我的界面:

interface dut_tb_if ();

 task ahb_read();
 endtask

 task ahb_write();
 endtask

endinterface

定义我的测试平台

module dut_tb();

 import dut_tb_pkg::*;

 dut_tb_intf dut_tb_intf();

 dut dut (.......);

endmodule

我的测试平台和测试是顶级模块,所以我的测试看起来像这样:

module dut_test1();

import dut_tb_pkg::*;

initial
begin
 dut_tb.dut_tb.intf.ahb_write(addr,wdata);
 dut_tb.dut_tb.intf.ahb_read(addr,rdata);
end
endmodule

我想在我的包中声明新任务,这些任务使用来自界面的任务,并且可以在测试平台中刺激它。我怎么能在包内完成这个?谁能给我举个例子。

谢谢 NV

解决方法

系统 verilog 提供了 virtual interfaces 来帮助解决这些问题。但是,这需要将指向接口的指针传递给包中​​的任务。下面是一个例子:

package pkg;
 task u(virtual interface A a); // a task in package with a virtual interface in argumetns
  $display("%m in pkg");
  a.t();  // call the task from the interface.
 endtask
endpackage  

interface A;
  task t;
    $display("%m: task in A");
  endtask
endinterface


module top;
  A a();  // instantiate interface
  initial begin
    pkg::u(a); // call the package task and pass the interface pointer to it.
  end
endmodule

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...