首页 > 解决方案 > 在模块实例化中输入对另一个模块的引用?(SystemVerilog)

问题描述

我有专用的测试平台模块,用于在我的测试平台中打印/跟踪有关 DUT 的信息。我想避免将所有有趣的(内部)信号连接到 tb 模块。

例如,假设a我的 DUT 中有一个内部信号。如何在printer.sv无需创建匹配输入的情况下访问它?草图:

/---- TB.sv -----------------------------------------\
|                                                    |
|   /--dut.sv--\       /--printer.sv-------------\   |
|   | wire a;  |   ->  | always @(posedge clk)   |   |
|   |          |       | $display("a is %d", a); |   |
|   \----------/       \-------------------------/   |
|                                                    |
\----------------------------------------------------/

我一直在查看bind关键字,看看它是否可以帮助我,但我不明白。

printer.vs 所需的信号数量很大,所以我真的很想避免将所有内容都声明为输入,这非常乏味。

是否有某种方法可以传递对实例化 dut 模块的分层引用?

标签: system-verilog

解决方案


您可以在绑定的打印机模块中使用向上引用。

module DUT(input clk);     
     wire a;
     function void hello;
       $display("Hello from %m");
     endfunction
      
endmodule
    
module printer(input clk);
      always @(posedge clk)
        $display("a is %d", DUT.a);
      initial DUT.hello;
endmodule
    
module TB;
      reg clock;
      DUT d1(clock);
      DUT d2(clock);
      
      bind DUT printer p(clk);
      
endmodule

并不是说向上名称引用是 Verilog 独立于bind. 绑定功能的工作方式与您在 DUT 中编写实例完全一样。这与您可以使用顶级模块名称作为引用开头的原因相同。

module DUT(input clk);     
     wire a;
     function void hello;
       $display("Hello from %m");
     endfunction

      printer p(clk);  // what bind is actually doing

      
endmodule
    
module printer(input clk);
      always @(posedge clk)
        $display("a is %d", DUT.a);
      initial DUT.hello;
endmodule
    
module TB;
      reg clock;
      DUT d1(clock);
      DUT d2(clock);      
endmodule

推荐阅读