《UVM白皮书》关于monitor的介绍
验证平台需要监测DUT的行为,实现这一功能的组件是monitor。
driver负责给DUT提供驱动,而monitor是收集DUT的数据,并交给后续组件。
一、一个monitor示例
class my_monitor extends uvm_monitor;//派生自uvm_monitor
virtual interface my_if vif;//声明接口interface
`uvm_component_utils(my_monitor)//factory机制
function new (string name="my_monitor",uvm_component parent=null);
super.new(name,parent);
endfunction
virtual function void build_phase(uvm_phase phase);
super.build_phase(phase);
if(!uvm_config_db#(virtual my_if)::get(this,"","vif",vif))
`uvm_fatal("my_monitor","virtual interface must be set for vif!!!")
endfunction
extern task main_phase(uvm_phase phase);
extern task collect_one_pkt(my_transaction tr);
endclass
————————————————————————————————————————————————————————————————————————
在monitor中 也需要使用接口连接它和DUT。在monitor中使用config_db get,那么在top_tb中需要加入config_db::get。下边会讲到
二、在env中实例化monitor
class my_env extends uvm_env;
my_driver drv;
my_monitor i_mon;//新增
my_monitor o_mon;//新增
`uvm_component_utils(my_env)
function new(string name="my_env",uvm_component parent);
super.new(name,parent);
endfunction
virtual function void build_phase(uvm_phase phase);
super.build_phase(phase);
drv=my_driver::type_id::create("drv",this);
i_mon=my_monitor::type_id::create("i_mon",this);//新增
o_mon=my_monitor::type_id::create("o_mon",this);//新增
endfunction
在这里实例化了两个monitor。任意的按需要。
此时UVM树形结构如下:
那么此时monitor的路径索引就是 uvm_test_top.i_mon和 uvm_test_top.o_mon。
三、在top_tb中使用进行接口interface连接
前边提到要在top_tb中使用config_db::set对应monitor中的config_db::get实现连接,如下:
initial begin
uvm_config_db#(virtual my_if)::set(null,"uvm_test_top.my_drv","vif",input_if);
uvm_config_db#(virtual my_if)::set(null,"uvm_test_top_i_mon","vif",input_if);//新增
uvm_config_db#(virtual my_if)::set(null,"uvm_test_top.o_mon","vif",input_if);//新增
end
这里有一个问题,一旦修改验证平台的层次结构,set函数的第二个参数(路径索引)就会变化,有没有什么方法能解决呢?
当然有。
在config_db机制中 uvm_condig_db#(virtual my_if)是一个参数化的类,其参数(括号里的)就是要寄信的类型。
那么我们只要保证要寄的信件是一样的, 也就是不管买家住在验证平台的哪个地方,只要买家和卖家暗号对得上,那么就可以安心把买卖双方的接口连接起来了。
路径索引就可以写作 "*"。如下。上边的3行变1行。
initial begin
uvm_config_db#(virtual my_if)::set(null,"*","vif",input_if);
end
不管你是A2栋3单元303室driver,还是T1大厦1406的monitor,你俩都网购了top_tb的virtual my_if,那这接口interface就能送到你家。