接口
接口是硬件与软件环境的媒介
接口的定义
接口定义与module类似
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 top;
bit clk;
always #5 clk = ~clk;
arb_if arbif(clk) ;//例化
arb a1(arbif) ;
test t1(arbif) ;
endmodule:top
chnl_intf chnl0_if(.*);//
接口的驱动与采样
时钟块的定义与含义
clocking bus@(posedge clock1) ;//定义了一个clocking块bus,由clock1的上升沿来驱动和采样。
default input #10ns output #2ns//clocking块中所有的信号,默认情况下会在clocking事件(clock1上升沿)的前10ns来对其进行输入采样,在事件的后2ns对其进行输出驱动。
input data, ready, enable;//它们的采样事件采用默认输入事件(clock1上升沿前的10ns)
output negedge ack ;声明了要驱动的ack信号。而驱动该信号的事件是时钟clock1的下降沿,即覆盖了原有的默认输出事件(Clock1上升沿后的2ns)。
input #1step addr ;//采用了自身定义的采样事件,即clock1上升沿前的1step。这里的1step会使得采样发生在clock1上升沿的上一个时间片采样区域,即可以保证采样到的数据是上一个时钟周期的数据。
endclocking
使用时钟块的接口
interface arb_if(input bit clk);
logic [1:0] grant,request;
logic rst;
clocking cb @(posedge clk);//声明cb
output request;
input grant;
endclocking
//========使用modport对接口信号分组============//
modport TEST(clocking cb,output grant);//使用cb
modport DUT (intput request,rst,output grant);
通过时钟块驱动信号
时钟块中使用modport时,任何同步接口信号必须加上接口名(arbif)和时钟块名(cb)的前缀
program automatic test(arb.TEST arbif);
initial begin
arbif.cb.request <= 2'b01;
$display("@%0t:Drove req = 01",$time);
repeat(2) @arbif.cb;
if(arbif.cb.grant != 2'b01)
$display("@0t:a1:grant != 2'b01",$time);
end
endprogram:test
结束仿真
$ finish:结束仿真
$ stop:暂停仿真
program隐式结束:内置$exit()
细节问题
logic:数据类型;wire:类型
wire -> wire logic
reg -> (var) logic