Connecting Virtual Interfaces to interfaces

Hi,
Could someone help me with a problem i am facing…
I have a virtual interface say my_if;
I have an array of instantiated interfaces my_if_array[15:0];
I want to connect my_if to one of the my_if_array interfaces during simulation run depending on some parameter i.
The following method does not work
my_if = my_if_array[i] ; ERROR =>Illegal operand (i) fro constant expression
I have to resort to the following method
case(i)
0 : my_if = my_if_array[0];
1: my_if = my_if_array[1];

and so on…

is there a cleaner way to do this ?

Interfaces are design level constructs which imposes some limitations on how you can index them using variables.

However, virtual interfaces are verification constructs which aren’t limited to the same restrictions. You should be able to create an array of virtual interfaces, assign the array to the physical interfaces, and access the interface handle using an array index.

I too have a similar problem.

I have a multi master and multi slave bus interface where in number of masters and slaves might vary,

so for the same reason I have declared an array of interfaces in my top level test bench file, and when I try to pass the array of interfaces to individual interfaces in test bench tool gives an error…

for (int i=0; i<num_masters;i++)
my_intf[i] = top.dut_intf[i]

The above code is the piece that has a problem with interfaces…is there a better way to do this, I dont want to be hand instantiating all the interfaces everytime there is a change in configuration.

Thanks in advance.
Pradeep

The following code from http://ovmworld.org/forums/showthread.php?911-problem-use-interface-array-on-Cadence-tool&highlight=interface

solved the problem:

module top;
bus_if top_if [7:0];
virtual top_temp[7:0];
initial top_temp=top_if;
endmodule

class env extends ovm_env;
virtual bus_if temp_if [7:0];
………….// other codes
function automatic void connect();
///////////////////////////////////////
foreach(temp_if[i])
temp_if[j] = top.top_temp[j];
///////////////////////////////////////
endfunction
endclass

I didnot realize the virtual definition in top file and being used internally.

Pradeep