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。

仿真波形如下:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值