interface笔记二,SV中使用interface

1.首先interface模块没有变化

interface cnt_if (input bit clk);
	
	logic rstn;
	logic load_en;
	logic [3:0] load;
	logic [3:0] count;

endinterface

2.设计模块中使用interface的例化的接口而非端口

​
module counter_ud (cnt_if cnt_if0);

	always @ (posedge cnt_if0.clk or negedge cnt_if0.rstn) begin
		
		if (!cnt_if0.rstn)
			cnt_if0.count <= 0;
		else begin
			if (cnt_if0.load_en)
				cnt_if0.count <= cnt_if0.load;
			else
				cnt_if0.count <= cnt_if0.count + 1;
	    end
	end
endmodule

​

3.testbench模块也引用interface例化接口

module test (cnt_if cnt_if0);
	initial begin
	
		$monitor("[%0t] load_en = %0d;load = %0d; count = %0d",$time,cnt_if0.load_en,cnt_if0.load,cnt_if0.count);
		
		cnt_if0.rstn <= 0;
		cnt_if0.load_en <= 1;
		cnt_if0.load <= 0;

		repeat (5) @(posedge cnt_if0.clk);
		cnt_if0.rstn <= 1;
		

			#(10);cnt_if0.load_en <=1;cnt_if0.load<=6;
			#(10); cnt_if0.load_en <=1;cnt_if0.load<=8;
			#(10); cnt_if0.load_en <=1;cnt_if0.load<=10;
			#(10); cnt_if0.load_en <=0;cnt_if0.load<=10;
			#(10); cnt_if0.load_en <=0;cnt_if0.load<=10;

		repeat (2) @(posedge cnt_if0.clk);
		$finish;
	end

endmodule

4.顶层模块

module top;

	bit clk;

	always #5 clk = ~clk;   //时钟输入

	cnt_if cnt_if0 (clk);   //interface模块
	
	counter_ud u0 (cnt_if0); //设计模块

	test t1 (cnt_if0);       //testbench模块

endmodule

 这就是使用接口的好处,简洁不易出错,便于修改。

5.SimLog

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值