I have to create a bunch of agents which are of same type. Can I create them as an array rather than copy pasting code again and again?
In reply to SharonBeaulah:
Of course you can do this.But it is not needed.
But you do not need to paste the code again and again because the agent class definition ius needed only once. You can reuse the agent code from another project by passing only a link to the source code.
In reply to chr_sue:
Sorry if my question wasnât clear. I want to instantiate same agent multiple times based on a configuration variable in one environment. Can I have it as an array?
In reply to SharonBeaulah:
You sure can, and people do this all the time to represent multiple masters and slaves on a bus.
In reply to SharonBeaulah:
Do you mean something like this?
master_agent my_master_agent[num_agent];
foreach(my_master_agent)
begin
my_master_agent[i] = master_agent::tpye_id::create(my_master_agent, this);
end
You can take num_agent from environment. You can use config_db or directly assign like âagent_inst.num_agent = 12â
In reply to hcglu:
[CLDEXT] Cannot set âwali[i_wali]â as a child of âuvm_test_top.environmentâ, which already has a child by that name.
Getting above error.
I donât want to use manual method as I have number of such agents and I want to access them using index which is a configuration variable.
Also I want to have multiple monitor bfms and driver bfms, but Iâm not able to get them in a for loop.
In reply to SharonBeaulah:
Could you please show some code related to the error you get.
In reply to chr_sue:
Sure. My code file is very huge, just pasting the related linesâŚ
typedef wali_agent #(
.DATA_WIDTH(WALI_DATA_WIDTH),
.ADDR_WIDTH(WALI_ADDR_WIDTH)
)
wali_agent_t;
wali_agent_t wali [N-1:0]; // N is a parameter
// In build_phase
foreach (wali[i_wali]) begin
wali[i_wali] = wali_agent_t::type_id::create(âwaliâ,this);
wali[i_wali].set_config(configuration.wali_config[i_wali]);
end
In reply to SharonBeaulah:
The first argument to create() is the instance name. Every child component needs a unique instance name. (Imagine your parents named you and your brother âChrisâ!)
Here is how I would write the create loop. Your instance name string does not HAVE to match the handle name, but it makes debug easier. Put the index value in the string with $sformatf().
master_agent agt[num_agent];
foreach (my_master_agent)
agt[i] = master_agent::type_id::create($sformatf("agt[%0d]", i), this);
Now you have instance names âagt[0]â, âagt[1]â, etc. I like to put square brackets around the index to prevent an issue with wildcards. In the uvm_config_db, if you specify âenv.agt1*â, that will match âenv.agt1â, âenv.agt10â, âenv.agt11â, etc.
In reply to chrisspear:
Little heads-up, Iâm kind of new to this and sorry if itâs so basic.
I tried this one and this is what Iâm getting. Iâm using UVMF so most of the code is auto-generated.
UVM_FATAL @ 0.000ns: uvm_test_top.environment.wali[0].wali[0]_driver [DRV] BFM handle with interface_name is null
I tried adding them to BFM as well, but itâs looking for that particular instance name and it is not accepting it as the name of BFM because of the index.
In reply to SharonBeaulah:
Aha - UVM Framework, that helps! I always use âgrep -râ (or the Emacs equivalent) to explore UVMF as there are many files.
That error message is from the driverâs connect_phase() checking if configuration.driver_bfm is null. The full error message is:
`uvm_fatal("DRV", $sformatf("BFM handle with interface_name %s is null",configuration.interface_name) );
It looks like the configuration.interface_name string is null. This is set in the agent configurationâs initialize() method. That string was passed in from the environmentâs initialize() method. You can either grep for the call or set a breakpoint on the agent initialize() method and walk through the code. Also, set the VERBOSITY to UVM_DEBUG and look in the log file for a message starting with âInterfaces for the following uvm environment hierarchyâ, which should be followed by a list of names.
I am curious if there has been any more development on this topic. I have gone through a similar methodology using UVM Framework. I have gotten past the interface_names issue which is due to what is generated at hdl_top. However, I am running into an error and I feel it is due to creating an array of a typedef for the agents configuration object.
This code is written in the environment configuration file generated from UVMF which then initializes the agents interface_names
typedef axi_configuration axi_agent_config_t;
rand axi_agent_config_t axi_agent_config[];
...
for(int i = 0; i< (NUM_AGENTS); i++) begin
$display("interface_names[%0d] = %s", i, interface_names[i]);
$display("interface_activity[0] = %s", interface_activity[0]);
axi_agent_config[i].initialize( interface_activity[0], {environment_path,$sformatf(".axi_agent[%0d]", i)}, interface_names[i]);
axi_agent_config[i].initiator_responder = INITIATOR;
end
the error I get from Questa is as follows
** Fatal: (vsim-131) ... (above for loop): Null instance encountered when dereferencing 'this.axi_agent_config[0x15454db79e60]'
Thank you!