| |
Nesting Sub-Component Configuration Objects
配置对象通过test的UVM组件配置空间传递给子组件。它们可以使用uvm_config_db :: set method中的path参数单独传递,以控制哪些组件可以访问对象。但是,常见的要求是中间组件也需要进行一些本地配置。
因此,通过测试平台层次结构来处理配置对象传递的有效方法是嵌套彼此内部的配置对象以反映层次结构本身的方式。在测试平台的每个中间层次,解压缩该级别的配置对象,然后重新配置其子配置对象(如果需要),然后使用uvm_config_db :: set传递给相关组件。
在下面的SPI块级环境示例中,每个agent都将具有单独的配置对象。envs配置对象将为每个agent配置对象提供一个句柄。在test中,将从测试用例的角度构造和配置所有配置对象,然后将env配置对象内的agent配置对象句柄分配给实际的agent配置对象。然后将env配置对象设置到配置空间中,以便在构建env时能检测到。
【此处需插一副图】
对于更复杂的环境,将需要额外的嵌套层次。
//
// Configuration object for the spi_env:
//
//
// Class Description:
//
//
class spi_env_config extends uvm_object;
// UVM Factory Registration Macro
//
`uvm_object_utils(spi_env_config)
//------------------------------------------
// Data Members
//------------------------------------------
// Whether env analysis components are used:
bit has_functional_coverage = 1;
bit has_reg_scoreboard = 0;
bit has_spi_scoreboard = 1;
// Configurations for the sub_components
apb_config m_apb_agent_cfg;
spi_agent_config m_spi_agent_cfg;
//------------------------------------------
// Methods
//------------------------------------------
// Standard UVM Methods:
extern function new(string name = "spi_env_config");
endclass: spi_env_config
function spi_env_config::new(string name = "spi_env_config");
super.new(name);
endfunction
//
// Inside the spi_test_base class, the agent config handles are assigned:
//
// The build method from before, adding the apb agent virtual interface assignment
// Build the env, create the env configuration
// including any sub configurations and assigning virtural interfaces
function void spi_test_base::build_phase( uvm_phase phase );
// Create env configuration object
m_env_cfg = spi_env_config::type_id::create("m_env_cfg");
// Call function to configure the env
configure_env(m_env_cfg);
// Create apb agent configuration object
m_apb_cfg = apb_agent_config::type_id::create("m_apb_cfg");
// Call function to configure the apb_agent
configure_apb_agent(m_apb_cfg);
// Adding the apb virtual interface:
if( !uvm_config_db #( virtual apb3_if )::get(this, "" , "APB_vif",m_apb_cfg.APB) ) `uvm_error(...)
// Assign the apb_angent config handle inside the env_config:
m_env_cfg.m_apb_agent_cfg = m_apb_cfg;
// Repeated for the spi configuration object
m_spi_cfg = spi_agent_config::type_id::create("m_spi_cfg");
configure_spi_agent(m_spi_cfg);
if( !uvm_config_db #( virtual apb3_if )::get(this, "" , "SPIvif",m_spi_cfg.SPI) ) `uvm_error(...)
m_env_cfg.m_spi_agent_cfg = m_spi_cfg;
// Now env config is complete set it into config space:
uvm_config_db #( spi_env_config )::set( this , "*m_spi_agent*", "spi_env_config", m_env_cfg) );
// Now we are ready to build the spi_env:
m_env = spi_env::type_id::create("m_env", this);
endfunction: build_phase