systemverilog:interface中的modport用法

使用modport可以将interface中的信号分组并指定方向,方向是从modport连接的模块看过来的。简单示例如下:

复制代码
interface cnt_if (input bit clk);
	
	logic rstn;
	logic load_en;
	logic [3:0] load;
	logic [7:0] count;
 
	modport TEST (input  clk, count,
				  output rstn,load_en,load);
	
	modport  DUT  (input clk,rstn,load_en,load,
				  output count);
 
endinterface



module Design(clk,rstn,load_en,load,count );

input clk,rstn,load_en,load;
output reg [7:0] count;


always @(posedge clk or negedge rstn)
	if(!rstn)
		count<=0;
	else 
		count<=count+1;
		

endmodule


class  AA;

virtual cnt_if.DUT this_s;

function new(virtual cnt_if.DUT if_inst);
	this_s=if_inst;
endfunction

task assig();
	this_s.rstn=0;
	
	repeat(100) @(posedge this_s.clk);
		this_s.rstn=1;
		this_s.load_en=0; this_s.load=1; this_s.count='d56;
	
	repeat(100) @(posedge this_s.clk);
		this_s.rstn=0; this_s.load_en=1; this_s.load=0; this_s.count='d34;

endtask


endclass 


module tb;
	logic clk;
	
	initial begin clk=0; end
	
	always #5 clk=~clk;
	
	//cnt_if.DUT if_instance (clk);
	cnt_if if_instance (clk);
	
	AA ainstance=new(if_instance.DUT);
	
	//Design(clk,rstn,load_en,load,count );
	Design design_inst(.clk(if_instance.DUT.clk), .rstn(if_instance.DUT.rstn) ,.load_en(if_instance.DUT.load_en ), .load(if_instance.DUT.load) ,.count(if_instance.DUT.count)  );
	
	initial 
	begin
			ainstance.assig;
	end


endmodule

注意:

(1)在interface中使用modport将信号分组后,在tb中例化时,直接例化interface的实例,不能例化interface中modport的实例;

(2)在calss中直接例化interface中modport的实例;

(3)在tb中实例化interface的实例后,将interface的实例的modport通过点运算符传递给DUT。

仿真波形如下:

相关推荐
Szime7 小时前
全球首创10位40GSPS超宽带ADC选型参考:国产超高速ADC深智微科技选型支持
科技·单片机·嵌入式硬件·fpga开发
Szime13 小时前
AD9653、AD9253、AD9694国产替代怎么评估?深智微科技整理ADI高速ADC选型思路
科技·fpga开发
FPGA小徐13 小时前
Xilinx zynq-7000系列FPGA移植Linux操作系统详细教程
fpga开发·架构
Zebros15 小时前
LC无线无源传感器读取方案设计研究综述
fpga开发·信息与通信·射频工程
国科安芯17 小时前
商业航天通信载荷数字处理单元供电架构研究——基于ASP7A84AS的高精度低压差线性稳压器技术分析
前端·单片机·嵌入式硬件·fpga开发·架构·安全性测试
Szime18 小时前
AD9653 国产替代怎么选?四通道 16 位 125MSPS ADC 选型参考
嵌入式硬件·fpga开发
cjie22119 小时前
常用视频缩放架构
fpga开发·架构
尤老师FPGA20 小时前
LVDS系列51:Xilinx Ultrascale系 ADC LVDS接口参考方法(十三)
fpga开发
Eloudy1 天前
NVIDIA Holoscan Sensor Bridge 简介
fpga开发·量子计算
XINVRY-FPGA1 天前
XC7A100T-2CSG324I AMD Xilinx Artix-7 FPGA
arm开发·人工智能·嵌入式硬件·神经网络·fpga开发·硬件工程·fpga