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完成仿真。