其他分享
首页 > 其他分享> > UVM 怎么层次化引用其他component类中的属性

UVM 怎么层次化引用其他component类中的属性

作者:互联网

在UVM中我们一般是通过uvm_config_db机制来在不同的类间传递数据。但这需要在传出和传入的类中各加一段代码,

并且uvm_config_db机制较为麻烦,传递对象时还需要进行类型转换。那么能不能像SV一样通过类似$root的方式来直接

改变/获得其他类中的属性呢?答案是可以的。

类似于SV,SV中top module的上一级是$root, UVM中顶层类是uvm_root,它是所有parent = null 的类的parent类

(注意,此处不要和OOP中的父类混淆,UVM中 parent 和child不是派生关系也不一定是包含关系,仅仅是UVM中定义的一种关系)。

uvm_root的唯一实例是uvm_top。

若有如下test case:

class test_case extends uvm_test;
    ....
endclass

通过run_test("test_case")调用。那么uvm_top有唯一的child(因此每次run的时候只会有一个test), 其 实例为uvm_test_top。uvm_test_top是

uvm_top的child,但uvm_top中没有uvm_test_top这个属性(parent child 不一定是包含关系)。可以通过如下方式引用到uvm_test_top:

package glob;
     uvm_component uvm_test_top_handle;
     test_case     glb;
     int glob_variable; //package中也可以放全局变量 
     uvm_test_top_handle = uvm_top.get_child("uvm_test_top");
     $cast(glb, uvm_test_top_handle);
     
     //glb就是指向uvm_test_top, 类型为test_case的句柄
  
endpackage

 

然后就可以直接引用其他类中的变量了

//上面语句放在package中就可以在各个类中引用了。 
import glob::*;
//test_case下有agent, 修改agent中属性i glb.agt.i = 1; //或者... $display(glb.agt.drv.j);

 

标签:层次化,case,top,component,UVM,child,test,uvm
来源: https://www.cnblogs.com/liutang2010/p/15870606.html