Setting array of interface to config_db inside a class

Hi,

Consider a scenario where an array of a small interface is instantiated within a top interface which is set to config_db from top module. An ENV class gets this top interface handle and distributes the small interfaces to agents as required. I wanted to write a code in ENV build phase which would look like this :


//Get top interface handle to top_intf here
for (int i=0; i<10; i++) begin
uvm_config_db#(virtual req_ack_if)::set(this,$sformatf("agent[%0d]*",i),"req_ack_if",top_intf.sub_intf[i].req_ack_inf);
end

The above code won’t compile because compiler won’t be able to find sub_intf without a constant value inside to determine hierarchy. Can this code be modified so as to not manually unroll the loop?

In reply to rishikpillai90:

Could you please show how the interface is defined and how the interface is instantiated.

Sub-interface:


interface sub_if();

req_ack_if req_ack_intf();
logic abcd;
//etc etc
endinterface : sub_if


Top interface :


interface top_if();
parameter NUM_INTF = 10;

sub_if sub_intf[NUM_INTF-1:0]();

endinterface : top_if

I am able to use

top_intf.sub_intf[0].req_ack_intf

while calling config_db::set inside ENV, but not inside a for loop as shown in my previous post.

In reply to rishikpillai90:

Try using a generate loop instead.

Is generate possible inside a class? I couldn’t see any reference to such usage in LRM.

In reply to rishikpillai90:

No, but you should be setting the config_db() handles at the top-level of your testbench, not inside any class hierarchy. I missed that you were trying to do this in your environment, so move those assignments outside of the environment.