Systemverilog中使用interface连接testbench和dut的端口

1.dut的端口声明如下,文件名为top.v:

复制代码
module top
(
	input 				clk			,
	input 				rst_n		,
	
	input 				wr_n		,
	input 				rd_n		,
	input 				cs0_n		,
	input 				cs7_n		,
	input [15 : 0] 		bus_addr_in	,
	//UART淇″彿
	input 				rx0_d		,
	output 				tx0_d		,		
    );

2.定义interface接口,文件名为top_if.sv;

复制代码
interface  top_if(  input bit 				clk );


	logic 				rst_n		;
		                    
	logic 				wr_n		;
	logic 				rd_n		;
	logic 				cs0_n		;
	logic 				cs7_n		;
	logic [15 : 0] 		bus_addr_in	;
	//UART信号                      
	logic 				rx0_d		;
	logic 				tx0_d		;
   );

3.在testbench模块中连接interface接口与dut的端口,interface与dut的端口连接时,只能按照信号名称一个一个的绑定。接下来就可以在testbench中通过interface的实例引用信号名,来对其进行赋值。这里通过`include "top_if.sv"将接口引进来。

复制代码
`include "top_if.sv"
module tb;
	 bit 				clk			;

	 top_if topif(clk);    //实例化top_if对象,将clk传递给interface
	
	 top   top_inst( .clk(topif.clk),               //将topif接口对象与DUT端口绑定,这里直接按照位置绑定
	                                   .rst_n( topif.rst_n    ),
	                                   .wr_n(topif.wr_n),
                                        .rst_n(topif.rst_n)		,
	                                      .wr_n	(topif.wr_n	)	,
	                                    .rd_n(topif.rd_n)		,
                                        .cs0_n(topif.cs0_n)		,
	                                    .cs7_n	(topif.cs7_n)	,
	                                   . bus_addr_in(topif.bus_addr_in)	,
	                
	                                    .rx0_d (topif.rx0_d)		,
	                                    .tx0_d(topif.tx0_d)			
        );
	initial
		begin
			clk=0; 
			topif.rst_n=0;
			#100 topif.rst_n=1;
			
		end
	
	always #12.5 clk=~clk;
	
	endmodule
相关推荐
fei_sun3 天前
【SystemVerilog】连接设计和测试平台(待补充)
systemverilog
fei_sun13 天前
【SystemVerilog验证】数据类型(待补充)
数据结构·systemverilog
不会武功的火柴14 天前
SystemVerilog语法(11)-面向对象编程下篇
面向对象·fpga·systemverilog·ic验证
Ether IC Verifier18 天前
SystemVerilog 数据类型详解
php·systemverilog·uvm·ic验证
Ether IC Verifier23 天前
IC 验证工程师新手入门指南
systemverilog·ic验证·dpu
Nick.Q23 天前
Ubuntu 24.04 从零跑通 OpenTitan:IC 验证工程师实录(Verilator + VCS + Verdi)
linux·ubuntu·systemverilog
不会武功的火柴1 个月前
SystemVerilog语法(9)-验证基础与简单Testbench
嵌入式硬件·fpga开发·fpga·systemverilog·硬件描述语言·rtl·uvm验证
谷公子的藏经阁2 个月前
DVCon 2025 论文精华导读及下载链接
ai·论文·systemverilog·uvm·dvcon
高新打工人5 个月前
关于systemverilog中的随机化的使用
systemverilog
蓝天下的守望者5 个月前
SystemVerilog中 `timescale的使用问题
systemverilog·uvm·vcs