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
相关推荐
hh1992031 个月前
systemverilog中的DPI-C用例介绍
c语言·systemverilog·dpi-c
逍遥xiaoy4 个月前
SystemVerilog测试框架示例
systemverilog·uvm
谷公子的藏经阁4 个月前
设计模式在芯片验证中的应用——迭代器
设计模式·systemverilog·uvm·芯片验证·design pattern
wjh776a685 个月前
基于PCIE4C的数据传输(三)——使用遗留中断与MSI中断
linux·fpga开发·systemverilog·xilinx·pcie
wjh776a687 个月前
【RS422】基于未来科技FT4232HL芯片的多波特率串口通信收发实现
fpga开发·verilog·systemverilog·xilinx·rs422
一只迷茫的小狗9 个月前
systemverilog/verilog文件操作
systemverilog
apple_ttt10 个月前
SystemVerilog学习(0)——目录与传送门
fpga开发·fpga·systemverilog·芯片验证
一只迷茫的小狗1 年前
systemverilog:interface中端口方向理解
systemverilog
apple_ttt1 年前
SystemVerilog学习(8)——包的使用
fpga开发·fpga·systemverilog·芯片验证
apple_ttt1 年前
SystemVerilog学习 (10)——线程控制
fpga开发·fpga·systemverilog·芯片验证