systemVerilog的interface(接口)介绍

1 存在问题

两个RTL模块之间可能有几十个连接信号,这些信号必须按照正确的顺序排列以使它们能正确地通信。问题:(1)信号线容易连接错;(2)添加或删除端口,上一层,或上上一层需要修改,比较复杂。

2 例子

2.1 arb_if.sv(接口文件)

interface arb_if(input bit clk)
	logic [1:0] grant,request;
	logic rst;
endinterface 

2.2 arb.sv

//使用了简单接口的仲裁器

# include "arb_if.sv"
module arb(arb_if arbif);
	begin
	if(arbif.rst)
		arbif.grant<=2'b00;
	else
		arbif.grant<=next_grant;
	...
	end
endmodule

2.3 test.sv

//简单仲裁器接口的测试平台

# include "arb_if.sv"
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)
				$dispaly("@%0t:a1:grant!=2'b01",$time);
			$finish;
		end
endmodule

2.4 top.sv

//使用简单仲裁器接口的top模块

# include "arb_if.sv"
module top;
	bit clk;
	always #5 clk = ~clk;
	arb_if arbif(clk);
	arb a1(arbif);
	test t1(arbif);
	endmodule:top

systemVerilog的interface(接口)介绍_第1张图片

说明:'include "arb_if.sv"来应用interface模块

3 modport 接口信号分组

3.1 arb_if.sv接口文件

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 requeset, grant, rst, clk);
endinterface	

3.2 arb.sv

module arb (arb_if.DUT arbif);
...
endmodule

3.3 test.sv

module test (arb_if.TEST arbif);
...
endmodule

你可能感兴趣的:(芯片验证,芯片设计,systemVerilog,interface,接口)