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。

仿真波形如下:

相关推荐
小眼睛FPGA10 小时前
【紫光HiYou开源入门轻量级PCIE开发板PG2L25G】实验例程1-基于紫光FPGA 的LED 流水灯
fpga开发
不会武功的火柴10 小时前
SystemVerilog语法(8)-有限状态机(FSM)
嵌入式硬件·fpga开发·自动化·ic验证·rtl·uvm方法学
Kent Gu12 小时前
Lattice FPGA选型
fpga开发
Terasic友晶科技15 小时前
答疑解惑|为DE25-Nano开发板配置Linux kernel时.config文件没有起作用是什么原因?
linux·服务器·fpga开发·linux kernel·de25-nano
8K超高清18 小时前
CCBN展会多图回顾
人工智能·算法·fpga开发·接口隔离原则·智能硬件
小眼睛FPGA18 小时前
【紫光HiYou开源入门轻量级PCIE开发板PG2L25G】实验例程5-DDR3 读写实验例程
fpga开发
unicrom_深圳市由你创科技19 小时前
如何做FPGA的功耗优化?动态功耗管理怎么实现?
fpga开发
不会武功的火柴19 小时前
SystemVerilog语法(9)-验证基础与简单Testbench
嵌入式硬件·fpga开发·fpga·systemverilog·硬件描述语言·rtl·uvm验证
kaizq19 小时前
MuleRun助力MakerChip-FPGA在线编程模拟仿真操练
fpga开发·verilog·龙虾机器人·mulerun·makerchip·在线模拟仿真
c-u-r-ry3019 小时前
vivado处理硬件设计差分对布线极性翻转的问题
经验分享·fpga开发