0

解读uvm_config_db中的set和get方法 - 程默白

 1 year ago
source link: https://www.cnblogs.com/ChengMobai/p/uvm_config_db.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

一、uvm_config_db简介

uvm_config_db的全称是configuration database,它是建立在 uvm_resource_db 之上的便利层,resource database储存的是与scope字符串相关联的name-value对(如下图所示) 。
uvm_config_db可以将scope字符串与组件层次结构中的完整层次结构名称相关联,这样就可以通过组件层次来更加方便地访问数据库的条目(储存的信息)。

3114000-20230306214045412-337990039.png

config_db 是参数化的,它的类型可以是标量、类句柄、队列、列表,甚至是虚拟接口。通过uvm_config_db::set 和 uvm_config_db::get 函数进行全局存储和检索数据库中的信息。

二、set和get函数

1、set函数

set函数的原型为

static function void set(uvm_component cntxt, string inst_name, string field_name, T value);
  • 第一个参数cntxt是一个组件,它是访问数据库条目的层级起点;
  • 第二个参数inst_name是限制数据库条目可访问性的分层路径;

简单来说,前两个参数可以组成一个层次化路径,这个路径指定了我们只能从哪个城市出发,走哪条公路达到我们想去的目的地。

  • 第三个参数field_name是用作查找数据库条目的标签;
  • 第四个参数value是要存储在数据库中的值,T是他的类型,如前文所述,可以是标量、类句柄、队列、列表、虚拟接口等;

field_name就像是一个做过特殊标记的盒子,里面放的东西就是value,这个特殊标记只有两个“人”知道,因此才能保证盒子的传送不会出错。

2、get函数

get函数的原型为:

static function bit get(uvm_component cntxt, string inst_name, string field_name, inout T value);

它的四个参数的定义与set大致一样,不同的是

  • 前两个参数:就像是两个要去见面的朋友一样,比如一个人(set)从洛阳去另一个人(get)所在的西安。从洛阳到西安的路线(由cntxt和inst_name构成的层级路线)是绝对的,但是对洛阳的朋友来说是要走很远的远方,对西安的朋友来说是家门口,因此以他们各自作为参考系来说,ntxt和inst_name是不同的。
  • 第三个参数:field_name必须要和set函数中的相同,特殊标记的暗号不一样,装有重要物资(value)的盒子就不能保证交到正确的接收方手上了。
  • 第四个参数:和set不同,此时的value是那个要从数据库检索值(也就是要从盒子里取得value)的变量。
  • get 如果成功返回 1 ,如果数据库中没有找到此类资源则返回 0;set是空函数没有返回值。

3、其他说明

  • inst_name和field_name都可以包含通配符或正则表达式。
  • cntxt可以为null,这时inst_name提供完整的层次信息,cntxt为null和uvm_root::get是等价的,他们都表示uvm_top
  • cntxt可以为this,表示cntxt为当前层次。
  • inst_name可以为空。
  • 如果在build前进行set,则使用 cntxt 层次结构来确定优先级,层次结构越高,优先级越高; 同一层次结构的set后面的配置会覆盖前面的配置。如果在build后set,所有设置都使用默认优先级,后面的配置会覆盖前面的配置。因此建议在其相关配置组件创建前调用set,确保得到期望的值。
  • set和get方法是静态的,所以必须使用 ::

三、一个示例

在test中set:

class my_test extends uvm_test; my_config cfg; ... function void bulid_phase(uvm_phase phase); ... uvm_config_db#(my_config)::set(this,"env","cfg",cfg); ... endfunctionendclass

在test.env中get:

class my_env extends uvm_env; my_config cfg; ... function void bulid_phase(uvm_phase phase); ... if(!uvm_config_db#(my_config)::get(this,"","cfg",cfg)) begin `uvm_fatal(" get config object failed") end ... endfunctionendclass
  1. https://verificationguide.com/uvm/uvm-configuration-database/

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK