UVM学习笔记(一)工厂、phase机制、config
目录
- 一、工厂机制
- 1.1 使用步骤
- 1.2 um_coreservice_t类
- 1.3 factory创建component、object实例的方法
- 1.4 UVM创建component、object实例的方法
- 1.5 T::type_id::create()
- 二、覆盖方法
- 2.1 set_type_override(): 类型覆盖
- 2.2 set_inst_override(): 实例覆盖
- 三、核心基类 uvm_object
- 3.1 field_automation机制
- 3.1.1 注册数据类型相关的宏
- 3.1.2 提供函数
- 3.1.2.1 copy
- 3.1.2.2 copy和clone
- 3.1.2.3 compare
- 3.1.2.4 print
- 四、 ==phase机制==
- 4.1 执行机制:自顶向下
- 4.2 run_phase
- 4.3 UVM编译和运行机制
- 4.4 运行UVM
- 4.5 控制仿真退出 uvm_objection
- 五、config机制
- 5.1 uvm_config_db
- 5.2 interface传递
- 5.3 变量传递
- 5.4 object传递
- 5.5 总结
- 六、消息管理
- 6.1 消息方法
- 6.2 消息处理
- 6.3 消息宏
- 6.4 消息机制
- 6.5 回调函数
一、工厂机制
1.1 使用步骤
①定义
②注册
③创建
class comp1 extends uvm_component;//父类为component`uvm_component_utils(comp1)//1.把该类注册到工厂中function new(string name = "comp1", uvm_component parent = null);//name和parentsuper.new(name, parent);//继承父类的new$display($sformatf("%s is created", name);endfunction: newfunction void build_phase(uvm_phase phase);super.build_phase(phase);endfunction:build_phase
endclass
class obj1 extends uvm_object;//父类为object`uvm_object_utils(obj1);//1.把该类注册到工厂中function new(string name = "obj1");//namesuper.new(name);$display($sformatf("%s is created", name);endfunction:new
endclass
comp1 c1, c2;
obj1 o1,o2;
initial beginc1 = new("c1");o1 = new("o1");c2 = comp1::type_id::create("c2",null);//创建o2 = obj1::type_id::create("o2");
end
1.2 um_coreservice_t类
●唯一的uvm_factory, 该组件用来注册、覆盖和例化
●全局的report_server, 该组件用来做消息统筹和报告
●全局的tr_database, 该组件用来记录transaction记录
●get_root()方法用来返回当前UVM环境的结构顶层对象
通过uvm_coreservice_t将最重要的机制(也是必须做统一例化处理的组件)都放置在了uvm_coreserice_t类中。
1.3 factory创建component、object实例的方法
trans t3;
uvm_factory f = uvm_factory::get();
//create_object_by_type (uvm_object_wrapper requested_type,
// string parent_inst_path="",
// string name="");
void'($cast(t3,f.create_object_by_type(trans::get_type(),get_full_name(),"t3")));
1.4 UVM创建component、object实例的方法
//create_object (string requested_type_name,
// string name="");
void'($cast(t4,create_object("trans","t4")));
1.5 T::type_id::create()
//trans::type_id::create(string name, uvm_component parent = null); trans::type_id::create("t",this);
二、覆盖方法
覆盖发生时,可以使用“类型覆盖”或者“实例覆盖”
●类型覆盖指,UVM层次结构下的所有原有类型都被覆盖类型所替换。
●实例覆盖指,在某些位置中的原有类型会被覆盖类型所替换。
2.1 set_type_override(): 类型覆盖
comp1::type_id::set_type_override(comp2::get_type());
// function void set_type_override_by_type
// (uvm_object_wrapper original_type,
// uvm_object_wrapper override_type,
// bit replace=1)set_type_override_by_type(trans::get_type(),bad_trans::get_type(),1);
// replace unit type with big type with method
// function void set_type_override(string original_type_name,
// string override_type_name,
// bit replace=1);
set_type_override("uint","big_uint");
2.2 set_inst_override(): 实例覆盖
comp1::type_id::set_inst_override(comp2::get_type(),{parent.get_full_name(),'.',inst_path});
关键点:com2继承com1,要覆盖的方法,父类需要加virtual
先覆盖,在例化
层次越高,覆盖的优先级越高
module factory_override;import uvm_pkg::*;//要使用UVM,必须要import`include "uvm_macros.svh"class comp1 extends uvm_component;//1.定义`uvm_component_utils(comp1)//2.注册function new(string name="comp1",uvm_component parent = null);super.new(name);$display($sformatf("comp1:: %s is created",name));endfunction:newvirtual function void hello(string name);$display($sformatf("comp1:: %s said hello",name));endfunctionendclassclass comp2 extends comp1;//1.定义`uvm_component_utils(comp2)//2.注册function new(string name="comp2",uvm_component parent = null);super.new(name);$display($sformatf("comp2:: %s is created",name));endfunction:newvirtual function void hello(string name);$display($sformatf("comp2:: %s said hello",name));endfunctionendclasscomp1 c1,c2;initial begincomp1::type_id::set_type_override(comp2::get_type());//comp2覆盖了comp1c1 = new("c1");c2 = comp1::type_id::create("c2",null);//3.创建:类型覆盖c1.hello("c1");//调用c1的函数c2.hello("c2");//调用c2的函数
endmodule
三、核心基类 uvm_object
3.1 field_automation机制
- UVM通过域的自动化,使得用户在注册UVM类的同时也可以声明今后会参与到对象拷贝、克隆、打印等操作的成员变量。
- 用户需要考虑哪些成员变量在注册UVM类( “uvm_{component, object}_utils) 的时候,也一并将它们归置到对应的域列表中,以便为稍后的域方法提供可以自动实现的基础。
3.1.1 注册数据类型相关的宏
`uvm_field_int(a, UVM_ALL_ON)
`uvm_field_real(a, UVM_HIGH)
`uvm_field_enum(T, a, UVM_LOW)
`uvm_field_object(a, UVM_ALL_ON)
`uvm_field_event(a, UVM_ALL_ON)
`uvm_field_string(a, UVM_ALL_ON)
`uvm_field_array_int(a, UVM_ALL_ON)
`uvm_field_array_string(a, UVM_ALL_ON)
`uvm_field_array_object(a, UVM_ALL_ON)
`uvm_field_array_enum(a, UVM_ALL_ON)
....P70
3.1.2 提供函数
- void copy(uvm_object rhs); //B.copy(A); A实例复制到B实例中
- uvm_object clone();//$cast(B, A.clone());无法用于component类
- bit compare(uvm_object rhs, uvm_comparer comparer = null);//A.compare(B);
- A.print();
- pack/unpack; pack_bytes/unpack_bytes; pack_int/unpack_int//打包成数据流和恢复到某个类的实例中
3.1.2.1 copy
class box extends uvm_object;int volume = 120 ;color_t color = WHITE ; string name = "box" ;//域自动化`uvm_object_utils_begin(box)`uvm_field_int (volume, UVM_ALL_ON)//数据操作`uvm_field_enum(color_t,color, UVM_ALL_ON)`uvm_field_string(name, UVM_ALL_ON)uvm_object_utils_end
endclass
box b1, b2 ;
initial beginb1 = box::type_id::create("box1");b1.volume = 80;b1.color = BLACK; .b2 = new();b2.copy(b1);//UVM自动实现b2.name = "box2";
end
3.1.2.2 copy和clone
copy: 创建好了对象,只copy数据
clone:先创建对象,再copy,并返回句柄
class ball extends uvm_ object ;int diameter = 10;color_t color = RED;`uvm_object_utils_begin(ball)`uvm_field_int(diameter, UVM_DEFAULT)`uvm_field_enum(color_t, color, UVM_NOCOPY)//不copyuvm_object_utils_endfunction void do_copy(uvm_object_rhs);//copy的回调函数ball b;$cast(b, rhs) ;$display ("ba11::do_copy entered. .") ;if(b.diameter <= 20) diameter = 20;endfunction
endclassclass box extends uvm_object;int volume = 120 ;color_t color = WHITE ;string name = "box" ;ball b;`uvm_object_utils_begin (box)`uvm_field_int(volume, UVM_ALL_ON)`uvm_field_enum(color_t, color, UVM_ALL_ON)`uvm_field_string(name, UVM_ALL_ON)`uvm_field_object(b, UVM_ALL_ON)uvm_object_utils_end
endclassbox b1,b2 ;
initial beginb1 = new ("box1") ;b1.volume = 80 ;b1.color = BLACK;b1.b.color = WHITE ;b2 = new() ;b2.copy(b1) ;b2.name = "box2";$display ("%s", b1.sprint()) ;$display("%s", b2.sprint()) ;
end
3.1.2.3 compare
class box extends uvm_object;int volume = 120;color_t color = WHITE;string name = "box" ;`uvm_object_utils_begin(box)...uvm_object_utils_end
endclassbox b1, b2 ;
initial beginb1 = new("box1") ;b1.volume = 80;b1.color = BLACK;b2 = new ("box2") ;b2.volume = 90;uvm_default_comparer.show_max = 10;//比较10个if (!b2.compare(b1)) begin`uvm_info("COMPARE","b2 comapred with b1 failure", UVM_LOW)endelse begin`uvm_info("COMPARE","b2 comapred with b1 succes", UVM_LOW)end
end
//comparer的回调函数
function bit do_compare(uvm_object rhs, uvm_comparer comparer);trans t;do_compare = 1;void'($cast(t, rhs));if(addr != t.addr) begindo_compare = 0;`uvm_warning("CMPERR", $sformatf("addr %8x != %8x", addr, t.addr))endif(data != t.data) begindo_compare = 0;`uvm_warning("CMPERR", $sformatf("data %8x != %8x", data, t.data))endif(op != t.op) begindo_compare = 0;`uvm_warning("CMPERR", $sformatf("op %s != %8x", op, t.op))endif(addr != t.addr) begindo_compare = 0;`uvm_warning("CMPERR", $sformatf("name %8x != %8x", name, t.name))endendfunction
3.1.2.4 print
class box extends uvm_ object ;int volume = 120 ;color_t color = WHITE; string name = "box" ;`uvm_object_utils_begin(box)...
endclassbox b1 ;
uvm_table_printer local_printer;//声明printer的句柄
initial beginb1 = new("box1") ;local_printer = new();//例化$display ("default table printer format") ;b1.print() ;//默认的table形式$display ("default line printer format") ;uvm_default_printer = uvm_default_line_printer ;//line形式,这些已经被例化了,不需要再例化了b1.print() ;$display ("default tree printer format") ;uvm_default_printer = uvm_default_tree_printer ;//tree形式b1.print() ;$display ("customized printer format") ;local_printer.knobs.full_name = 1 ;b1.print(local_printer) ;//传入自己设定的打印规则
end
四、 phase机制
4.1 执行机制:自顶向下
4.2 run_phase
- 上电
- 复位
- 寄存器配置
- 发送主要测试内容
- 等待DUT完成测试
4.3 UVM编译和运行机制
4.4 运行UVM
+UVM_TESTNAME = <>来选择test
task run_test(string test_name = "");uvm_root top;//唯一顶层uvm_coreservice_t cs;cs = uvm_coreservice_t::get();//获取coreservice全局唯一的实例top = cs.get_root();//利用coreservice获取全局顶层top.run_test(test_name);//运行
endtask
4.5 控制仿真退出 uvm_objection
仿真过程中,所有component和sequence都可以挂起objection,且至少要有一个组件将objection挂起,防止仿真退出
class test1 extends uvm_test ;task run_phase(uvm_phase phase) ;phase.raise_objection(this) ;//挂起当前组件,输入参数为this,run_phase以objection为主uvm_info("run phase", "entered . .",UVM_LOW)#1us;uvm_info("run_ phase", "exited . .", UVM_LOW)phase.drop_objection(this);//落下当前组件endtask
endclass
五、config机制
config机制用于参数传递
传递父类的句柄;转到子类void’($cast(dst,src))
传递参数类型保持一致
传递路径保持一致
5.1 uvm_config_db
- 传递interface到环境中
- 设置单一变量值,如int,string,enum
- 传递配置对象(config object)到环境
//顶层环境set,底层环境get
uvm_config_db#(T)::set(uvm_component cntxt, string inst_name, string feild_name,T value);//实例,实例的名字,实例对应的某个变量,值
uvm_config_db#(T)::get(uvm_component cntxt, string inst_name, string feild_name, inout T value);//set,get在组件里面使用
5.2 interface传递
interface intf1;logic enable = 0;
endinterface
class comp1 extends uvm_component;`uvm_component_utils(comp1)virtual intf1 vif;//句柄...//newfunction void build_phase(uvm_phase phase);if(!uvm_config_db#(virtual intf1)::get(this,"","vif",vif))begin//#(virtual intf1):要传递的参数类型//this: 当前的组件,comp1//"":component里面的实例,这里面没有实例//"vif":变量名//前三个变量共同得到路径uvm_root.test.c1.vif,从中拿到virtual intf1传递给vif`uvm_error("GETVIF","no virtual interface is assigned")end`uvm_info("SETVAL",$sformatf("vif.enable is %b before set", vif.enable), UVM_LOW);vif.enable = 1;`uvm_info("SETVAL",$sformatf("vif.enable is %b after set", vif.enable), UVM_LOW);endfunction
endclass
//顶层
class test1 extends uvm_test;`uvm_component_utils(test1)comp1 c1;...
endclass
intf1 intf();//
initial beginuvm_config_db#(virtual intf1)::set(uvm_root::get(), "uvm_test_top.c1", "vif",intf);//run_test之前,build_phase之前//#(virtual intf1):要传递的参数类型//uvm_root::get(): 传递一个uvm_root的句柄//"uvm_test_top.c1":实例,uvm_test_top下的c1//"vif":变量名//intf:将这个指针存放在路径中//前三个变量共同得到路径uvm_root.uvm_test_top.c1.vif,从中拿到virtual intf1传递给vifrun_test("test1") ;//root-test-c1
end
5.3 变量传递
5.4 object传递
要配置的参数多,且分属不同的组件,将每个组件的变量整合,放置到uvm_object中,再讲该对象进行传递
//将要传递的变量放到父类为object的类中
class config1 extends uvm_object ;int val1 = 1;int str1 = "null" ;`uvm_object_utils(config1)
endclass
//底层
class comp1 extends uvm_component;`uvm_component_utils(comp1)config1 cfg;function void build_phase (uvm_phase phase) ;uvm_object tmp ;uvm_config_db# (uvm_object)::get (this,"" ,"cfg", tmp) ;void' ($cast(cfg, tmp));//父类句柄,转换为子类句柄调用值,也可以直接传递子类`uvm_info ("SETVAL",$sformatf("cfg.va11 is %d after get", cfg.val1), UVM_LOW)`uvm_info ("SETVAL",$sformatf("cfg.str1 is %s after get", cfg.str1), UVM_LOW)endfunction
endclass
//顶层
class_test1 extends uvm_test;uvm_component_utils(test1)comp1 c1, c2 ;config1 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.va11 = 50 ;cfg2.str1= "c2" ; //父类句柄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
5.5 总结
1. 先set()在get(),成对出现2. 传输类型要保持一致3. 路径,*表示通配,任意路径
六、消息管理
6.1 消息方法
6.2 消息处理
6.3 消息宏
6.4 消息机制
6.5 回调函数
set_report_severity_action(UVM_ERROR,UVM_DISPLAY | UVM_CALL_HOOK);//对于ERROR这个级别,不仅要打印还要调用其回调函数
set_report_verbosity_level(UVM_LOW);//只打印UVM_LOW及更重要的UVM_NONEset_report_verbosity_level_hier(UVM_NONE);//禁用this下所有UVM消息
set_report_id_verbosity_hier("BUILD", UVM_NONE);//禁用this下的“CREATE”,“BUILD”,“RUN”ID消息
uvm_root::get().set_report_id_verbosity_hier("CREATE", UVM_NONE);//禁用this下的“CREATE”,“BUILD”,“RUN”ID消息
UVM学习笔记(一)工厂、phase机制、config相关推荐
- UVM学习笔记—前门访问/后门访问
目录 0.前言 1.前门访问 2.后门访问 2.1路径设置 2.2操作类型 0.前言 在UVM学习笔记-寄存器模型的搭建及使用中提到过前门访问和后门访问的概念,这篇文章将会详细的阐述一下这2种访问方式 ...
- 设计模式学习笔记——抽象工厂(Abstract Factory)模式
设计模式学习笔记--抽象工厂(Abstract Factory)模式 @(设计模式)[设计模式, 设计模式中文名, 设计模式英文名] 设计模式学习笔记抽象工厂Abstract Factory模式 基本 ...
- Apache Nutch 1.3 学习笔记十(插件机制分析)
1. 一些对象说明 PluginRepository:这是一个用于存储所有插件描述对象(PluginDescriptor),插件扩展点(ExtensionPoint)和被激活的插件. PluginDe ...
- Python3.7学习笔记30-垃圾回收机制
Python3.7学习笔记30-垃圾回收机制 一.前言 Python 程序在运行的时候,需要在内存中开辟出一块空间,用于存放运行时产生的临时变量:计算完成后,再将结果输出到永久性存储器中.如果数据量过 ...
- UVM学习笔记—快速入门篇
UVM指的是验证方法学,是学习数字验证的入门课程.它是至关重要的,有不少人往IC验证方向发展的,多多少少都会去了解UVM.但UVM并不是简单的翻个书就可以学会的,还是要掌握学习方法或者跟着老师学习的. ...
- 软件工程作业-方舟学习笔记01-认识phase
上一篇是分析方舟编译器的准备阶段,这一篇开始正式开扒. 吃饭的时候看到了一篇非常好的博客↓ https://www.zhihu.com/column/c_1187372958643941376 答主I ...
- uvm学习笔记----适合新手快速学习
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-ofH8i8OK-1635320932444)(C:\Users\lenovo\AppData\Roaming\Typor ...
- 【学习笔记】自注意力机制self-attention
文章目录 注意 引言 self-attention 自注意力机制 多头自注意力机制 图像中的自注意力机制 注意 本篇文章参考李宏毅老师的讲课视频,截图均来自老师的PPT,本文是学习笔记.原视频大家可以 ...
- UVM学习笔记--sequence和sequencer
1. UVM sequence机制的意义 UVM的sequence机制最大的作用就是将test case和testbench分离开来. 对一个项目而言,testbench是相对稳定的框架,而针对各个m ...
最新文章
- [NC19798]区间权值
- Debian/Ubuntu--blade安装与使用
- 【干货分享】流程DEMO-人员调动流程
- python主要学哪些课程_Python学习课程大纲自学Python参考
- 2021-03-29 标准化函数
- java 定时器代码_Java定时器代码的编写
- phpvirtualbox+Virtualbox完整虚拟化环境部署
- python十条建议_十条建议帮你提高Python编程效率
- 有什么是你追了很多女生都失败后才知道的?
- bash脚本编程入门_Bash编程入门
- 1431. 拥有最多糖果的孩子
- linux命令大全文档,LINUX命令大全文档
- linuxmove命令_linux中mv命令使用详解
- 吃易消化吸收的东西利于长寿
- 初识 Node.js
- Cross-validation 交叉验证
- MATLAB插值函数_akala啦_新浪博客
- 单片机攻略3——C51入门
- chrome单击打开标贴在当前窗口的新标签页设置
- 互联网晚报 | 12月8日 星期三 | 淘宝购物车上线“好友买单”功能;英超联赛正式入驻视频号;中国联通成立5G消息生态联盟...