如何将Modport接口连接到最初使用Modport声明的模块

发布于 2025-02-10 05:11:15 字数 1140 浏览 3 评论 0原文

我有一个最初像这样写的模块:

module design_name #(
  parameter AWIDTH = 32,
  parameter DWIDTH = 32,
  ...
  ) (
  input wire clk,
  input wire rst,
  input wire [AWIDTH-1:0] write_addr,
  ...
);
// logic, etc.
endmodule

当然,我现在想在测试台上测试此块。我想使用一个界面,因此我创建了一个类似的接口:

interface design_name_if #(
  parameter AWIDTH = 32,
  ...
) (
  input clk
);
  logic rst;
  logic [AWIDTH-1:0] write_addr;
  ...
  
  modport des (
    input rst,
    input write_addr,
    ...
  );
endinterface
  

我想我的问题现在开始;如何在测试工作台中使用此界面?我目前有:

module tb;

  reg clk;

  design_name_if intf (clk);

  design_name dut (
    .clk        (intf.clk),
    .rst        (intf.des.rst),
    .write_addr (intf.des.write_addr),
    ...
// I don't think the above is correct

  initial begin
    clk = 0; // or intf.clk = 0; ?
    forever #1 clk = ~clk;
  end

  initial begin
    rst = 0;
    #10
    rst = 1;
  end

endmodule

我还尝试了其他一些简单的逻辑,例如试图断言某些信号和其他内容,但是我什至无法让CLK启动,在运行模拟时,我也无法首先断言。如果重要的话,该接口将在同一文件中的结核病上方声明。我正在测试的模块显然是在另一个文件中。我可以通过将所有信号称为测试工作台内的所有信号,但我想将测试工作台正常工作,但我想使用任务,功能等。任何帮助都可以很好地感谢您!

I have a module that I wrote originally like so:

module design_name #(
  parameter AWIDTH = 32,
  parameter DWIDTH = 32,
  ...
  ) (
  input wire clk,
  input wire rst,
  input wire [AWIDTH-1:0] write_addr,
  ...
);
// logic, etc.
endmodule

I now, of course, want to test this block in a test bench. I want to use an interface so I have created an interface like so:

interface design_name_if #(
  parameter AWIDTH = 32,
  ...
) (
  input clk
);
  logic rst;
  logic [AWIDTH-1:0] write_addr;
  ...
  
  modport des (
    input rst,
    input write_addr,
    ...
  );
endinterface
  

I guess my question starts now; how do I use this interface in my test bench? I currently have:

module tb;

  reg clk;

  design_name_if intf (clk);

  design_name dut (
    .clk        (intf.clk),
    .rst        (intf.des.rst),
    .write_addr (intf.des.write_addr),
    ...
// I don't think the above is correct

  initial begin
    clk = 0; // or intf.clk = 0; ?
    forever #1 clk = ~clk;
  end

  initial begin
    rst = 0;
    #10
    rst = 1;
  end

endmodule

I've also tried some other simple logic, like just trying to assert certain signals and other things, but I can't even get the clk to start, nor can I ever get rst to assert when running the simulation. If it matters, the interface is declared above the tb in the same file. The module I'm testing is, probably obviously, in a different file. I can get the test bench to work without an interface by declaring all the signals as reg and wire within the test bench normally but I wanted to use an interface with tasks, functions, etc. Any help appreciated, thank you!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

关于从前 2025-02-17 05:11:15

你很近。只需摆脱参考中的Modport即可-A Modport不是范围,它是端口连接或虚拟接口参考的一组访问权限。

 design_name dut (
    .clk        (intf.clk),
    .rst        (intf.rst),
    .write_addr (intf.write_addr),
    ...

You were very close. Just get rid of the modport in the reference—a modport is not a scope, it is a set of access rights for a port connection or virtual interface reference.

 design_name dut (
    .clk        (intf.clk),
    .rst        (intf.rst),
    .write_addr (intf.write_addr),
    ...
夜还是长夜 2025-02-17 05:11:15

有几个问题:

  1. 从结构的角度来看,接口只是一堆电线。电线intf.clk与电线clk不同。发布的代码使用永远的循环驱动CLK,但是TestBench将Intf.Clk连接到未驱动的DUT,因此DUT不会看到任何时钟(驱动DUT CLK INPUT PIN的电线没有驱动程序)。此模式也存在于信号/线/变量rst上。

  2. 在测试台上statment

永远#1 clk = 〜clk;

在初始块的中间语句。这将防止同一初始块中的所有其他语句执行。例如,它永远不会执行#10或rst = 1语句。解决方案是使用其他初始块或始终块驱动时钟(无论您选择使用接口或本地声明的时钟)。

  1. 在初始刺激块末尾停止测试没有$完成。该测试台将在无限循环中运行模拟器。初始块需要模板:

     初始
     开始
     <语句>
     $完成;
     结尾
     

以使得测试不会使模拟器卡在循环中。

There are several problems:

  1. From a structural point of view, an interface is just a bunch of wires. The wire intf.clk is different than the wire clk. The posted code drives clk using a forever loop, but the testbench connects intf.clk to the dut which is not driven so the dut will not see any clocks (the wire that drives the dut clk input pin has no driver). This pattern is present on the signal/wire/variable rst also.

  2. In the testbench the statment

forever #1 clk = ~clk;

statement in the middle of the initial block. This will prevent all other statements in the same initial block from executing. For example it will never execute the #10 or rst = 1 statements. The solution is to drive the clock (whatever clock you choose to use the interface or local declaration) using a different initial block or an always block.

  1. There is no $finish to stop the test at the end of the initial stimulus block. This testbench will run the simulator in an infinite loop. The initial block needs the template:

    initial
     begin
     <statements>
     $finish;
     end
    

so that the test does not get the simulator stuck in a loop.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文