uvm实战学习笔记.docx
《uvm实战学习笔记.docx》由会员分享,可在线阅读,更多相关《uvm实战学习笔记.docx(32页珍藏版)》请在冰豆网上搜索。
![uvm实战学习笔记.docx](https://file1.bdocx.com/fileroot1/2022-10/12/f7deffc6-ca68-407a-b781-b66bdfe7acac/f7deffc6-ca68-407a-b781-b66bdfe7acac1.gif)
uvm实战学习笔记
uvm实战-学习笔记
《UVM实战(卷1)》学习笔记
看了第1/2/3/4/5/6/8/9.1这几个章节。
第一章是综述,第二章是一个具体的例子,学习笔记从第三章相关内容开始。
我个人觉得UVM重要的部分(特点的部分):
1)factory机制(overrideconfig_db)
2)TLM传递
3)phase机制
4)sequence-sequencer以及virtualseq/sqr
内容中的截图基本来自于UVM源代码、书自带的例子和《uvm1.1应用指南及源代码分析》这个PDF里的。
需要结合书(《UVM实战(卷1)》第1版)来看这个笔记。
第3章UVM基础
3.1uvm_component和uvm_object
常用的类名字:
这个图是从作者张强的《uvm1.1应用指南及源代码分析》里截得,不如书上3.1.1里的图好。
uvm_sequencer也是代码里必须有的,所以我加了uvm_sequencer
uvm_void是一个空的虚类。
在src/base/uvm_misc.svh中定义:
红框的是我们搭testbench的时候用的比较多的基类。
常用的uvm_object派生类:
sequencer给driver的transaction要派生自uvm_sequence_item,不要派生自uvm_transaction
所有的sequence要派生自uvm_sequence或者uvm_sequence的派生类,可以理解为sequence是sequence_item的组合(集合)。
driver向sequencer索要item,sequencer检查是否有sequence要发送item,当发现有item待发送时,就把这个item发给driver.
常用的uvm_component派生类:
所有的driver要派生自uvm_driver.driver用来把sequence_item中的信息驱动到DUT端口上,从transaction-level向signal-level的转换。
uvm_driver需要参数(REQRSP),比uvm_component增加了几个成员。
重要的是seq_item_port和req/rsp.(src/comps/uvm_driver.svh)
monitor/scoreboard派生自uvm_monitor和uvm_scoreboard,但是uvm_monitor和uvm_scoreboard并没有在uvm_component基础上做扩展。
src/comps/uvm_monitor.svh
sequencer要派生自uvm_sequencer.sequencer做了很多扩展,但是如果我们自己写的sequencer里没有增加成员的话,可以直接写如下代码:
typedefuvm_sequencer#(传递的sequence_item类名)sequencer类名;
因为sequencer在agent中例化,所以一般写在agent类文件里。
reference_model派生自uvm_component.
agent要派生自uvm_agent.uvm_agent里多了一个is_active的成员。
一般根据这个active来决定是否实例化driver和sequencer.is_active变量的数值需要在env的build_phase里设置完成(可以直接设置,也可以用uvm_config_db#(int):
:
set)。
env要派生自uvm_env.uvm_env没有对uvm_component扩展。
src/comps/uvm_env.svh
所有的test都要派生自uvm_test或者它的派生类。
uvm_test也没扩展
src/comps/uvm_test.svh
uvm_object和uvm_component的macro
macro非常重要,事关把这些类的对象注册到factory机制中去。
uvm_objectmacro
1)对于uvm_sequence_item就统一用(假设不用parameter):
`uvm_object_utils_begin(item类名)
….field_automation…
`uvm_object_utils_end
2)对于uvm_sequence,要加上
`uvm_object_utils(sequence类名)
可能还需要`uvm_declare_p_sequencer(sequencer类名)的声明
uvm_componentmacro
对于drivermonitorreference_modelscoreboardsequencercaseagentenv这些uvm_component派生类都要加上:
`uvm_component_utils(类名)
uvm_component里的成员也可以像uvm_object里成员一样,用field_automation机制。
field_automation机制:
对于uvm_object派生类来说,field_automation机制让对象自动有的copycompareprintpackunpack等函数,简化了实现uvm_component派生类里一些function/task的工作量
对于uvm_component派生类来说,field_automation机制最重要的是可以在build_phase中自动获取uvm_config_db#():
:
set()的数值(必须加super.build_phase(phase))----也就是不用写uvm_config_db#():
:
get()
注意:
field_automation的macro的类型要和uvm_config_db的参数类型一致:
如下示例代码,field_intvsuvm_config_db#(bit[47:
0])这个时候super.build_phase()是不起作用的。
想要起作用的话,需要用
clone=new+copy源代码中可以看到clone函数一上来会做一次create,然后调copy函数
src/base/uvm_object.svh
3.2UVM的树形结构
uvm_component的new/create要注意第一个参数是名字,第二个参数是parent指针。
UVM真正的树根是“uvm_top”.根据上面这个树结构,可以看出一个个component的parent是什么。
uvm_top的parent是null。
当一个component在实例化的时候,如果parent参数设成null,那么parent参数会被仿真器自动设置成uvm_root的实例uvm_top.
在6.6.1章节里也提到了,sequence在uvm_config_db#():
:
get()的时候,第一个参数设成“null”,实际就是uvm_root:
:
get()3.5.1章节也提到了这个
层次结构函数:
get_parent()get_child(stringname)这两个分别获取parent指针和指定名字的child指针。
get_children(refuvm_componentchildren[$])获取所有的child指针
get_num_children()获取child个数
get_first_child(refstringname)get_next_child(refstringname)获取child的名字(反映到stringname上),返回值是0/1两种情况
应用参考代码如下(改动的2.5.2例子中的my_agent.sv):
注意:
上述代码是在connet_phase中实现的。
上述代码的打印结果如下:
my_agent'snameisuvm_test_top.env.i_agt,parent'sfullpathisuvm_test_top.env,childrennumis3
uvm_test_top.env.i_agt0child:
drv-->fullpath:
uvm_test_top.env.i_agt.drv
uvm_test_top.env.i_agt1child:
mon-->fullpath:
uvm_test_top.env.i_agt.mon
uvm_test_top.env.i_agt2child:
sqr-->fullpath:
uvm_test_top.env.i_agt.sqr
Thisshouldbei_agt.my_agent'snameisuvm_test_top.env.i_agt
uvm_test_top.env.i_agtfirstchildnameisdrv
uvm_test_top.env.i_agtnextchildnameismon
uvm_test_top.env.i_agtnextchildnameissqr
my_agent'snameisuvm_test_top.env.o_agt,parent'sfullpathisuvm_test_top.env,childrennumis1
uvm_test_top.env.o_agt0child:
mon-->fullpath:
uvm_test_top.env.o_agt.mon
UVM_WARNING/tools/synopsys/vcs/G-2012.09/etc/uvm/src/base/uvm_component.svh(1846)@0:
uvm_test_top.env.o_agt[NOCHILD]Componentwithname'drv'isnotachildofcomponent'uvm_test_top.env.o_agt'
Thisshouldbeo_agt.my_agent'snameisuvm_test_top.env.o_agt
uvm_test_top.env.o_agtfirstchildnameismon
3.3fieldautomation机制
注意数组类型的fieldmacro比一般的要少real和event的macro.一般的对于enum类型有3个参数,而数组的只有2个参数。
联合数组的macro比较多
常用函数需要注意packunpackpack_bytesunpack_bytespack_intsunpack_ints返回值都是bit个数。
field-automation标记位
17bit中bit0→copybit1→no_copybit2→comparebit3→no_comparebit4→printbit5→no_printbit6→recordbit7→no_recordbit8→packbit9→no_pack
UVM_ALL_ON是‘b000000101010101
UVM_ALL_ON|UVM_NO_PACK这样就会忽略掉packbit
field-automation的macro可以和if结合起来,参考3.3.4的代码
`uvm_object_utils_begin(my_transaction)
`uvm_field_int(dmac,UVM_ALL_ON)
`uvm_field_int(smac,UV