systemverilog:interface中端口方向理解

news/2024/5/19 19:13:50 标签: systemverilog

(1)从testbench的角度看,tb中信号的输入输出方向与interface中信号输入输出方向一致
(2)从DUT角度看,DUT中信号输入输出方向与interface中信号输入输出方向相反。简单图示如下

代码示例如下:
 

interface my_if(input bit clk);
	bit write;
	bit [15:0] data_in;
	bit [7:0] address;
	logic [15:0] data_out;

	clocking cb @ (negedge clk);
		default input #1ns output #2ns;
		output  write;
		output  data_in;
		output   address;
		input data_out;
	endclocking

	modport master(clocking cb);

	modport slave(input write, data_in, address, output data_out);

endinterface

module master( clk,data_out  ,  write ,data_in,address );
	input logic clk,write;
	output logic [7:0] data_out;
	input logic [7:0] data_in ,address;
	
	
	always @(negedge clk)
		if(write==0)
			data_out<=0;
		else if (write==1)
			data_out<=data_in;
			
endmodule


class BB;

 virtual  my_if master_inst;
 
function new(virtual interface  my_if a);
	master_inst=a;
endfunction
	
task ass();
	master_inst.master.cb.write<=0;
	repeat(10) @(posedge master_inst.clk);
		master_inst.master.cb.data_in<='h12;

	repeat(10) @(posedge master_inst.clk);
		master_inst.master.cb.data_in<='h34;	

	repeat(10) @(posedge master_inst.clk);
		master_inst.master.cb.data_in<='h45;

master_inst.master.cb.write<=1;
	repeat(10) @(posedge master_inst.clk);
		master_inst.master.cb.data_in<='h56;	

	repeat(10) @(posedge master_inst.clk);
		master_inst.master.cb.data_in<='h67;

	repeat(10) @(posedge master_inst.clk);
		master_inst.master.cb.data_in<='h52;	

	repeat(10) @(posedge master_inst.clk);
		master_inst.master.cb.data_in<='h81;

	repeat(10) @(posedge master_inst.clk);
		master_inst.master.cb.data_in<='h05;	
		
endtask

endclass


module slaver(my_if.slave sif);
	
	initial begin
		sif.data_out <= 16'h0;
		#275 sif.data_out <= 16'h1;
	end
endmodule

module test;
	bit clk = 0;

	always #50 clk = ~clk;

	my_if regbus(clk);
	
	master m0(.clk(regbus.clk ), .address(regbus.address), .data_out(regbus.data_out), .data_in(regbus.data_in),.write(regbus.write));
	
	//slaver s0(regbus.slave);
	
	 BB b_inst=new(regbus);
	 
	initial begin
	 
	 #100 b_inst.ass();
	 
	end

endmodule 


注意:
(1)当interface中有modport或者clocking块时,在testbench中可以直接定义interface的实例,可以将其直接传递到class中,然后在class中的task中可以通过点运算法逐层次的访问modport或者clocking中的信号。也可以通过点运算符直接在tb中实例化interface中的modport对象,然后传递到class中。
(2)在class中的task中对clocking块中的信号赋值时,必须使用非阻塞赋值语句<=;
 


http://www.niftyadmin.cn/n/5186292.html

相关文章

Vue中el与data的两种写法

想必大家对Vue中的el与data并不陌生&#xff0c;接下来&#xff0c;让我为大家介绍一下el与data的两种写法吧&#xff01; 一、el的两种写法 1.new Vue时候配置e1属性。 2.先创建Vue实例&#xff0c;随后再通过vm.$mount(#root)指定el的值 <!DOCTYPE html> <html l…

js点击按钮切换图片

要通过JavaScript点击按钮来切换图片&#xff0c;你可以使用HTML和JavaScript来实现。以下是一个示例&#xff0c;演示了如何创建一个按钮&#xff0c;当点击按钮时&#xff0c;切换显示的图片&#xff1a; <!DOCTYPE html> <html> <head> <title>切…

mysql之squid代理服务器

&#xff08;一&#xff09;squid代理服务器 1、nginx做代理服务器 &#xff08;1&#xff09;反向代理&#xff08;负载均衡&#xff09; &#xff08;2&#xff09;缓存 &#xff08;3&#xff09;nginx无法做正向&#xff0c;通过proxy_pass进行反向代理 2、squid&…

windows c++开发

一 安装 离线MSDN MSDN:microsoft developer network ,微软向开发人员提供的一套帮助系统。 运行vs 2017 -》运行 vs studio installer ->点击修改-》单个组件-》代码工具-》help viewer-> 安装完后&#xff0c;启动vs 在“帮助”菜单&#xff0c;“设置帮助首选项…

Android NDK JNI 开发native层崩溃日志栈分析

问题&#xff1a; 在Android的JNI开发中&#xff0c;你是否看到如下一堆崩溃日志&#xff0c;不知如何下手分析问题&#xff0c;崩溃在哪一行&#xff1f; 11-16 17:20:44.844 23077 23077 W test_jni_h: jni_preload: Starting for processln 11-16 17:20:44.844 23077 2307…

leetcode刷题日记:160. Intersection of Two Linked Lists(相交链表)

给出两个单链表的头结点headA与headB&#xff0c;让我们找出两个链表相接的起始节点&#xff0c;如果两个链表不存在相交结点返回null。 我们就先假设存在这样两个链表&#xff0c;链表1与链表2&#xff0c;假设链表1的长度为 L 1 L_1 L1​和 L 2 L_2 L2​,假设对于两个链表&am…

K8S篇之实现利用Prometheus监控pod的实时数据指标

一、监控部署 1、将k8s集群中kube-state-metrics指标进行收集&#xff0c;服务进行部署 1.1 pod性能指标&#xff08;k8s集群组件自动集成&#xff09; k8s组件本身提供组件自身运行的监控指标以及容器相关的监控指标。通过cAdvisor 是一个开源的分析容器资源使用率和性能特性的…

懒人福利:6款Sketch插件合集,提升设计效率爆款推荐!

Sketch作为一种在线设计工具&#xff0c;一直是许多设计师的最爱。它不仅能快速建立原型&#xff0c;还能提供丰富的插件&#xff0c;以满足不同的需求。 今天&#xff0c;我想和大家分享六款流行的Sketch插件供参考。这些插件都是精心挑选的&#xff0c;它们支持Windows、Mac…