uvm_config_db的set()与get()方法
1、set方法1.1 方法原型:uvm_config_db#(T)::set(uvm_component cntxt, string inst_name, string filed_name, T value);1.2 举个栗子:uvm_config_db#(int)::set(this, "c1", "val1", 100);1.3 参数含义1)#( )括号中是要传送的数据类型T,可以是:vir
目录
1、set方法
1.1 方法原型:
uvm_config_db#(T)::set(uvm_component cntxt, string inst_name, string filed_name, T value);
uvm_config_db#(T)是一个参数化的类,参数T是要传递数据的类型,set()方法是这个类中的一个静态方法,get()方法也一样。
1.2 举个栗子:
uvm_config_db#(int)::set(this, "c1", "val1", 100);
1.3 参数含义
1)#( )括号中是要传送的数据类型T,可以是:
- virtual interface;
- 单一变量值如:int,string,enum等;
- 对象(config object);
2)第⼀个和第⼆个参数联合起来组成要传送的⽬标路径,与此路径符合的⽬标才能收信。
- 第⼀个参数uvm_component cntxt,必须为uvm_component 的实例的句柄。
- 第⼆个参数string inst_name,是一个字符串,使用时要打上" "双引号,表示的是相对于此实例的路径。
3)第三个参数string filed_name,也是一个字符串,使用时要打上" "双引号,是要传递的变量的名字。这个参数必须要和get()方法中的第三个参数保持一致。
前三个参数组成的路径可以完全确定一个目标变量:this.c1.val1,即this域(本域)中的c1组件中的val1变量;
4)第四个参数T value,其中 T 和uvm_config_db#(T)中的 T 保持一致,即这个参数是T类型的变量值。
上述代码表示将100传递给this.c1路径下的val1变量。
2、get方法
2.1 方法原型:
uvm_config_db#(T)::get(uvm_component cntxt, string inst_name, string filed_name, inout T value);
2.2 举个栗子:
int val1;
uvm_config_db#(int)::get(this, " ", "val1", val1);
2.3 参数含义
1)set() 第⼀个参数必须为uvm_component 的实例的指针,this代表本域所属component的指针。
2)第⼆个参数是相对于此实例的路径,如果第⼀个设置为 this,且传递的变量就在本component层级中,则第⼆个可以是空的字符串。
3)第三个参数必须和set中的严格⼀样,即例子中都是“val1”。
*即set()方法和get()方法中的前三个参数所指向的目标变量路径必须保持一致,这样可以保证set和get是同一个变量。
既然是第⼀个和第⼆个参数联合起来的,如test_top中,set( ) 也可以是下⾯这样:
uvm_config_db#(int)::set(this.env, "i_agt.drv", "val1", 100);
get( )也可以下边这样,⽐如driver的build_phase:
uvm_config_db#(int)::get(this.parent, "drv", "val1", val1);
this. parent表示的是 drv 的 parent,即i_agt,则this.parent.drv,表示的就是drv本身;所以第一个参数可以直接用 this 代替,这样的话第二个参数就是空的字符串 “ ” :
uvm_config_db#(int)::get(this, " ", "val1", val1);
3 拓展
在top_tb 中,传递 virtual interface 时,uvm_config_db#(virtual chnl_intf)::set()方法的
- 第⼀个参数是null,UVM会⾃动把它替换成 uvm_root :: get( ),即替换为 uvm_top,在UVM世界中,uvm_top是uvm_root的一个唯一实例,是UVM的树根,也是一个全局变量,可以直接使用。
uvm_root是全局的,uvm_root的get()方法是静态的,其uvm源代码如下:
/****************************************** UVM源代码 *******************************************/
static function uvm_root get()
// static accessor for uvm_root;
uvm_root r;
r = uvm_root::get();//uvm_top在uvm层次中是一个全局变量,是验证平台的top-level,控制着phases的执行,提供search component的接口。
const uvm_root uvm_top = uvm_root::get()
- 第二个参数“uvm_test_top”是 top_tb 中 run_test() 函数创建的实例名称。无论传递给 run_test() 的参数是什么,创建的实例名称都为 uvm_test_top,这是UVM世界中的“规则”。前两个参数组合起来的路径索引“ __top__.uvm_test_top ”结构如下所示:
为什么根路径是“__top__”呢,因为在UVM源码中,创建uvm_top实例时,是这样写的:new("__top__", null);创建时传入的名字是"__top__",所以路径是“ __top__.uvm_test_top ”,由此可见,路径的显示的是创建实例时传递进去的名字,在好的编码习惯中,变量名应尽量与其实例化时传递的名字保持一致:
//在好的编码习惯中,变量名drv应尽量与其实例化时传递的名字"drv"保持一致:
drv = my_driver::type_id::create("drv",this);
但是在显示路径时,并不会显示“__top__”,而是从uvm_test_top这个层次开始显示的。
module tb;
import uvm_pkg::*;
`include "uvm_macros.svh"
...
chnl_intf chnl0_if(.*);
initial begin
uvm_config_db#(virtual chnl_intf)::set(null, "uvm_test_top", "ch0_vif", chnl0_if);
/* 相当于
uvm_config_db#(virtual chnl_intf)::set(uvm_root::get(), "uvm_test_top", "ch0_vif", chnl0_if);
*/
run_test("basic_test");
end
endmodule
uvm_config_db#( )::set( )方法和uvm_config_db#( )::get( )方法一般在build_phase()中使用。
更多推荐
所有评论(0)