抽象和具体class的连接

An alternative to using a virtual interface handle for DUT to UVM testbench connections is to use an abstract concrete class pair. The abstract version of the class defines templates for all the methods that are available in the BFM. The concrete version of the class is declared in the BFM and it extends the abstract version, providing an implementation of the methods. The handle of the concrete class is assigned to the abstract handle in the agent classes via the uvm_config_db. The properties of class object polymorphism allow the abstract class handle to interact with the BFM using the method implementations in the concrete version of the class.

If a class is defined inside an interface or a module, it can reference any of the variables within the interface or module scope. This can be used to simplify the handling of parameters.

The following code snippets show the Abstract and Concrete versions of the sfr_master class:

// The abstract class for the SFR master driver/BFM
class sfr_master_abstract;
 
virtual task execute(sfr_seq_item item);
 
endtask
 
endclass
 
// The implementation for the SFR master BFM, containing the concrete implementation of the sfr_master
module sfr_master_bfm #(ADDR_WIDTH = 8,
DATA_WIDTH = 8)
(input clk,
input reset,
output logic[ADDR_WIDTH-1:0] address,
output logic[DATA_WIDTH-1:0] write_data,
input logic[DATA_WIDTH-1:0] read_data,
output logic we,
output logic re);
 
import uvm_pkg::*;
import sfr_agent_pkg::*;
 
always @(reset or posedge clk) begin
if(reset == 1) begin
re <= 0;
we <= 0;
address <= 0;
write_data <= 0;
end
end
 
// Definition of the concrete version of the sfr_master class:
class sfr_master_concrete extends sfr_master_abstract;
 
task execute(sfr_seq_item item);
if(reset == 1) begin
wait(reset == 0);
end
else begin
@(posedge clk);
address = item.address;
we <= item.we;
write_data <= item.write_data;
re <= item.re;
@(posedge clk);
if(re == 1) begin
item.read_data = read_data;
re <= 0;
end
we <= 0;
end
endtask: execute
endclass
 
// Declaration of the SFR_MASTER class handle
sfr_master_concrete SFR_MASTER;
 
// Initial block, constructing the SFR_MASTER object and assigning the handle into the uvm_config_db
// Note the use of the sfr_master_abstract handle as the uvm_config_db parameter
initial begin
SFR_MASTER = new();
uvm_config_db #(sfr_master_abstract)::set(null, "uvm_test_top", "SFR_MASTER", SFR_MASTER);
end
 
endmodule: sfr_master_bfm

Note that in the above code, the BFM has been changed to a module from an interface, this is another freedom that using the abstract-concrete pattern enables. Modules allow the BFM to have hierarchy.

Inside the SFR agent classes, any reference to the BFM is via handles of the sfr_master_abstract type:在agent中,使用抽象类

class sfr_driver extends uvm_driver #(sfr_seq_item);
 
// Abstract version of the sfr_master class:
sfr_master_abstract SFR;
 
extern task run_phase(uvm_phase phase);
 
endclass: sfr_driver
 
task sfr_driver::run_phase(uvm_phase phase);
sfr_seq_item item;
 
forever begin
seq_item_port.get_next_item(item);
SFR.execute(item);
seq_item_port.item_done();
end
 
endtask: run_phase

The handle to the sfr_master_abstract object is passed via the agent config object via the uvm_config_db, note that in the following code snippet, the sfr_monitor uses the same connection pattern:

class sfr_test extends uvm_component;
 
 
sfr_env_config env_cfg;
sfr_config_object sfr_agent_cfg;
 
sfr_env env;
 
extern function void build_phase(uvm_phase phase);
extern task run_phase(uvm_phase phase);
 
endclass: sfr_test
 
function void sfr_test::build_phase(uvm_phase phase);
env_cfg = sfr_env_config::type_id::create("env_cfg");
sfr_agent_cfg = sfr_config_object:: type_id::create("sfr_agent_cfg");
 
// Assigning the handle to the concrete implementations of the sfr_master and sfr_monitor classes to their abstract counterparts
if(!uvm_config_db #(sfr_master_abstract)::get(this, "", "SFR_MASTER", sfr_agent_cfg.SFR_MASTER)) begin
`uvm_error("BUILD_PHASE", "Unable to find virtual interface sfr_master_bfm in the uvm_config_db")
end
if(!uvm_config_db #(sfr_monitor_abstract)::get(this, "", "SFR_MONITOR", sfr_agent_cfg.SFR_MONITOR)) begin
`uvm_error("BUILD_PHASE", "Unable to find virtual interface sfr_master_bfm in the uvm_config_db")
end
 
sfr_agent_cfg.is_active = 1;
env_cfg.sfr_agent_cfg = sfr_agent_cfg;
env = sfr_env::type_id::create("env", this);
env.cfg = env_cfg;
endfunction: build_phase

When the abstract-concrete class connection pattern is used, the agent does not have to be parameterised, since class handles are used to make the connection.

In summary, the abstract concrete class approach works by passing a class object handle from the hdl_top part of the testbench to the UVM testbench.

uvm_cookbook--DUT-Testbench Connections--Abstract-Concrete Class Connections的更多相关文章

  1. Configure the max limit for concurrent TCP connections(转)

    To keep the TCP/IP stack from taking all resources on the computer, there are different parameters t ...

  2. 一步一步学习SignalR进行实时通信_2_Persistent Connections

    原文:一步一步学习SignalR进行实时通信_2_Persistent Connections 一步一步学习SignalR进行实时通信\_2_Persistent Connections Signal ...

  3. 【转载】Configure the max limit for concurrent TCP connections

    转载地址:http://smallvoid.com/article/winnt-tcpip-max-limit.html To keep the TCP/IP stack from taking al ...

  4. Concurrent HTTP connections in Node.js

    原文: https://fullstack-developer.academy/concurrent-http-connections-in-node-js/ -------------------- ...

  5. 洛谷 P1197 BZOJ 1015 [JSOI2008]星球大战 (ZOJ 3261 Connections in Galaxy War)

    这两道题长得差不多,都有分裂集合的操作,都是先将所有操作离线,然后从最后一步开始倒着模拟,这样一来,分裂就变成合并,也就是从打击以后最终的零散状态,一步步合并,回到最开始所有星球都被连为一个整体的状态 ...

  6. Thinkpad Access Connections实现快速的在各种网络间进行切换

    Thinkpad Access Connections快速的在各种网络间进行切换 因为工作的原因要经常在多个无线或有线之间切换,每次要切换到不同的固定IP地址的网络更是一种折磨,换一次就要从新输入一次 ...

  7. Java性能提示(全)

    http://www.onjava.com/pub/a/onjava/2001/05/30/optimization.htmlComparing the performance of LinkedLi ...

  8. httpcomponents-client-4.4.x

    Chapter 1. Fundamentals Prev     Next Chapter 1. Fundamentals 1.1. Request execution The most essent ...

  9. httpcomponents-client-ga(4.5)

    http://hc.apache.org/httpcomponents-client-ga/tutorial/html/   Chapter 1. Fundamentals Prev     Next ...

随机推荐

  1. 从输入 URL 到展现页面的全过程

    总体分为以下几个过程 DNS解析 TCP连接 发送HTTP请求 服务器处理请求并返回HTTP报文 浏览器解析渲染页面 连接结束 DNS解析 域名到ip地址转换 TCP连接 HTTP连接是基于TCP连接 ...

  2. STM32,下载HAL库写的代码后J-Link识别不到芯片,必须要按住复位才能下载?

    问题描述:最近在学STM32的HAL库,据说可以统一STM32江湖,前途无量.最近一段时间参照STM32CubeMX和原子的资料自己学着建了两个HAL库的工程模板,F4的还好说,F1的出现了一个玄学问 ...

  3. 版本管理 - Git 使用入门

    Git 是一个分布式的版本管理系统,而 SVN 是一个集中式管理系统. 版本控制 Git与SVN的对比 对比 SVN Git 工作方式 集中式 分布式 文件管理 增量式 系统快照 权限控制 对团队中参 ...

  4. Linux python 虚拟环境管理

    直接复制的内容: 原著:https://www.cnblogs.com/q767498226/p/11099884.html 报错解决:https://blog.csdn.net/weixin_467 ...

  5. GUI编程笔记

    GUI编程 告诉大家该怎么学? 这是什么? 它怎么玩? 该如何去我们平时运用? 组件 窗口 弹窗 面板 文本框 列表框 按钮 图片 监听事件 鼠标 键盘事件 破解工具 1.简介 GUi的核心技术:Sw ...

  6. c++ 的学习 第二集函数的重载

    1. 规则 函数名相同参数个数不同.参数类型不同.参数顺序不同 2. 注意 返回值类型与函数重载无关 调用函数时,实参的隐式类型转换可能会产生二义性 返回值类型与函数重载无关 什么意思? 返回 ...

  7. python3.7发送邮件带附件

    代码: 1 # -*- coding: utf-8 -*- 2 3 import smtplib, ssl 4 from email.mime.text import MIMEText 5 from ...

  8. P3706-[SDOI2017]硬币游戏【高斯消元,字符串hash】

    正题 题目链接:https://www.luogu.com.cn/problem/P3706 题目大意 给出 \(n\) 个长度为 \(m\) 的 \(H/T\) 串. 开始一个空序列,每次随机在后面 ...

  9. 深入浅出WPF-04.x名称空间详解

    x名称空间详解 几个需要特别说明的名称空间: x:Class 用来标记XAML和后台代码之间的合并关系.x:Class根节点的类型必须和x:Class值指向的类型保持一致.x:Class的值指向的类型 ...

  10. hexo配合github action 自动构建(多种形式)

    已经使用HEXO正常构建GitHub页面 根据github action 给hexo配置自动部署github page 前往墨抒颖的个人网站查看纯净版 1. 为仓库设置访问密钥 第一步先生成密钥,打开 ...