目录
1 接口
接口是什么
接口(interface)是连接设计和测试平台的一个"插排",可以用作设计,也可用作验证;
接口的优势
- 将有关信号封装在同一个接口中,对于设计和验证环境都便于维护和使用。
- interface是SV中唯一的硬件和软件环境的媒介交互。
- 接口可以例化,使得对于多组相同的总线,在例化和使用时变得更加灵活。
接口的使用
- 在inteface端口列表中只需定义时钟、复位等公共信号,或者不定义任何端口,推荐使用logic定义变量。
- interface也可以依靠函数参数化方式提供复用性。
- interface在例化时,同module例化方式一样。
- 模块里面可以例化模块,也可以例化interface,interface里面可以例化interface但不能例化module。
实例说明(接口使用三步骤)
- 定义接口,Dut调用interface
interface arb_if(input bit clk);
logic [1:0] grant,request;
logic rst;
endinterface
module arb (arb_if arbif); //接口传入模块中
...
always @ (posedge arbif.clk or negedge arbif.rst) begin
if (arbif.rst)
arbif.grant <= 2'b00;
else
arbif.grant <= next_grant;
...
end
endmodule
- Test调用interface
module test (arb_if arbif);
...
initial begin
@(posedge arbi