UVM-config机制

1.config机制的作用

  • 在创建底层组件之前,需要对验证环境进行配置,为了验证环境的复用性,通过外部的参数配置,使得环境在创建时可以根据不同参数来选择创建的组件类型

  • 与重新编译来调节变量比,UVM config机制可以在仿真中通过变量设置来修改环境

UVM提供了uvm_config_db配置类以及几种方便地变量设置方法来实现仿真的环境控制
uvm_config_db类的使用方式包括:

  • 传递virtual interface 到环境中
  • 设置单一变量值,例如int、string、enum等
  • 传递配置对象(config object)到环境
    set与get函数的参数:
    config_db机制用于在UVM验证平台间传递参数,set()是寄信,get()是收信
uvm_config_db#(T)::set(uvm_component cntxt, string inst_name, string field_name, T value);
uvm_config_db#(T)::get(uvm_component cntxt, string inst_name, string field_name, inout T value);
  • T是传递信息的类型
  • cntxt是一个uvm_component实例的指针,cntxt+inst_name组成目标路径
  • inst_name是相对此实例的路径
  • field_name变量名set和get的第三个参数必须一致

2.config_db的使用

2.1 传递interface

接口的传递从硬件世界到UVM环境中的传递可以通过uvm_config_db来实现。
在实现的过程中需要注意几点:

  • 接口的传递应该发生在 run_test() 之前。这保证了在进入build_phase之前virtual interface已经被传递到uvm_config_db中;
  • 应当把interface和virtual interface 的声明分开,在传递的过程中的类型应该为virtual interface(接口句柄)
interface  intf1;
	logic enable = 0;
endinterface
class comp1 extends uvm_component;//底层组件拿到config
	'uvm_component_utils(comp1);
	virtual intf1 vif;//声明接口要带virtual
	...
	function void build_phase(uvm_phase phase);
	//这里的this的绝对路径是root.test.c1.vif
	//第二个参数"",表示要找comp1里面的vif
		if(!uvm_config_db#(virtual intf1)::get(this, "", "vif", vif))begin//判断是否有误
		'uvm_error("GETVIF", "no virtual interface is assigned")
		end
		'uvm_info("SETVAL", $sformatf("vif.enable is %b after set", vif.enable),UVM_LOW)
		vif.enable = 1;
	endfunction
endclass
class test1 extends uvm_test;//顶层test中传递config
	'uvm_component_utils(test1)
	comp1 c1;
	...
endclass
intf1 intf();
initial begin
	uvm_config_db#(virtual intf1)::set(uvm_root::get(), "uvm_test_top.c1", "vif", intf);//在run_test之前,将配置发送出去
	run_test("test1");
end

2.2传递变量

在各个test中,可以在build phase对底层组件的变量加以配置,进而在环境例化之前完成配置,使得环境可以按照预期运行

class comp1 extends uvm_component;
	'uvm_component_utils(comp1)
	int val1 = 1;
	string str1 = "null";
	...
	function void build_phase(uvm_phase phase);
		'uvm_info("SETVAL", $sformatf("vall is %d before get", vall), UVM_LOW)
		'uvm_info("SETVAL", $sformatf("str1 is %s before get", str1), uvm_low)
		uvm_config_db#(int)::get(this,"","vall",vall);
		uvm_config_db#(string)::get(this,"","str1",str1);
	endfunction
endclass
class test1 extends uvm_test;
	'uvm_component_utils(test1)
	comp1 c1;
	...
	function void build_phase(uvm_phase phase);
		uvm_config_db#(int)::set(this,"c1","vall",100);//例化之前set
		uvm_config_db#(string)::set(this,"c1","str1","comp1");
		c1 = comp1::type_id::create("c1",this);
	endfunction
endclass

2.3传递object

  • 如果要给底层配置的参数很多,就可以把封装在一个object类中,在顶层test中将类的实例对象句柄进行set传递;
  • 底层通过get拿到对象句柄,就可以通过句柄获取配置类中的变量设置
//将参数封装到object中
class config1 extends uvm_object;
	int vall = 1;
	int str1 = "null";
	'uvm_object_utils(config1)
endclass
//底层组件拿到config
class comp1 extend uvm_component;
	'uvm_component_util(comp1)
	config1 cfg;
	...
	function void build_phase(uvm_phase phase);
		uvm_object tmp;
		uvm_config_db#(uvm_object)::get(this, "","cfg", tmp);
		//传递的是父类uvm_object,要获得子类的成员变量,所以要做类型转换
		void'($cast(cfg,tmp));
		'uvm_info("SETVAL",
		$sformatf("cfg.vall is %d after get",cfg.vall),UVM_LOW)
		'uvm_info("SETVAL",
		$sformatf("cfg.str1 is %s after get", cfg.srt1),UVM_LOW)
	endfunction
endclass
//顶层test中传递config
class test1 extends uvm_test;
	'uvm_component_utils(test1)
	comp1 c1,c2;
	config cfg1,cfg2;
	...
	function void build_phase(uvm_phase phase);
		cfg1 = config1::type_id::create("cfg1");
		cfg2 = config1::type_id::create("cfg2");
		cfg1.val1 = 30;
		cfg1.str1 = "c1";
		cfg2.val1 = 50;
		cfg2.str1 = "c2";
		//设置set
		uvm_config_db#(uvm_object)::set(this, "c1", "cfg", cfg1);
		uvm_config_db#(uvm_object)::set(this, "c2", "cfg", cfg2);
		c1 = comp1::type_id::create("c1", this);
		c2 = comp1::type_id::create("c2", this);
	endfunction
endclass
  • 这里config传递的是一个父类句柄,所以要做句柄类型转换
  • set和get的类型必须相同,要不都是父类,要不都是子类
  • 1
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
UVM中的config_db机制是一种方便的配置管理机制,可以在测试用例中动态地配置不同组件之间的参数。它允许用户将配置信息存储在单个数据库中,并在需要时从中检索。 config_db机制的核心是一个名为uvm_config_db的类,它提供了一些静态方法,用于将配置信息存储在数据库中、从数据库中检索配置信息和删除配置信息。每个配置信息都有一个名称和一个通用的数据类型,可以是任意类型的数据结构,包括简单的整数和字符串,以及更复杂的对象和指针。 config_db机制可以用于多种情况,例如: 1. 在测试用例中配置测试环境中的组件; 2. 在测试用例中配置测试用例本身; 3. 在测试用例中配置测试运行时环境(如时钟周期)。 下面是一个例子,展示如何使用config_db机制来配置两个组件之间的参数: ```systemverilog // 存储配置信息 uvm_config_db#(int)::set(null, "env.agent1.config", "data", 100); uvm_config_db#(string)::set(null, "env.agent2.config", "data", "hello"); // 从数据库中检索配置信息 int my_int; string my_string; uvm_config_db#(int)::get(null, "env.agent1.config", "data", my_int); uvm_config_db#(string)::get(null, "env.agent2.config", "data", my_string); ``` 在上面的例子中,我们使用uvm_config_db类的set方法将一个整数值和一个字符串值存储在了数据库中,并使用get方法从数据库中检索这些值。注意,我们使用了不同的名称("env.agent1.config"和"env.agent2.config")来区分不同的配置信息。这些名称应该在测试用例中被定义为常量或宏,以便在整个测试用例中使用。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值