Setting the interface handle into config tb from top tb module

Hi,

I need some help regarding the setting of interface to config db in top tb module and which in turn set into agent from env.

basically my implementation is shown as below


module top_tb;
// ports
 
// i have a genvar for loop 
genvar i;
for (i=0; i<5; i++) begin : gen
  //interface instance
  xyz_if m_if;
 
  //module instance to which the interface is passed 
  module1 m1(m_if);
 
  // i am trying to set the same if into config db here 
  initial begin
   if(i==1)
   uvm_config_db#(virtual xyz_if)::set(uvm_root::get(), "uvm_test_top.env*", "vif", m_if);
  end  
 
end //for loop
endmodule
end

will this work, please help.
other process i tried is below, after for loop i added this way


initial begin
for (int i =0; i<3; i++) begin
   uvm_config_db#(virtual xyz_if)::set(uvm_root::get(), "uvm_test_top.env*", "vif", gen[i].m_if);
end
end

i am getting error at gen[i] place.
help me to use the correct way

Thanks

In reply to jaswanth_b:

You don’t mention what kind of error you are getting (compilation, run time, wrong value, etc), so these are some general recommendations:

  • Only target uvm_test_top with your interface handle
  • Use ‘null’ for context when at the top testbench level
  • Don’t use ‘*’ for a target as this can result in conflicts
  • Every string name used should be unique so that the test can assign the correct interface handle to the correct agent
  • In your test, get each handle and assign it to each agent’s (or environment) configuration object

module top_tb;
// ports

// i have a genvar for loop 
genvar i;
for (i=0; i<5; i++) begin : gen
  //interface instance
  xyz_if m_if;

  //module instance to which the interface is passed 
  module1 m1(m_if);
 
  // i am trying to set the same if into config db here 
  initial begin
    uvm_config_db#(virtual xyz_if)::set(null, "uvm_test_top", $sformatf("vif%0d",i), m_if);
  end
end //for loop
endmodule

In reply to cgales:

Hi,

Thanks for the reply
actually issue is i am getting the wrong value in my usage.

In reply to jaswanth_b:

Can you please explain more about this:

  • “In your test, get each handle and assign it to each agent’s (or environment) configuration object”

In reply to jaswanth_b:

It is recommended to have a configuration object for each agent. This configuration object contains all the information used by the agent to control its behavior. Part of this configuration object should be the virtual interface handle to be used by the agent.

The environment configuration object will contain all the agent configuration objects. It is created as part of the test and passed to the environment, which will then pass the agent configuration objects to the correct agent.