uvm environment

本篇主要介绍uvm_env

uvm environment实际上是验证环境的可重用的单元。 其中可以包含多个uvm_agent, 不同的interface,

coverage collector和checker等。

如下图所示是一个uvm_env的示例图:

下面说明创建uvm_env的过程:

  1. 从uvm_env派生出一个自定义的env, 比如说是my_env, 用factory 机制注册, 并且创建new函数:
1
2
3
4
5
6
7
8
9
class my_env extends uvm_env;
// [Recommended] Makes this driver more re-usable
`uvm_component_utils (my_env)
// This is standard code for all components
function new (string name = "my_env", uvm_component parent = null);
super.new (name, parent);
endfunction
// Code for rest of the steps come here
endclass
  1. 申明这个env中的一些component:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
// apb_agnt and other components are assumed to be user-defined classes that already exist in TB
apb_agnt m_apb_agnt;
func_cov m_func_cov;
scbd m_scbd;
env_cfg m_env_cfg;

// Build components within the "build_phase"
virtual function void build_phase (uvm_phase phase);
super.build_phase (phase);
m_apb_agnt = apb_agnt::type_id::create ("m_apb_agnt", this);
m_func_cov = func_cov::type_id::create ("m_func_cov", this);
m_scbd = scbd::type_id::create ("m_scbd", this);

// [Optional] Collect configuration objects from the test class if applicable
if (uvm_config_db #(env_cfg)::get(this, "", "env_cfg", m_env_cfg))
`uvm_fatal ("build_phase", "Did not get a configuration object for env")

// [Optional] Pass other configuration objects to sub-components via uvm_config_db
endfunction
  1. 在connec_phase连接各个uvm_component

如下图所示是一个定义env的例子:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
class my_env extends uvm_env ;

`uvm_component_utils (my_env)

my_agent m_agnt0;
my_scoreboard m_scbd0;

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

virtual function void build_phase (uvm_phase phase);
super.build_phase (phase);
m_agnt0 = my_agent::type_id::create ("my_agent", this);
m_scbd0 = my_scoreboard::type_id::create ("my_scoreboard", this);
endfunction : build_phase

virtual function void connect_phase (uvm_phase phase);
// Connect the scoreboard with the agent
m_agnt0.m_mon0.item_collected_port.connect (m_scbd0.data_export);
endfunction

endclass