SystemVerilog语法中,在Class中引用层次化信号

news/2024/5/19 17:56:51 标签: systemverilog

在class中可以像在verilog中一样,直接在class中引用层次化信号。示例如下:
1.DUT模块,文件名为top.v。

module top
(
	input 				clk			,
	input 				rst_n		,
	//总线信号	
	input 				wr_n		,
	input 				rd_n		,
	input 				cs0_n		,
	input 				cs7_n		);

2.cpu类,文件名为cpu.sv,在cpu类中可以通过.运算符直接引用其他模块的信号,如tb.top_inst.syn_rst_n。

`include "tb_interface.sv"

class cpu;

virtual top_if  cpu_if;//声明虚拟接口

function new(virtual top_if  watch_dog_interface);//在构造函数中将虚拟接口传递到类变量中
	cpu_if=watch_dog_interface;

endfunction  

task signal_synchronous(logic [2:0]  signal);
	   wait(    tb.top_inst.syn_rst_n);//在类中直接引用其他模块的信号、变量
	   
	   @(posedge tb.top_inst.sys_clk);
			#1 ;
			cpu_if.cs0_n<=signal[0];//通过接口对接口中的信号赋值
			cpu_if.rd_n<=signal[1];
			cpu_if.wr_n<=signal[2];

	   @(posedge tb.top_inst.sys_clk);
			#1 ;
			cpu_if.cs0_n<=signal[0];
			cpu_if.rd_n<=signal[1];
			cpu_if.wr_n<=signal[2];		
			
	   @(posedge tb.top_inst.sys_clk);
			#1 ;
			cpu_if.cs0_n<=signal[0];
			cpu_if.rd_n<=signal[1];
			cpu_if.wr_n<=signal[2];
		
		repeat(10) @(posedge tb.top_inst.sys_clk);
	
endtask
endclass

3.在testbench中将dut和tb连接,并在tb模块中实例化类对象。

`timescale 1ns/1ps

`include "tb_interface.sv"
`include "watch_dog.sv"
`include "cpu.sv"

module tb;

	 bit 				clk			;

	top_if topif(clk);    //实例化top_if对象,将clk传递给interface
	//top_if topif ;
	 dszj_2k_6001797_top   top_inst( .clk(topif.clk),               //将topif接口对象与DUT绑定,这里直接按照位置绑定
	                                   .rst_n( topif.rst_n    ),
	                                   .wr_n(topif.wr_n),		
	                                   .rd_n( topif.rd_n		),
	                                   .cs0_n( topif.cs0_n		),
	                                   .cs7_n(topif.cs7_n		)
	                              
	                                   );	                                                                   
	                              
	initial
		begin
			clk=0; 
			topif.rst_n=0;
			#100 topif.rst_n=1;
			
		end
	
	always #12.5 clk=~clk;
	
	 watch_dog  watch_dog_inst=new(topif);//将topif接口传递给watch_dog类的对象
	 
	 
	 cpu cpu_inst=new(topif);//将topif接口传递给cpu类的对象
	initial
	   begin	 
	      
	       repeat(1000) @(posedge clk);
	       watch_dog_inst.print();
	      // watch_dog_inst.
	      cpu_inst.signal_synchronous(3'b111);
	   end
	
	endmodule


 


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

相关文章

[双指针](一) Leetcode 283.移动零和1089.复写零

[双指针] Leetcode 283.移动零和1089.复写零 移动零 283. 移动零 1.题意分析 (1) 给你一个数组&#xff0c;将数组中的所有0移动到数组的末尾 (2) 保证非0元素在数组中相对位置不变 (3) 在原数组中操作 2.解题思路 由于题目要求我们移动数组内容&#xff08;也就是交换两…

Hadoop3.0大数据处理学习2(HDFS)

一、简介 HDFS&#xff1a;Hadoop Distributed File System。Hadoop分布式存储系统 一种允许文件通过网络在多台主机上分享的文件系统&#xff0c;可以让多机器上的用户分享文件和存储空间。 两大特性&#xff1a;通透性、容错性 分布式文件管理系统的实现很多&#xff0c;HD…

粤嵌实训医疗项目--day03(Vue + SpringBoot)

往期回顾 粤嵌实训医疗项目day02&#xff08;Vue SpringBoot&#xff09;-CSDN博客 粤嵌实训医疗项目--day01&#xff08;VueSpringBoot&#xff09;-CSDN博客 目录 一、SpringBoot AOP的使用 二、用户模块-注册功能&#xff08;文件上传&#xff09; 三、用户模块-注册实现…

如何分离一个要素的shp矢量文件:利用ArcGIS分割工具

下面介绍如何用ArcGIS对含有多个分离区域的一整个面要素进行分割 如下图&#xff0c;现在想要将下方的长形shp提取出来&#xff0c;首先打开shp文件&#xff1a; 右击空白处查看该矢量文件的投影信息&#xff1a; 在文件夹中新建shp文件&#xff0c;设置一样的投影&#xff1a…

5、计算电机速度【51单片机控制步进电机-TB6600系列】

摘要&#xff1a;本节介绍用定时器定时的方式&#xff0c;精准控制脉冲时间&#xff0c;从而控制步进电机速度。 一、计算过程 电机每一步的角速度等于走这一步所花费的时间&#xff0c;走一步角度等于步距角&#xff0c;走一步的时间等于一个脉冲的时间&#xff1a; TB6600及…

C++学习day--23 枚举、类型定义、头文件

1、枚举 1.1 枚举的概念 枚举是 C/C 语言中的一种基本数据类型&#xff0c; 它可以用于声明一组常数 。当一个变量有几个固 定的可能取值时&#xff0c;可以将这个变量定义为枚举类型。 比如&#xff0c;你可以用一个枚举类型的变量来表示季节&#xff0c;因为季节只有 4 …

数据结构与算法之LRU: 实现 LRU 缓存算法功能 (Javascript版)

关于LRU缓存 LRU - Lease Recently Used 最近使用 如果内存优先&#xff0c;只缓存最近使用的&#xff0c;删除 ‘沉睡’ 数据 核心 api: get set 分析 使用哈希表来实现, O(1)必须是有序的&#xff0c;常用放在前面&#xff0c;沉睡放在后面, 即&#xff1a;有序&#xff0…

prometheus监控etcd证书报错问题

背景 prometheus重启之后显示集群中的etcd节点全部down掉了。 在集群中查看etcd状态是正常的 进一步查看etcd日志发现 {"level":"warn","ts":"2023-10-27T07:52:58.389Z","caller":"embed/config_logging.go:169&q…