为什么在接口中使用端口?

发布于 2025-01-16 22:05:23 字数 374 浏览 1 评论 0原文

SystemVerilog LRM (IEEE 1800-2017) 对接口中的端口进行了如下描述:

简单接口的一个限制是接口中声明的网络和变量仅用于连接到具有相同网络和变量的端口。要共享外部网络或变量(从接口外部建立连接以及与实例化该接口的所有模块端口形成公共连接),需要接口端口声明。接口端口列表中的网络或变量与接口内的其他网络或变量的区别在于,在实例化接口时,只有端口列表中的网络或变量才能通过名称或位置与外部连接。接口端口声明语法和语义与模块相同(参见23.2.2)。

第一句话到底说了什么?我没有看到限制。

在第二句中,外部信号的示例是什么?如何决定信号应该在接口内部声明还是作为接口的端口声明? LRM 中使用的文本不适合我。

The SystemVerilog LRM (IEEE 1800-2017) describes ports in interfaces as follows:

One limitation of simple interfaces is that the nets and variables declared within the interface are only used to connect to a port with the same nets and variables. To share an external net or variable, one that makes a connection from outside the interface as well as forming a common connection to all module ports that instantiate the interface, an interface port declaration is required. The difference between nets or variables in the interface port list and other nets or variables within the interface is that only those in the port list can be connected externally by name or position when the interface is instantiated. Interface port declaration syntax and semantics are the same as those of modules (see 23.2.2).

What is the first sentence saying exactly? I don't see the limitation.

In the second sentence, what is an example of an external signal? How do you decided whether a signal should be declared inside the interface or as a port to the interface? The text used in the LRM just doesn't click for me.

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

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

发布评论

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

评论(1

烟酒忠诚 2025-01-23 22:05:23

该问题通过 simple_bus 示例显示,该示例遵循 IEEE 1800-2017 SystemVerilog LRM 部分你引用了。

接口 sb_intf1sb_intf2 有两个实例,每个实例创建一组唯一的内部信号(req、int、...)。如果clk也被声明为内部信号,那么也会有两个时钟信号。示例中未显示生成时钟信号的代码。它可能位于 top 模块或其他模块中。他们需要添加连续的分配,以便将生成的时钟信号发送到每个接口实例中的每个内部clk

通过将共享信号放入接口的端口声明中,可以更轻松地连接公共信号。

interface simple_bus (input logic clk); // Define the interface
  logic req, gnt;
  logic [7:0] addr, data;
  logic [1:0] mode;
  logic start, rdy;
endinterface: simple_bus
module memMod(simple_bus a); // Uses just the interface
  logic avail;
  always @(posedge a.clk) // the clk signal from the interface
    a.gnt <= a.req & avail; // a.req is in the 'simple_bus' interface
endmodule
module cpuMod(simple_bus b);
  ...
endmodule
module top;
  logic clk = 0;
  simple_bus sb_intf1(clk); // Instantiate the interface
  simple_bus sb_intf2(clk); // Instantiate the interface
  memMod mem1(.a(sb_intf1)); // Reference simple_bus 1 to memory 1
  cpuMod cpu1(.b(sb_intf1));
  memMod mem2(.a(sb_intf2)); // Reference simple_bus 2 to memory 2
  cpuMod cpu2(.b(sb_intf2));
endmodule

The problem is shown with the simple_bus example that follows the section of the IEEE 1800-2017 SystemVerilog LRM you quoted.

There are two instances of the interface sb_intf1 and sb_intf2 each creating a unique set of internal signals (req, int, ...). If clk had also been declared as internal signal, there would also be two clock signals. What's not shown in the example is the code generating the clock signal. That could have been in the top module or another module. They would have needed to add continuous assignments to get the generated clock signal to each the internal clk in each interface instance.

By putting the shared signals in the interface in their port declarations, it makes it much easier to join the common signals.

interface simple_bus (input logic clk); // Define the interface
  logic req, gnt;
  logic [7:0] addr, data;
  logic [1:0] mode;
  logic start, rdy;
endinterface: simple_bus
module memMod(simple_bus a); // Uses just the interface
  logic avail;
  always @(posedge a.clk) // the clk signal from the interface
    a.gnt <= a.req & avail; // a.req is in the 'simple_bus' interface
endmodule
module cpuMod(simple_bus b);
  ...
endmodule
module top;
  logic clk = 0;
  simple_bus sb_intf1(clk); // Instantiate the interface
  simple_bus sb_intf2(clk); // Instantiate the interface
  memMod mem1(.a(sb_intf1)); // Reference simple_bus 1 to memory 1
  cpuMod cpu1(.b(sb_intf1));
  memMod mem2(.a(sb_intf2)); // Reference simple_bus 2 to memory 2
  cpuMod cpu2(.b(sb_intf2));
endmodule
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文