Parameterized interfaces and their instances

Hello,

Please comment about case 1 and case 2 separately can-do/can’t-do.

Case: 1,
If I have a definition of the interface with parameter.

interface bus_intfc #(parameter MAX_NUM_PORTS = 1) (input logic clk, input logic reset);
  //relevant code of interface
endinterface

Then I can instantiate interface as below:

bus_intfc #(.MAX_NUM_PORTS(3)) bus_monitor_intfc (i_clk_d, reset_d);

Case: 2,
If I have definition of the interface without any paramter but inside interface I have parameter.

interface bus_intfc(input logic clk, input logic reset);
  parameter MAX_NUM_PORTS = 1;
  //other relevant code of interface
endinterface

Can I still instantiate above interface as?

bus_intfc #(.MAX_NUM_PORTS(3)) bus_monitor_intfc (i_clk_d, reset_d);

Thank you.

In reply to megamind:

Referring to IEEE 1800-2012 Section 23.10, parameter can be declared at two places:

There are two different places parameters can be defined within a module (or interface or program). The first is the module’s parameter_port_list (see 23.2), and the second is as a module_item (see 6.20). A module declaration can contain parameter definitions of either or both types or can contain no parameter definitions.

Here in your case 1 and 2, it will override the parameter.

In reply to sharvil111:

One point that needs mentioning is if you mix the two case, as in

interface bus_intfc #(int MIN_NUM_PORTS) (input logic clk, input logic reset);
  parameter MAX_NUM_PORTS = 1;
  //other relevant code of interface
endinterface

You can no longer override the parameter MAX_NUM_PORTS as it becomes a
localparam
. This is explained later in section 23.10.

For that reason, I recommend only using the first case to specify parameters that may be overridden.

In reply to dave_59:

Thanks Dave for pointing it out. Yes one can not override localparams. The two coding styles should not be mixed.