1、定义
driver
和
monitor之间的联系两者之间的代码高度相似。其本质是因为二者处理的是同一种协议,在同样一套既定的规则下做着不同的事情。由于二者的这种相似性,
UVM中通常将二者封装在一起,成为一个
agent;
2、举例
class my_agent extends uvm_agent ;
my_driver drv;
my_monitor mon;
function new(string name, uvm_component parent);
super.new(name, parent);
endfunction
extern virtual function void build_phase(uvm_phase phase);
extern virtual function void connect_phase(uvm_phase phase);
`uvm_component_utils(my_agent)
endclass
function void my_agent::build_phase(uvm_phase phase);
super.build_phase(phase);
if (
is_active == UVM_ACTIVE
) begin
drv = my_driver::type_id::create("drv", this);
end
mon = my_monitor::type_id::create("mon", this);
endfunction
function void my_agent::connect_phase(uvm_phase phase);
super.connect_phase(phase);
endfunction
3、说明
所有的
agent
都要派生自
uvm_agent
类,且其本身是一个
component
,应该使用
uvm_component_utils
宏来实现
factory
注册。
is_active是uvm_agent的一个成员变量,而uvm_active_passive_enum是一个枚举类型变量,其定义为:typedef enum bit { UVM_PASSIVE=0, UVM_ACTIVE=1 } uvm_active_passive_enum;