【问题标题】:Input a reference to another module in a module instantiation? (SystemVerilog)在模块实例化中输入对另一个模块的引用? (SystemVerilog)
【发布时间】:2021-03-08 15:54:02
【问题描述】:

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

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

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

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

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

有什么方法可以将分层引用传递给实例化的 dut 模块吗?

【问题讨论】:

    标签: system-verilog


    【解决方案1】:

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

    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
    

    【讨论】:

    • 哦,所以打印机模块可以访问已被binded 的 DUT,即使在打印机源代码中看不到它? - 后续问题:如果在没有bind DUT 的情况下实例化打印机会怎样?
    • 绑定如何影响范围?似乎很难将实例化打印机与顶部 TB 中定义的 localparams 绑定,这可能吗?如果有 2 个 DUT 彼此相邻,d1d2,会发生什么情况?打印机内部的引用 DUT.a 将如何解析?
    • 我更新了我的答案以阐明向上引用的工作原理。您应该将其他问题作为带有代码示例的新帖子提出。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-10-20
    • 1970-01-01
    • 1970-01-01
    • 2021-11-27
    • 2017-06-21
    • 2022-07-11
    相关资源
    最近更新 更多