当前位置: 首页 > news >正文

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

在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		));	                                                                   initialbeginclk=0; topif.rst_n=0;#100 topif.rst_n=1;endalways #12.5 clk=~clk;watch_dog  watch_dog_inst=new(topif);//将topif接口传递给watch_dog类的对象cpu cpu_inst=new(topif);//将topif接口传递给cpu类的对象initialbegin	 repeat(1000) @(posedge clk);watch_dog_inst.print();// watch_dog_inst.cpu_inst.signal_synchronous(3'b111);endendmodule


 

http://www.lryc.cn/news/210048.html

相关文章:

  • 磁盘的结构(磁道,扇区,盘面,柱面,物理地址)
  • uni-app集成uni-simple-router,报错:Uncaught ReferenceError: ROUTES is not defined
  • 几个常用的nosql数据库的操作方式
  • 如何使用 nvm-windows 这个工具来管理你电脑上的Node.js版本
  • 公司电脑禁用U盘的方法
  • Elasticsearch 7.X版本常用语法语句
  • Python分享之数学与随机数 (math包,random包)
  • Linux 基本语句_8_C语言_文件控制
  • 博通BCM575系列 RDMA 网卡驱动 bnxt_re 分析(一)
  • ExcelPatternTool 开箱即用的Excel工具包现已发布!
  • Navicat for MySQL 视图创建使用方法
  • 计算机视觉的相机选型
  • 实体店做商城小程序如何
  • sql-50练习题0-5
  • Flutter框架实现登录注册功能,不连接数据库
  • 持续集成部署-k8s-部署利器-Helm
  • 替换所有的问号
  • NCCL后端
  • 【API篇】十、生成Flink水位线
  • 【Javascript】弹出框
  • NSS [鹤城杯 2021]EasyP
  • mysql用户及权限管理(InsCode AI 创作助手)
  • 命令模式——让程序舒畅执行
  • GZ035 5G组网与运维赛题第3套
  • 071:mapboxGL上传含shp的zip文件,在map上解析显示图形
  • python下拉框选择测试
  • 即时编译器JIT
  • npm更新包时This operation requires a one-time password.
  • C++类模板再学习
  • 华为终端智能家居应用方案