Reputation: 2864
SystemVerilog LRM section 25.3.3 describes generic interfaces
:
If a port declaration has a generic interface type, then it can be connected to an interface instance of any type.
I have an array of generic interfaces in my module:
module bing #(
parameter SOME_VALUE = 4
)(
input clk,
interface my_interfaces[SOME_VALUE-1:0]
);
When instantiating this module I would like to connect each interface in the array to an interface instance of a different type. Is this possible?
Alternatives / workarounds welcome - needs to be synthesisable.
Upvotes: 2
Views: 2641
Reputation: 42616
Your request does not make much sense. An array is, by definition, a collection of elements of identical types. No programming language that I am aware of would let the type of an element change based on the selected index.
The construct that comes closest to doing what you are looking for is a array of base class handles, with each element containing a handle to a different extension of the base class. However, if you wanted to access something that was unique to a particular extended class, you would either have to use a virtual method, or cast the element to variable of the correct type.
The problem here might not be with the language, but the fact that synthesis tools have not caught up with class based descriptions. It's a very hard problem. Even if the language let you pass around modules as objects, synthesis tools need to statically determine the type of each object.
Upvotes: 1
Reputation: 7573
I don't this is going to be possible to do as this would mean that in your testbench you'd have to have something like the following:
module top
some_interface if1(...);
some_other_interface if2(...);
bing #(SOME_VALUE = 2) (
.my_interfaces[0](if1),
.my_interfaces[1](if2)
);
endmodule
which is illegal syntax. When connecting ports, you can only use the port identifier (in your case my_interfaces
) and you're not allowed to slice it (the BNF defined in 23.3.2 Module instantiation syntax doesn't allow it).
If you want to pass in an array of interfaces of the same type, then you won't have any problem. I don't think the use model you have in mind is compatible with the language. Even if when you define the my_interfaces
port as an array of generic interfaces, it's still an array and it's going to expect an array of a certain type of interface to be connected to it. An array can only hold objects of the same type.
What you can do is use the maximum footprint approach and always connect all interfaces you need. You'd need to explicitly define each as an own port. Based on your parameter you'd just exclude parts of your logic (using generate
statements) and the unused wires should be optimized away by your synthesis tool.
Upvotes: 1