1、uvm object 使用config_db。
<1>. uvm_object中通过config_db get得到变量

class my_config extends uvm_object;
`uvm_object_utils(my_config)
virtual my_if vif;
function new(string name = "my_config");
super.new(name);
$display("%s", get_full_name());
if(!uvm_config_db#(virtual my_if)::get(null, get_full_name(), "vif", vif))
`uvm_fatal("my_config", "please set interface")
     //在get函数原型中,第一个参数必须是一个component,所以这里不能使用this指针,只能使用null或者uvm_root      //通过名字get_full_name()得到,即其实例化时指定的名字
     //使用null时,UVM会自动将其替换为uvm_root::get(),再加上第二个参数get_full_name() ,就可以完整地得到此object的路径 
endfunction
endclass function void base_test::build_phase(uvm_phase phase);

cfg = new("cfg");
endfunction module top_tb;

initial begin
uvm_config_db#(virtual my_if)::set(null, "cfg", "vif", input_if);
end
//所以,base_test中实例化cfg的名字要与top_tb中config_db::set的路径参数一致。

<2>. uvm_object中通过config_db set变量

class case0_sequence extends uvm_sequence #(my_transaction);

virtual task pre_body();
  if(uvm_config_db#(int)::get(null, get_full_name(), "count", count))
`uvm_info("seq0", $sformatf("get count value %0d via config_db", count), UVM_MEDIUM)
  else
`uvm_error("seq0", "can't get count value!")
  #;
  uvm_config_db#(bit)::set(uvm_root::get(), "uvm_test_top.env0.scb","cmp_en", );
    //可以set 到uvm_component中。
    ...
    void'(uvm_config_db#(bit)::get(uvm_root::get(), get_full_name(), "first_start", first_start)
    if(first_start)
    `uvm_info("drv0_seq", "this is the first start of the sequence", UVM_MEDIUM)
    else
    `uvm_info("drv0_seq", "this is not the first start of the sequence",UVM_MEDIUM)
    uvm_config_db#(bit)::set(uvm_root::get(), "uvm_test_top.v_sqr.*", "first_start", 0);
    //这个sequence向自己传递了一个参数:first_start。在一次仿真中,当此sequence第一次启动时,其first_start值为1;
    //
当后面再次启动时,其first_start为0。根据first_start值的不同,可以在body中有不同的行为。
    //由于此sequence在virtual sequence中被启动,所以其get_full_name的结果应该是uvm_test_top.v_sqr.*,而不
是uvm_test_top.env0.i_agt.sqr.* 
    endtask

endclass

2、uvm_config_db的方法:

<1> set()方法:所有静态函数和方法在使用时,called using域操作符::

set 方法设置为静态函数,才实现了set的变量全局可见。

  static function void set (  uvm_component cntxt,
string inst_name,
string field_name,
T value); virtual function void build_phase (uvm_phase phase);
...
uvm_config_db #(int) :: set (null, "uvm_test_top.m_env.m_apb_agent", "cov_enable", );
...
endfunction
  // Set virtual interface handle under name "apb_vif" available to all components below uvm_test_top, indicated by the *
uvm_config_db #(virtual apb_if) :: set (null, "uvm_test_top.*", "apb_vif", apb_if); // Set an int variable to turn on coverage collection for all components under m_apb_agent
uvm_config_db #(int) :: set (null, "uvm_test_top.m_env.m_apb_agent.*", "cov_enable", ); // Consider you are in agent's build_phase then you may achieve the same effect by
uvm_config_db #(int) :: set (this, "*", "cov_enable", );

<2> get 方法设置为静态函数,才实现了get变量全局可见。

  static function bit get (  uvm_component cntxt,
string inst_name,
string field_name,
inout T value); // Get virtual interface handle under name "apb_vif" into local virtual interface handle at m_env level
uvm_config_db #(virtual apb_if) :: get (this, "*", "apb_vif", apb_if); // Get int variable fails because no int variable found in given scope
uvm_config_db #(int) :: get (null, "uvm_test_top", "cov_enable", cov_var);

<3> exists() 检查 field_name 在inst_name中是否存在,存在返回1,不存在则返回0

  static function bit exists (  uvm_component cntxt,
string inst_name,
string field_name,
bit spell_chk);
// Check if interface handle exists at the given scope
if (! uvm_config_db #(virtual apb_if) :: exists (this, "*", "apb_vif"))
`uvm_error ("VIF", "Could not find an interface handle", UVM_MEDIUM)

<4>. wait_modified()

block 直到要get的变量有改动
  static task wait_modified ( uvm_component cntxt,
string inst_name,
string field_name); class my_agent extends uvm_agent; virtual task run_phase (uvm_phase phase);
...
// Waits until loopCount variable gets a new value
uvm_config_db #(int) :: wait_modified (this, "", "loopCount");
endtask
endclass class my_env extends uvm_env; my_agent m_apb_agent; virtual task main_phase (uvm_phase phase);
...
// Update loopCount variable in database
for (int i = ; i < N; i++) begin
...
uvm_config_db #(int) :: set (this, "m_apb_agent", "loopCount", i);
end
endtask
endclass

<5>. typedef 定义的一些宏

  typedef  uvm_config_db #(uvm_bitstream_t)     uvm_config_int;
typedef uvm_config_db #(string) uvm_config_string;
typedef uvm_config_db #(uvm_object) uvm_config_object;
typedef uvm_config_db #(uvm_object_wrappet) uvm_config_wrapper;

systemverilog soft constraint的更多相关文章

  1. SV randomize

    randomize中的变量只支持2-state的values,不支持4-states. randc类型的变量不能被约束在solve------before的语句中. constraint可以被定义在c ...

  2. 【DeepLearning】一些资料

    记录下,有空研究. http://nlp.stanford.edu/projects/DeepLearningInNaturalLanguageProcessing.shtml http://nlp. ...

  3. systemverilog中奇怪的语法

    1.->运算符 expression_a->expression_b其实等效于(!expression_a || expression_b),systemverilog中利用 || 运算的 ...

  4. systemverilog.vim

    " Vim syntax file " Language: SystemVerilog " Maintainer: Stephen Hobbs <stephenh@ ...

  5. systemverilog的高亮显示

    1. 在_vimrc文件末尾添加: syntax on "确定vim打开语法高亮 filetype on "打开文件类型检测 filetype plugin on "为特 ...

  6. systemverilog FAQ(zz)

    1. What is clocking block? Ans: Clocking block can be declared using the keywords clocking and endcl ...

  7. systemverilog(3)之Randomize

    what to randomize? (1) primary input data <==one data (2)encapsulated input data <== muti grou ...

  8. [转载]转一篇Systemverilog的一个牛人总结

    原文地址:转一篇Systemverilog的一个牛人总结作者:dreamylife Systemverilog 数据类型 l       合并数组和非合并数组 1)合并数组: 存储方式是连续的,中间没 ...

  9. SystemVerilog基本语法总结(上)

    SystemVerilog基本语法总结(上) 在总结SV的语法之前,先分享一些关于SV的笔试题目,这样更显得具有针对性的总结. a. 验证中,代码覆盖率是指(衡量哪些设计代码在激活触发,而哪一些则一直 ...

随机推荐

  1. c# 简单方便的连接oracle方式

    通过nuget安装ManagedDataAccess (自动生成的config里面的配置都可以删掉) winform程序,拖出一个datagridview和button using Oracle.Ma ...

  2. 将golang中变量重置为零的reflect方法

    下面给出简单的代码,这里通过将变量重置为零来实现过滤字段的目的: type student struct { Age int `json:"age,omitempty"` Name ...

  3. win10.64位wnmp-nginx1.14.0 + PHP 5. 6.36 + MySQL 5.5.59 环境配置搭建 结合Thinkphp3.2.3

    本文20%是原创,另外参考了这里https://blog.csdn.net/foolly/article/details/78963025 作者:CSDN 古雨蓝枫 和这里https://www.cn ...

  4. Docker集中化web界面管理平台-Shipyard部署记录

    Docker图形页面管理工具基本常用的有三种: DOCKER UI,Shipyard,Portainer.对比后发现,Shipyard最强大,其次是Portainer,最后是Docker ui.之前介 ...

  5. Android学习笔记一之第一个Android程序

    /** *Title:总结昨天下午至今天上午的学习成果 *Author:zsg *Date:2017-8-13 / 一.了解Android 1.Android架构 Android大致可分为四层架构:L ...

  6. Magic xpa 3.x很容易将数据导出到Excel中

    Magic xpa 3.x很方便的将表中数据导出到Excel文件中,还可以自动将表中数据生成各种图表. 通过使用自带的打印数据内部事即可实现. 1.首先将打印数据任务属性设置为“是”. 2.可使用主程 ...

  7. docker学习记录

    Container 容器是一种基础工具, 泛指任何容纳其他物品的工具, 可以部分或者完全封闭,被用于容纳,储存, 运输物品, 物体可以放置在容器中, 而容器可以保护内容物 1 Docker Objec ...

  8. Android自定义万能Canvas画布

    一.需求: 1.在自定义的画布中实现可缩放手势,摇一摇可对控件进行整理排序: 2.画布中可以添加位置设定的控件,控件可以响应点击.长按.拖动事件: 3.控件A长按事件会隐藏画布中的控件除了A之外,显示 ...

  9. 部署GlusterFS及Heketi

    一.前言及环境 在实践kubernetes的StateFulSet及各种需要持久存储的组件和功能时,通常会用到pv的动态供给,这就需要用到支持此类功能的存储系统了.在各类支持pv动态供给的存储系统中, ...

  10. vue双向绑定的简单实现(原创)

    简单模拟一下vue的双向绑定实现,代码比较粗糙,菜鸟一枚,欢迎各位大佬斧正 1.实验环境: 利用a.b两个input,a代表页面中的数据,b代表data中的数据 2.原理: 利用Object.defi ...