2016-11-22 53 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