Issue with putting an array of interface into uvm_config_db

Help!

Is it possible to do something like this:

genvar i;
generate for(i=0; i< num_dut_instances; i++) begin : dut_inst
Dut_if dut_if[i];
end
endgenarate : dut_inst





initial begin
for(int i = 0; i < num_dut_instances; i++) begin
uvm_config_db#(virtual Dut_if)::set(uvm_root::get(),“*”,$sformatf(“dut_if_%0d”,i),dut_if[i]); //error on this line
end
end

the above code is not working and is giving error “dut_if” undeclared identifier.

But, if I write the above code in the following manner it works well:

Dut_if dut_if_1;
Dut_if dut_if_2;





initial begin
uvm_config_db#(virtual Dut_if)::set(uvm_root::get(),““,“dut_if_1”,dut_if_1);
uvm_config_db#(virtual Dut_if)::set(uvm_root::get(),”
”,“dut_if_2”,dut_if_2);
end

can you please tell how to correctly use array of interfaces in UVM

If you instantiate your interfaces with a generate statement:

module top;
  genvar i;
  for(i=0; i< num_dut_instances; i++) begin : dut_inst
    Dut_if dut_if();
  end
endmodule

Then the instance names of your Dut_if are
top.dut_inst[0].dut_if, top.dut_inst[1].dut_if, …,
If you instantiate your interfaces with an instance range:

module top;
  Dut_if dut_if[0:num_dut_instances-1]();
endmodule

Then the instance names of your Dut_if are
top.dut_if[0], top.dut_if[1], …,

Note that in both cases, you cannot use a dynamic variable to select an index into an instance. An instance name is not a regular array variable. Because of the way parameter overrides work, each generated instance has the potential to be a unique instance. A regular array requires that each element be exactly the same type.
So the index must be a constant so the compiler can check the hierarchical reference for validity. You can write:

module top;
  genvar i;
  for(i=0; i< num_dut_instances; i++) begin : dut_inst
    Dut_if dut_if();
    initial uvm_config_db#(virtual Dut_if)::set(uvm_root::get(),"*",$sformatf("dut_if_%0d",i),dut_if);
  end
endmodule

In reply to dave_59:

Thanks Dave,

Works like a charm! :)

Regards,
Nitin Ahuja

Hi dave_59 ,

if interface is parameterized one then how multiple intefaces can put in uvm_config_db.

Thanks
kbkdec15

In reply to kbkdec15:

If you have an array of parametrized interfaces instances, you apply the same parameters to your interface.

for(i=0; i< num_dut_instances; i++) begin : dut_inst
    Dut_if dut_if();
    initial uvm_config_db#(virtual Dut_if#(myparams)::set(uvm_root::get(),"*",$sformatf("dut_if_%0d",i),dut_if);
  end

If each interface instance needs a unique set of parameters, you can put the parameters into an array.


parameter int myparams[num_dut_instances] = {1,2,3,4,5,6,7,8);
for(i=0; i< num_dut_instances; i++) begin : dut_inst
    Dut_if #(myparams[i] dut_if();
    initial uvm_config_db#(virtual Dut_if#(myparams[i])::set(uvm_root::get(),"*",$sformatf("dut_if_%0d",i),dut_if[i]);
  end

If you cannot get your parameters into an array, then you will not be able to use a generate statement and will have to explicitly instantiate and config each instance.

In reply to dave_59:

how to use the uvm_config_db::get for the above array of interfaces? Thanks in advance