Interface:SV中新定义的接口方式,用来简化接口链接,使用时注意在module或program以外定义interface,而后经过'include来添加进工程。接口
interface arb_if(input bit clk); //clk信号,通常单独拿出来input
logic [1:0]grant, request; //只定义信号类型。类型在不一样的modport中分别定义。it
logic rst;io
clocking cb @(posedge clk); //定义时钟块,其中的信号都是clk上升沿有效test
output request;基础
input grant;module
enclockingsed
modport TEST (clocking cb, output rst); //直接引用clocking, 在定义rst的方向request
modport DUT (input request, rst, output grant); //定义各个信号的方向引用
endinterface
module test(arb_if.TEST arbif);
initial begin
arbif.cb.request <= 0; //直接引用clocking中的信号,并且clock blocking中的信号,最好使用<=非阻塞赋值。
@arbif.cb; //至关于@posedge clk
$display("");
end
endmodule
interface能够直接与verilog-2001的端口进行链接:
module top;
bit clk;
always #5 clk = ~clk;
arb_if arbif(clk);
arb_port a1(.grant(arbif,grant),
.request(arbif.request),
.rst(arbif.rst),
.clk(arbif.clk) );
test t1(arbif);
endmodule:top
Program:主要是为了在逻辑和仿真时间上,区分开RTL与验证平台。在SV搭建的验证环境中,testcase通常就定义一个program来开始执行。
program中不能使用always,由于program相比较来讲,与C语言更靠近一些。因此多用initial就能够。program中的仿真时间与RTL中的是有区别的,
SV将同一仿真时刻分为四个区域,Active(design), Observed(assertion), Reactive(testbench), Postponed(sample)。至关于在原verilog的基础
上又为program增长了一个执行区间,一个采样区间。因此clk的定义不能放在program中。当program中的initial结束时,SV会调用$finish完成仿真。