2016-11-22 60 views
0

我有一个UVM项目。我在我的test_base下面的代码:函数的一般类型输入

class test_base extends uvm_test; 
    //factory registration 
    `uvm_component_utils(test_base) 

    //internal decleration 
    girobo2_env grb_env_i; 

    //configuration objects: 
    grb2_env_config m_env_cfg; 
    axi_agent_config m_axi_agent_cfg; 

    ......... 

    //build_phase 
    //Create axi_agent agent configuration object 
    m_axi_agent_cfg = axi_agent_config::type_id::create("m_axi_agent_cfg"); 
    if(!uvm_config_db #(virtual axi_interface)::get(this, "", "axi_vif", m_axi_agent_cfg.axi_vif) 
     `uvm_error("RESOURCE_ERROR", "axi_interface virtual interface not found") 
    m_env_cfg.m_axi_agent_cfg = m_axi_agent_cfg; 
    // Call function to configure the axi agent 
    configure_axi_agent(m_axi_agent_cfg); 

    //-------------------------------------------------------------------- 
    // configure_my_agent 
    //-------------------------------------------------------------------- 
    // Convenience function to configure the agent 
    // This can be overloaded by extensions to this base class 
    virtual function void configure_axi_agent (axi_agent_config cfg); 
     cfg.is_active = UVM_PASSIVE;  
    endfunction: configure_my_agent 
endclass: test_base 

有定义configure_my_agent功能一般的(如模板C++为例)输入的类型的选项。

回答

1

您可以将输入类型configure_my_agent设置为通用uvm_object。然后,您可以通过任何uvm_object并适当地转换它。

virtual function void configure_my_agent (uvm_object base_cfg); 

    if (base_cfg.get_type_name == "grb2_env_config") begin 
    axi_agent_config cfg; 
    $cast(cfg, base_cfg); 
    cfg.is_active = UVM_PASSIVE; 
    end 
    else if (base_cfg.get_type_name == "grb2_env_config") begin 
    grb2_env_config cfg; 
    $cast(cfg, base_cfg); 
    cfg.is_active = UVM_PASSIVE; 
    end 
    else if ...... // All other config type names 

endfunction: configure_my_agent 

注: 就个人而言,我不喜欢这种方法。 is_active的类型为UVM_ACTIVE_PASSIVE_ENUM,应该在构建阶段从每个代理的基本测试中直接设置。然后,在代理的build_phase中,查找此变量并确定您的代理是主动还是被动。请注意,为此,您应该在代理的uvm_component_utils中注册is_active变量(UVM组件在其build_phase期间自动查找已注册的类变量)。

+0

@ noobuntu-我写的中试基地这个功能.... – sara8d

+0

你怎么如果“CGF”使用,如果还没有确定? – sara8d

+0

我改变了if中的cfg到base_cfg。我收到以下错误:#** Error(suppressible):.. \ sv \ test_base.sv(109):(vlog-7027)在当前范围中找不到名称('cfg') 。请验证名称'cf g'的拼写。 – sara8d

0

UVM工厂提供了一种机制,用于指定也可用于检查类型的类型替代。

静态方法axi_agent_config::type_id::get_type()返回一个代理单例对象的句柄,该代理单例对象代表axi_agent_config的类型。您可以调用虚拟uvm_object方法get_object_type(),该方法返回代理单例对象的句柄,该代理单例对象表示传递给cfg的对象的实际对象的类型。所以,你可以写

if (axi_agent_config::type_id::get_type() == cfg.get_object_type()) 
    // then you have a matching base class object 
else if (axi_extended_agent_cdg::type_id::get_type() == cfg.get_object_type()) 
    // then you have a matching extended object 
+0

@ dave_59-但是,通用函数的参数(从哪个类型)应该是什么? – sara8d

+0

使用通用基类型 –

+0

#** at .. \ sv \ test_base.sv(157):无法在指定范围内找到名称'get_type'。相关行是:if(axi_agent_config :: type_id :: get_type()== cfg.get_object_type()) – sara8d