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。

仿真波形如下:

相关推荐
cycf2 小时前
深入浅出通信原理
fpga开发·信息与通信
IM_DALLA19 小时前
【Verilog学习日常】—牛客网刷题—Verilog快速入门—VL21
学习·fpga开发
皇华ameya1 天前
AMEYA360:村田电子更适合薄型设计应用场景的3.3V输入、12A输出的DCDC转换IC
fpga开发
千穹凌帝1 天前
SpinalHDL之结构(二)
开发语言·前端·fpga开发
一口一口吃成大V1 天前
FPGA随记——FPGA时序优化小经验
fpga开发
贾saisai1 天前
Xilinx系FPGA学习笔记(九)DDR3学习
笔记·学习·fpga开发
redcocal2 天前
地平线秋招
python·嵌入式硬件·算法·fpga开发·求职招聘
思尔芯S2C2 天前
高密原型验证系统解决方案(下篇)
fpga开发·soc设计·debugging·fpga原型验证·prototyping·深度调试·多fpga 调试
坚持每天写程序2 天前
xilinx vivado PULLMODE 设置思路
fpga开发
redcocal3 天前
地平线内推码 kbrfck
c++·嵌入式硬件·mcu·算法·fpga开发·求职招聘