接口
- interface 可以使用 initial 与 always 也可定义 function 与 task
- 可以在 硬件环境 与 软件环境 传递
interface arb_if(input bit clk); //接口
logic [1 : 0]grant, request;
logic rst;
endinterface
module arb(arb_if arbif);
---
always @(posedge arbif.clk or posedge arbif.rst) begin
if(arbif.rst)
arbif.grant <= 2'b00;
else
arbif.grant <= next_grant;
...
end
endmodule
module test(arb_if arbif); //测试模块
...
initial begin
@(posedge arbif.clk) arbif.request <= 2'b01;
$display ("@%0t: Drove req = 01", $time);
repeat(2) @(posedge arbif.clk);
if(arbif.grant != 2'b01) $display("@%0t: a1: grant != 2'b01", $time);
$finish;
end
endmodule:test
module top; //顶层模块
bit clk;
always #5 clk = ~clk;
arb_if arbif(clk); //通过接口传递
arb a1(arbif);
test t1(arbif);
endmodule: top
通过传递变量名完成变量传递
modport信号分组
interface arb_if(input bit clk);
logic [1 : 0]grant, request;
logic rst;
modport TEST(output request, rst, input grant, clk);
modport DUT(input request, rst, clk, output grant);
modport MONITOR(input request, grant, rst, clk);
endinterface
可以通过 modport 来进一步限定信号传输的方向
如何避免采样的竞争问题?
- 在驱动时,添加相应的人为延迟
- 在采样事件前的某段时刻中进行采用