UVM环境组件
1、uvm_driver
1)、uvm_driver的作用
uvm_driver负责从uvm_sequencer中获取transaction,经过数据处理,通过接口对DUT进行激励。
2)、uvm_driver类的定义
class uvm_driver #(type REQ=uvm_sequence_item, type RSP=REQ) extends uvm_component;
该类是参数化类,REG表示该类传递的transaction类型,RSP类型与REQ类型保持一致,定义新的driver时,应该声明transaction类型。
如:class my_driver extends uvm_driver #(basic_transaction);
my_driver类型在定义时,声明其传递的transaction类型basic_sequence。
若没有在传递时声明transaction类型,则默认为uvm_sequence_item类型,是父类类型,在使用transaction句柄时,应把它先转化为子类句柄再使用。
3)、uvm_driver的通信端口和变量
uvm_driver在uvm_component类型的基础上扩展了一些通信端口和变量,用来实现和其他组件之间的通信:
①、 uvm_seq_item_pull_port #(REQ,RSP) seq_item_port;
该端口负责与sequencer之间通信,获取新的transaction,与sequencer中声明的seq_item_export做connect。
②、uvm_analysis_port #(RSP) rsp_port;
该端口实现将响应信号送到sequencer,表明已经拿到transaction,与sequencer中声明的rsp_export做connect。
③、REQ req
;
表示driver从sequencer获取的transaction。
④、RSP rsp
;
表示driver获取transaction后返回给sequencer的响应,类型与REQ相同。
2、uvm_monitor
1)、uvm_monitor的作用
①、uvm_monitor类负责监视接口数据。
②、把数据发送到其他组件,如scoreboard、reference model或者coverage collector。
③、观察总线协议或者内部协议时,可通过插入并发断言,做一些功能和时序检查。
2)、uvm_monitor的定义
uvm_monitor继承于uvm_component类型,相对于uvm_component没有新增的成员变量和方法。我们可以在继承于uvm_monitor类的monitor新类型中,实现环境需要的方法和变量。
3、uvm_sequencer
1)、uvm_sequencer的作用
uvm_sequencer如同一个管道,产生连续的激励事务,通过tlm端口送到driver一侧。
2)、uvm_sequencer的定义
uvm_sequencer不直接继承于uvm_component类型,它继承于uvm_sequencer_param_base类型,uvm_sequencer_param_base继承于uvm_sequencer_base类型,uvm_sequencer_base继承于uvm_component类型。
虽然uvm_sequencer与uvm_component之间隔着两个中间类型,但是它的注册和new()方法与其他uvm_component在定义时一样。
class my_sequencer extends uvm_sequencer#(basic_transaction);
`uvm_component_utils(my_sequencer)
function new(string name = “my_sequencer”,uvm_component parent);
super.new(name,parent);
endfunction
...
endclass
uvm_sequencer也是一个参数类型,其参数与uvm_driver类型一样。
4、uvm_agent
1)、uvm_agent的作用
uvm_agent是一个组织单位,它负责把driver、monitor和sequencer组织在一起,它存在最大的意义是为了验证环境的复用。
2)、uvm_agent的内容
uvm_agent通常情况下包括driver、monitor、sequencer这三个组件的实例,但是有时候我们并不需要全部这三个组件,可以通过is_active变量进行有条件的例化。
3)、uvm_agent的active模式和passive模式
is_active是uvm_agent的成员变量,它的取值有UVM_ACTIVE、UVM_PASSIVE。缺省值是UVM_ACTIVE,表示agent处于active模式,需要例化driver、monitor和sequencer;如果is_active=UVM_PASSIVE,表示agent处于passive模式,只可以例化monitor。
active模式对应着dut的接口暴露给agent且需要激励的场景,而passive模式对应着DUT的接口已经与其他设计连接而只需要监测的场景。
通过is_active变量,agent需要在build_phase()和connect_phase()等方法中通过选择语句来对driver和sequencer进行有条件的例化和连接。
class my_agent extends uvm_agent;
my_driver driver;
my_monitor monitor;
my_sequencer sequencer;
`uvm_component_utils(my_agent)
function new(string name = "my_agent",uvm_component parent);
super.new(name,this);
endfunction
uvm_active_passive_enum is_active=UVM_ACTIVE;
function void build_phase(uvm_phase phase);
super.build_phase(phase);
monitor = my_monitor::type_id::create("monitior",this);
if(is_active==UVM_ACTIVE) begin
sequencer = my_sequencer::type_id::create("sequencer",this);
driver = my_driver::type_is::create("driver",this);
end
endfunction
function void connect_phase(uvm_phase phase);
super.connect_phase(phase);
if(is_active==UVM_ACTIVE) begin
driver.seq_item_port.connect(sequencer.seq_item_export);
end
endfunction
endclass
5、uvm_scoreboard
1)、uvm_scoreboard的作用
uvm_scoreboard负责进行数据对比和报告。
2)、uvm_scoreboard的定义
uvm_scoreboard继承于uvm_component类,但是相对于uvm_component类没有添加任何成员,建议将自定义的scoreboard类继承于uvm_scoreboard类,便于子类可以自动继承可能被扩充到uvm_scoreboard中的成员。
3)、uvm_scoreboard的使用
在scoreboard中会声明TLM端口以供monitor传输数据。
对于简单的设计,可以采用uvm预定义的comparator;对于复杂的设计,可以在scoreboard中分别创建reference model和comparator。
class my_scoreboard extends uvm_scoreboard;
`uvm_component_utils(my_scoreboard)
function new(string name = "my_scoreboard",uvm_component parent);
super.new(name,this);
endfunction
/*uvm_in_order_comparator是uvm自带的用于比较的参数类,
它有两个端口before_export和after_export分别从DUT的输入
端和输出端monitor获取观测的数据事务*/
typedef uvm_in_order_comparator #(bus_xact) comp_t;
comp_t m_comp;
uvm_analysis_export #(bus_xact) in_export;
uvm_analysis_export #(bus_xact) out_export;
function void build_phase(uvm_phase phase);
super.build_phase(phase);
in_export = new("in_export",this);
out_export = new("out_export",this);
m_comp = comp_t::type_is::create("m_comp",this);
endfunction
function void connect_phase(uvm_phase phase);
super.connect_phase(phase);
in_export.connect(m_comp.before_export);
out_export.connect(m_comp.after_export);
endfunction
endclass
6、uvm_env
1)、uvm_env的作用
uvm_env是一个结构化的容器,它可以容纳其他组件同时,也可以作为子环境在更高的集成中被嵌入。
2)、uvm_env的实现
class my_env extends uvm_env;
my_agent agent;
my_scoreboard scoreboard;
`uvm_component_utils(my_env)
function new(string name = "my_env",uvm_component parent);
super.new(name,this);
endfunction
function void build_phase(uvm_phase phase);
super.build_phase(phase);
agent = my_agent::type_is::create("agent",this);
scoreboard = my_scoreboard::type_id::create("scoreboard",this);
endfunction
endclass
7、uvm_test
1)、uvm_test的作用
uvm_test类决定着环境的结构和连接关系,也决定着是用哪一个测试序列。uvm_test提供验证环境建立的入口,只有通过它才能调动phase机制运转。uvm_test的实例通常作为uvm环境组件的顶层。
2)、uvm_test的实现
class test extends uvm_test;
my_env env;
`uvm_component_utils(test)
function new(string name = "test",uvm_component parent);
super.new(name,this);
endfunction
function void build_phase(uvm_phase phase);
super.build_phase(phase);
env = my_env::type_id::create("env",this);
endfunction
endclass