fbochud Posted February 22, 2012 Report Share Posted February 22, 2012 Hi, I'm trying to implement my VIP by using configuration classes for the agent and the environment. What is the recommended way of doing this, if I want to override both the agent and its configuration with an extended child definition? Below is an example of how I think i should be written, but unfortunately, the configuration is not set for the extended agent: (Sorry for the bad increment) package pkg; import uvm_pkg::*; `include "uvm_macros.svh" /*************************************************** /* configuration that will be used in my base agent /***************************************************/ class BaseConfig extends uvm_object; `uvm_object_utils(BaseConfig) rand int baseconfig_item; function new (string name = ""); super.new(name); baseconfig_item = 0; endfunction // Standard utility method for a config object or transaction function string convert2string; return $sformatf("baseconfig_item = %0d\n", baseconfig_item); endfunction endclass: BaseConfig /*************************************************** /* configuration that will be used in my extended agent /***************************************************/ class ExtendedConfig extends BaseConfig; `uvm_object_utils(ExtendedConfig) rand int extconfig_item; function new (string name = ""); super.new(name); extconfig_item = 1; endfunction // Standard utility method for a config object or transaction function string convert2string; return $sformatf("extconfig_item = %0d, baseconfig_item = %0d\n", extconfig_item, baseconfig_item); endfunction endclass: ExtendedConfig /*************************************************** /* configuration that will be used in my environment, /* instantiates basically one agent_config per agent, /****************************************************/ class EnvConfig extends uvm_object; `uvm_object_utils(EnvConfig) rand int env_item; BaseConfig cfg; function new (string name = ""); super.new(name); cfg = new(); cfg = BaseConfig::type_id::create("cfg"); env_item = 2; endfunction // Standard utility method for a config object or transaction function string convert2string; return $sformatf("env_item = %0d, cfg: %s\n", env_item, cfg.convert2string); endfunction endclass: EnvConfig /*************************************************** /* Agent and enviromnent definitions /****************************************************/ class BaseAgent extends uvm_agent; `uvm_component_utils(BaseAgent) // new - constructor function new (string name, uvm_component parent); super.new(name, parent); endfunction : new function void build_phase(uvm_phase phase); super.build_phase(phase); endfunction: build_phase task run_phase(uvm_phase phase); phase.raise_objection(this); `uvm_info("Component A", "hello out there!", UVM_MEDIUM) phase.drop_objection(this); endtask endclass: BaseAgent class ExtendedAgent extends BaseAgent; `uvm_component_utils(ExtendedAgent) ExtendedConfig my_ext_cfg; // new - constructor function new (string name, uvm_component parent); super.new(name, parent); endfunction : new function void build_phase(uvm_phase phase); super.build_phase(phase); // Get config if (!uvm_config_db #(ExtendedConfig)::get(this, "", "cfg", my_ext_cfg) ) `uvm_fatal("NOCFG",{"config must be set for: ",get_full_name(),".my_ext_cfg"}); endfunction: build_phase task run_phase(uvm_phase phase); phase.raise_objection(this); `uvm_info("Component B", "hello out there!", UVM_MEDIUM) `uvm_info("Component B", my_ext_cfg.convert2string, UVM_MEDIUM) phase.drop_objection(this); endtask endclass: ExtendedAgent class BaseEnv extends uvm_env; `uvm_component_utils(BaseEnv) EnvConfig env_cfg; BaseAgent my_base_agent; // new - constructor function new(string name, uvm_component parent); super.new(name, parent); endfunction : new // build function void build_phase(uvm_phase phase); super.build_phase(phase); if(!uvm_config_db#(EnvConfig)::get(this, "", "env_config", env_cfg)) `uvm_fatal("NOCFG",{"config must be set for: ",get_full_name(),".env_cfg"}); // update some baseAgent params env_cfg.cfg.baseconfig_item = 5; // forward config to lower component uvm_config_db #(BaseConfig)::set(this, "cfg", "config", env_cfg.cfg); my_base_agent = new("agent", null); my_base_agent = BaseAgent::type_id::create("agent", this); endfunction : build_phase endclass: BaseEnv endpackage /*************************************************** /* Top module with overrides /****************************************************/ module test; import uvm_pkg::*; import pkg::*; BaseEnv my_base_env; EnvConfig env_cfg; initial begin // Override my base class with extended functionality factory.set_type_override_by_type(BaseAgent::get_type(), ExtendedAgent::get_type()); factory.set_type_override_by_type(BaseConfig::get_type(), ExtendedConfig::get_type()); env_cfg = new(); uvm_config_db #(EnvConfig)::set(my_base_env, "*", "env_config", env_cfg); my_base_env = new("env", null); run_test(); end endmodule // test Quote Link to comment Share on other sites More sharing options...
janick Posted February 22, 2012 Report Share Posted February 22, 2012 The uvm_config_db() does not know about inheritance and puts the configuration in the BaseConfig table, even though it is an instance of ExtendedConfig. You need to get it using uvm_config_db#(BaseConfig)::get() and $cast() it to ExtendedConfig. Quote Link to comment Share on other sites More sharing options...
fbochud Posted February 22, 2012 Author Report Share Posted February 22, 2012 Thank you for the quick answer. I'm not sure I understood correctly, but here are my changes 1. In the class BaseAgent, I instantiate a base_cfg and run a uvm_config_db #(BaseConfig)::get(this, "", "config", my_cfg) 2. in the class ExtendedAgent, I declare an ExtendedConfig and assign it using $cast(my_ext_cfg, my_cfg); It seems to work . Any comments? See Code Below: /*************************************************** / Agent and environment definitions ****************************************************/ class BaseAgent extends uvm_agent; `uvm_component_utils(BaseAgent) BaseConfig my_cfg; // new - constructor function new (string name, uvm_component parent); super.new(name, parent); endfunction : new function void build_phase(uvm_phase phase); super.build_phase(phase); // Get config if (!uvm_config_db #(BaseConfig)::get(this, "", "config", my_cfg) ) `uvm_fatal("NOCFG",{"config must be set for: ",get_full_name(),".my_cfg"}); endfunction: build_phase task run_phase(uvm_phase phase); phase.raise_objection(this); `uvm_info("Component A", "hello out there!", UVM_MEDIUM) // `uvm_info("Component A", my_cfg.convert2string, UVM_MEDIUM) phase.drop_objection(this); endtask endclass: BaseAgent class ExtendedAgent extends BaseAgent; `uvm_component_utils(ExtendedAgent) ExtendedConfig my_ext_cfg; // new - constructor function new (string name, uvm_component parent); super.new(name, parent); endfunction : new function void build_phase(uvm_phase phase); super.build_phase(phase); $cast(my_ext_cfg, my_cfg); endfunction: build_phase task run_phase(uvm_phase phase); phase.raise_objection(this); `uvm_info("Component B", "hello out there!", UVM_MEDIUM) `uvm_info("Component B", my_ext_cfg.convert2string, UVM_MEDIUM) phase.drop_objection(this); endtask endclass: ExtendedAgent A last issue is when I try to assign the extconfig_item from the top module (see code below). Not really sure, how I should do this... module test; import uvm_pkg::*; import pkg::*; BaseEnv my_base_env; EnvConfig env_cfg; initial begin // Override my base class with extended functionality factory.set_type_override_by_type(BaseAgent::get_type(), ExtendedAgent::get_type()); factory.set_type_override_by_type(BaseConfig::get_type(), ExtendedConfig::get_type()); env_cfg = new(); env_cfg.env_item = 0; // Ok env_cfg.cfg.baseconfig_item = 10; // Ok env_cfg.cfg.extconfig_item = 11; // Error, Could not find member 'extconfig_item' in class 'BaseConfig' uvm_config_db #(EnvConfig)::set(my_base_env, "*", "env_config", env_cfg); my_base_env = new("env", null); run_test(); end endmodule // test Quote Link to comment Share on other sites More sharing options...
fbochud Posted February 23, 2012 Author Report Share Posted February 23, 2012 Correction, the last code compiles, but it does not work as desired. Setting the env_cfg params in "module test" doesn't update the actual parameters in the agents. At the test start baseconfig_item = 5 instead of the expected 10. Any suggestions? Quote Link to comment Share on other sites More sharing options...
fbochud Posted February 23, 2012 Author Report Share Posted February 23, 2012 Re-Correction: baseconfig_item = 5 is correct since it is set in the env BaseEnv constructor. Sorry for last post. Remains the last issue with assign extconfig_item from the top module. Quote Link to comment Share on other sites More sharing options...
fbochud Posted March 7, 2012 Author Report Share Posted March 7, 2012 By creating the env_cfg and the extended agent_cfg in the top, one will be able to assign the extconfig items: [...] // Configurations EnvConfig env_cfg; ExtendedConfig agent_cfg; initial begin // Override my base class with extended functionality factory.set_type_override_by_type(BaseAgent::get_t ype(), ExtendedAgent::get_type()); agent_cfg = ext_audio_config::type_id::create("agent_cfg"); agent_cfg.baseconfig_item = 20; agent_cfg.extconfig_item = 10; env_cfg = EnvConfig::type_id::create("env_cfg"); env_cfg.env_item = 15; env_cfg.cfg = agent_cfg; uvm_config_db #(EnvConfig)::set(this, "*", "env_config", env_cfg); [...] Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.