system verilog後續複習(一)

一、interface
首先在testbench中使用.name(wire_name)進行信號之間的連接
在這裏插入圖片描述
sv中信號的連接方式:
1、.*(名字和位寬以及數據類型需要相同)

module top;
	logic [1:0] grant,request;
	logic clk,reset;
	arb_port	a1(.*);
	test 	    t1(.*);
endmodule

2、.name 與 1 可以起到同樣的作用

module top;
	logic [1:0] grant,request;
	logic clk,reset;
	arb_port	a1(.grant,.request,.reset,.clk);
	test 	    t1(.grant,.request,.reset,.clk);
endmodule

使用interface(作爲一種類型)進行連接:

interface arb_if(input clk);
	logic [1:0] grant,request;
	logic reset;
endinterface
module top;
	bit clk;
	always #5 clk=~clk;
	arb_if  arbif(clk);
	arb_port a1(arbif);
	test b1(arbif);
endmodule:top

如果需要在tb中使用interface:

module tb(arb_if arbif);
initial
begin
	@(posedge arbif.clk);
	arbif.request<=2'b01;
	repeat(2) @(posedge arbif.clk);
	if(arbif.grant=2'b11)
	$display("%0d:a1:grant=2'b11",$time);
	$finish;
end
endmodule

可以使用modport增加interface的方向性,增加input,output以及inout

interface arb_if(input bit clk);
	logic [1:0] request,grant;
	logic reset;
modport TEST(input grant,input clk,output request,output reset);
modport DUV(input request,input clk,input reset,output grant);
endinterface
module arb_port (arb_if.DUV arbif);
endmodule

module test(arb_if.TEST arbif);
endmodule

需要在合適的時間點驅動和接收同步信號,避免競爭以及信號的錯位;
=>clocking block(將異步信號變爲同步信號)
將信號同步,保證測試平臺在正確的時間點與信號交互,一般用於testbench中,一個interface也能包含多個clocking block
從DUV輸出到testbench輸入有一個默認#1的延遲,從testbench輸出到DUV輸入沒有延遲(default input #1step output #0)
在這裏插入圖片描述
skew=> (在時鐘沿之前採樣,在時鐘沿之後驅動)

clocking dram @(clk)
input #1 address;
output #6 data;
endclocking

在這裏插入圖片描述
clocking block實際使用:

interface arb_if(input bit clk);
	logic[1:0] request,grant;
	logic reset;
clocking cb@(posedge clk);
	default input #1 output #0;
	input grant;
	output request;
endclocking
modport TEST(clocking cb,output reset);
modport DUT(input reset,input request,output grant);
endinterface

但是注意一下:arbif.cb.grant與arbif.grant不同(異步與同步)

module TEST(arb_if arbif);
initial
begin
	arbif.cb.request<=2'b01;//all drives must use non-blocking
if(arbif.cb.grant==2'b01)
$display("%0d,"grant==01",$time);
endmodule
@(arbif.cb) //clock edge from arbif
repeat(3) @(arbif.cb)//wait for 3 posedge

@(arbif.cb.grant)
@(posedge arbif.cb.grant)
@(nededge arbif.cb.grant)
wait(arbif.cb.grant=1)

#1 //1 timescale
##1 //1 cycle

timing regions:
在這裏插入圖片描述
注意:
(1)接口信號採樣:從時鐘塊讀取一個信號時,是在時鐘沿前得到採樣值,postpone sample。
(2)接口信號驅動:如果測試平臺在時鐘有效沿之後驅動輸出,那麼直到時鐘的下一個有效沿纔會被設計所捕獲。

program block:(在program中不能使用always塊,加入always塊仿真將永不結束,在reactive中執行,隱含$finish)
sv tb的執行代碼在一個program block中(program類似於module,包含數據和變量,能夠被其他module例化;program 不能有module和interface的例化)

program test(arb_if.TEST arbif)
intial
begin
//asyn drive
	arbif.reset<=0;
#10 arbif.reset<=1;
#15 arbif.reset<=0;
//syn drive
	arbif.cb.request<=1;
	##1 arbif.cb.request<=0;
wait(arbif.cb.grant==1);
end
endprogram
interface arb_if(input bit clk);
	logic grant,request;
	logic reset;
clocking cb@(posedge clk);
	input grant;
	output request;
endclocking
modport TEST(clocking cb,output reset);
endinterface
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章