I use SystemVerilog for synthesis. I struggled with the fact that the interface arrays are not really arrays in SystemVerilog, and the index should be a constant value, but exceeded it using many generate for and assign patterns to overcome what is really a language restriction (if I can emulate the effect using more code, the language could just do The Right Thing (tm)).
For the next pseudo-code, I leave for myself most of what is in real code (modports, tasks, etc.). I have an interface:
interface i_triplex(); logic a;
And I pass an array of these interfaces to a module that looks like
module roundrobin_triplex#( parameter int NUNITS = 8 ) ( input wire clk, input wire rst, i_triplex t[NUNITS] ); always_ff @(posedge clk) begin if (rst) begin
What is the preferred way to use an entire interface instance in an array uniformly - regardless of the NUNITS value? I have some suggestions, but I really want to know what other engineers can offer.
Suggestion 1: Use VHDL.
Proposition 2: Reset the interface and do it oldschool Verilog-style, as in
module roundrobin_triplex#( parameter int NUNITS = 8 ) ( input wire clk, input wire rst,
Proposition 3: Use struct for input wires and struct for output wires instead of an interface.
Proposition 4: Use a preprocessor system that deploys generate for loops inside processes (what the language should do anyway!), So the resulting code looks like (pre-processed using NUNITS = 4):
module roundrobin_triplex#( parameter int NUNITS = 8 ) ( input wire clk, input wire rst, i_triplex t[NUNITS] ); always_ff @(posedge clk) begin if (rst) begin i_triplex.data[0] <= '1; i_triplex.data[1] <= '1; i_triplex.data[2] <= '1; i_triplex.data[3] <= '1; end else begin // ... end end endmodule
Proposition 5: Use the generate for / assign solution:
module roundrobin_triplex