uvm实战-学习笔记 下载本文

对于driver monitor reference_model scoreboard sequencer case agent env这些uvm_component派生类都要加上: `uvm_component_utils(类名)

uvm_component里的成员也可以像uvm_object里成员一样,用field_automation机制。

field_automation机制:

对于uvm_object派生类来说,field_automation机制让对象自动有的copy compare print pack unpack等函数,简化了实现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_int vs uvm_config_db#(bit[47:0]) 这个时候super.build_phase()是不起作用的。

想要起作用的话,需要用

clone = new + copy 源代码中可以看到clone函数一上来会做一次create,然后调copy函数 src/base/uvm_object.svh

3.2 UVM的树形结构

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(string name) 这两个分别获取parent指针和指定名字的child指针。 get_children(ref uvm_component children[$]) 获取所有的child指针 get_num_children() 获取child个数

get_first_child(ref string name) get_next_child(ref string name) 获取child的名字(反映到string name上),返回值是0/1两种情况

应用参考代码如下(改动的2.5.2例子中的my_agent.sv):

注意:上述代码是在connet_phase中实现的。 上述代码的打印结果如下:

my_agent's name is uvm_test_top.env.i_agt, parent's full path is uvm_test_top.env, children num is 3

uvm_test_top.env.i_agt 0 child: drv --> full path:uvm_test_top.env.i_agt.drv uvm_test_top.env.i_agt 1 child: mon --> full path:uvm_test_top.env.i_agt.mon uvm_test_top.env.i_agt 2 child: sqr --> full path:uvm_test_top.env.i_agt.sqr This should be i_agt. my_agent's name is uvm_test_top.env.i_agt uvm_test_top.env.i_agt first child name is drv uvm_test_top.env.i_agt next child name is mon uvm_test_top.env.i_agt next child name is sqr

my_agent's name is uvm_test_top.env.o_agt, parent's full path is uvm_test_top.env, children num is 1

uvm_test_top.env.o_agt 0 child: mon --> full path: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] Component with name 'drv' is not a child of component 'uvm_test_top.env.o_agt'

This should be o_agt. my_agent's name is uvm_test_top.env.o_agt uvm_test_top.env.o_agt first child name is mon

3.3 field automation 机制

注意数组类型的field macro比一般的要少real和event的macro. 一般的对于enum类型有3个参数,而数组的只有2个参数。 联合数组的macro比较多

常用函数需要注意 pack unpack pack_bytes unpack_bytes pack_ints unpack_ints 返回值都是bit个数。

field-automation标记位

17bit中 bit0?copy bit1?no_copy bit2?compare bit3?no_compare bit4?print bit5?no_print bit6?record bit7?no_record bit8?pack bit9?no_pack UVM_ALL_ON是 ‘b000000101010101

UVM_ALL_ON|UVM_NO_PACK 这样就会忽略掉pack bit

field-automation的macro可以和if结合起来,参考3.3.4的代码 `uvm_object_utils_begin(my_transaction) `uvm_field_int(dmac, UVM_ALL_ON) `uvm_field_int(smac, UVM_ALL_ON) if(is_vlan)begin `uvm_field_int(vlan_info1, UVM_ALL_ON) `uvm_field_int(vlan_info2, UVM_ALL_ON) `uvm_field_int(vlan_info3, UVM_ALL_ON) `uvm_field_int(vlan_info4, UVM_ALL_ON) end `uvm_field_int(ether_type, UVM_ALL_ON) `uvm_field_array_int(pload, UVM_ALL_ON) `uvm_field_int(crc, UVM_ALL_ON | UVM_NOPACK) `uvm_field_int(is_vlan, UVM_ALL_ON | UVM_NOPACK) `uvm_object_utils_end

这个is_vlan变量可以在sequence里约束成0或1,来实现vlan或非vlan

ps: 我觉得这个地方代码其实写成像3.3.3里的有一个crc_error的rand bit的更合理一些。然后crc_error是UVM_ALL_ON|UVM_NOPACK,而crc是UVM_ALL_ON

3.4 UVM打印信息控制

get_report_verbosity_level()

set_report_verbosity_level(UVM_HIGH) 只对当前调用的component起作用

set_report_verbosity_level_hier(UVM_HIGH) 对当前及下面所有的component起作用 simv +UVM_VERBOSITY=UVM_HIGH 命令行方式 ------ 我觉得用这个就可以了 重载打印信息:

set_report_severity_override(UVM_WARNING,UVM_ERROR);