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。

仿真波形如下:

相关推荐
szxinmai主板定制专家25 分钟前
【飞腾AI加固服务器】全国产化飞腾+昇腾310+PCIe Switch的AI大模型服务器解决方案
运维·服务器·arm开发·人工智能·fpga开发
GateWorld35 分钟前
《从零掌握MIPI CSI-2: 协议精解与FPGA摄像头开发实战》-- CSI-2 协议详细解析 (三)数据格式
fpga开发·mipi csi2
hahaha60164 小时前
FPGA静态功耗
fpga开发
碎碎思4 小时前
FPGA定点和浮点数学运算-实例对比
fpga开发
GateWorld16 小时前
《从零掌握MIPI CSI-2: 协议精解与FPGA摄像头开发实战》-- CSI-2 协议详细解析LLP (二)
fpga开发·mipi csi2
hahaha60161 天前
Xilinx 325T FPGA 中的 GT(GTP 或 GTX)收发器和普通 LVDS 接口的差模和共模电压
fpga开发
hahaha60161 天前
FPGA没有使用的IO悬空对漏电流有没有影响
fpga开发
贝塔实验室2 天前
FPGA 动态重构配置流程
驱动开发·fpga开发·硬件架构·硬件工程·射频工程·fpga·基带工程
GateWorld2 天前
《从零掌握MIPI CSI-2: 协议精解与FPGA摄像头开发实战》-- CSI-2 协议详细解析 (一)
fpga开发·mipi csi2
思尔芯S2C2 天前
思尔芯携手Andes晶心科技,加速先进RISC-V 芯片开发
人工智能·科技·fpga开发·risc-v·debugging·prototyping·soc validation