UVM的其他机制

一. field automation机制

1.概述

        使用 `uvm_field 系列宏注册类中的所有字段(成员变量)。类中的成员变量类型决定了要使用什么样的 `uvm_field 宏:如int型变量,使用`uvm_field_int宏;string型变量,则使用 `uvm_field_string宏等。

范式:`define uvm_field_数据类型(变量名,标志位)

        该机制多用于产生 transaction。使用该机制,我们能够很方便的用 transaction 的成员函数,比如 print()compare()(这个在 scoreboard 用的比较多)、pack()(这个函数在 driver 用的比较多)、unpack()(这个在 monitor 用的比较多)等等。在使用`uvm_field 系列宏进行注册后,就可以直接调用基类中的这些常用方法,而无需自己定义,提高了验证平台搭建的效率。

2.常用函数

(1)copy

把A实例复制到B实例中,B.copy(A)。

使用copy前,B必须使用new实例化。

(2)compare

比较A与B是否一致,A.compare(B)。

结果一致返回1,否则返回0。

(3)pack

将所有的字段打包为bit流

(4)unpack

将一个bit流逐一恢复到某个类的实例中

(5)print

打印所有的字段

(6)clone

clone=new+copy

uvm component 不可以用clone,只能用copy。

二.config db机制

        config_db机制用在UVM验证平台间传递参数。

1) 传递virtual interface到环境中去
2) 设置单一的变量值,例如int、string、enum等
3) 传递配置对象到环境中

uvm_config_db#(T)::set(this,''env.i_agent.drv'', "pre_num",100);

        set函数有四个参数,第一个和第二个组成目标路径,第三个为传递给成员名,第四个为值。


uvm_config_db#(T)::get(this,"", "pre_num", pre_num);

        get函数有四个参数,第一个和第二个组成目标路径,第三个与set必须一致,第四个为要设置的变量

三.callback机制

        callback机制最大用处就是提高验证平台的可重用性。此外,还用于构建异常的测试用例。

操作步骤

        1.定义一个基类

        然后在基类中定义所需要的callback方法,必须是虚方法(将在子类中重载)

class Driver_callback extends uvm_callback;
    virtual task pre_send(); endtask
    virtual task post_send(); endtask
endclass : Driver_callback 

        声明一个Driver_callback_pool的池子,指明被哪个类使用;

        2.使用uvm_register_cb宏来注册上面定义的基类

class Driver extends uvm_component;

`uvm_component_utils(Driver)

`uvm_register_cb(Driver,Driver_callback)

function new (string name, uvm_component parent=null);
super.new(name,parent);
endfunction

endclass

        使用uvm_do_callbacks宏

        这个宏函数有三个参数,第一个参数必须是Driver类名字,这个类会调用callback方法,第二个必须是使用的callback基类的名字,表示这个基类含有callback方法,第三个是所要调用的callback方法名字(如果有参数需要带上参数)。

virtual task run();

repeat(2) begin
`uvm_do_callbacks(Driver,Driver_callback,pre_send())
$display(" Driver: Started Driving the packet ...... %d",$time);
// Logic to drive the packet goes hear
// let's consider that it takes 40 time units to drive a packet.
#40;
$display(" Driver: Finished Driving the packet ...... %d",$time);
`uvm_do_callbacks(Driver,Driver_callback,post_send())
end
endtask

        3.扩展基类,重载callback方法

class Custom_Driver_callbacks_1 extends Driver_callback;

function new (string name = "Driver_callback");
super.new(name);
endfunction

virtual task pre_send();
$display("CB_1:pre_send: Delaying the packet driving by 20 time units. %d",$time);
#20;
endtask

virtual task post_send();
$display("CB_1:post_send: Just a message from post send callback method \n");
endtask

endclass

4.添加callback实例到uvm_callback_pool中

        在testcase中实例化该类,并使用uvm_callbacks类的静态方法add将该类添加到“池子”里。注意uvm_callbacks使用时也有两个参数,第一个是Driver的类名字,第二个是callback基类名字。add方法也有两个参数,第一个是Driver在验证环境中的实例路径,指定是哪个Driver使用的,第二个就是扩展callback类实例的名字。也就是说前面的参数都是使用类的名字,只有在add方法这里使用的是实例名。

module test;

initial begin
Driver drvr;
Custom_Driver_callbacks_1 cb_1;
drvr = new("drvr");
cb_1 = new("cb_1");
uvm_callbacks #(Driver,Driver_callback)::add(drvr,cb_1);
uvm_callbacks #(Driver,Driver_callback)::display();
run_test();
end

endmodule


 

四.消息打印机制

1.冗余度

typedef enum{
	UVM_NONE = 0,
	UVM_LOW = 100,
	UVM_MEDIUM = 200,
	UVM_HIGH = 300,
	UVM_FULL = 400,
	UVM_DEBUG = 500
} uvm_verbosity;

        每个component都有其过滤度阈值,默认为UVM_MEDIUM,如果某个消息的过滤度 ≤ 过滤度阈值,就会打印,否则就不打印。

        例如,冗余度设置为UVM_HIGH,则UVM_HIGH // LOW // MEDIUM // NONE,都会被打印

set_report_verbosity_level                设置某个component默认的冗余度

2.严重性

         set_report_max_quit_count                 设置error出现的退出阈值

还可以通过set_report_severity_action                将warning、info加入计数

set_report_severity_file(级别,log名)                将输出信息导入文件中

        UVM中有很多预定义的宏以及方法,但是不需要每个都记住甚至知道,我感觉更重要的是思想和理解。手撕代码也是,撕不出来或者有瑕疵无所谓,只要思路清晰,至少后续再学也会很快。个人愚见,重在理解,知道能完成这个功能,之后具体实现查书抄代码之类都可以。

  • 4
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值