uvm中的agent

在实际的验证环境中, uvm_agent应该算是比较大的uvm_componet, 里面可以包含squencer、driver、monitor等单元。如下图所示:

同样uvm agent也可以进行一些参数的配置

agent可以分成两种:

  1. active
  • 包含所有的component, 比如sequencer、driver、monitor;
  • 数据可以通过driver来驱动DUT
  1. passive
  • 只包含monitor和coverage group等;
  • 用于checker和coverage

uvm agent的创建

  1. 和定义其他模块一样, 先从[uvm_agent] 派生出一个自定义的class,用factory机制注册, 并且创建new函数:
1
2
3
4
5
6
7
8
9
10
// my_agent is user-given name for this class that has been derived from "uvm_agent"
class my_agent extends uvm_agent;
// [Recommended] Makes this agent more re-usable
`uvm_component_utils (my_agent)
// This is standard code for all components
function new (string name = "my_agent", uvm_component parent = null);
super.new (name, parent);
endfunction
// Code for rest of the steps come here
endclass
  1. 实例化agent里面的componet
1
2
3
4
5
6
7
8
9
10
11
12
13
// my_agent is user-given name for this class that has been derived from "uvm_agent"
class my_agent extends uvm_agent;

// [Recommended] Makes this agent more re-usable
`uvm_component_utils (my_agent)

// This is standard code for all components
function new (string name = "my_agent", uvm_component parent = null);
super.new (name, parent);
endfunction

// Code for rest of the steps come here
endclass
  1. 在build_phase中创建上述的componet。 注意这里的函数用于查询uvm_agent是active模式还是passive模式:
1
2
3
4
5
6
7
8
9
10
11
12
13
 virtual function void build_phase (uvm_phase phase);

// If this UVM agent is active, then build driver, and sequencer
if (get_is_active()) begin
m_seqr0 = uvm_sequencer#(my_data)::type_id::create ("m_seqr0", this);
m_drv0 = my_driver::type_id::create ("m_drv0", this);
end

// Both active and passive agents need a monitor
m_mon0 = my_monitor::type_id::create ("m_mon0", this);

//[Optional] Get any agent configuration objects from uvm_config_db
endfunction
  1. 把agent中的componet连接起来: 比如说sequencer和driver:
1
2
3
4
5
6
 virtual function void connect_phase (uvm_phase phase);

// Connect the driver to the sequencer if this agent is Active
if (get_is_active())
m_drv0.seq_item_port.connect (m_seqr0.seq_item_export);
endfunction

uvm agent 的配置

uvm agent有个内部参数是is_active, 可以通过config_db进行配置:

1
2
3
4
5
// Set the configuration called "is_active" to the agent's path to mark the given agent as passive
uvm_config_db #(int) :: set (this, "path_to_agent", "is_active", UVM_PASSIVE);

// Set the configuration called "is_active" to the agent's path to mark the given agent as active
uvm_config_db #(int) :: set (this, "path_to_agent", "is_active", UVM_ACTIVE);