Check the interface type using parameterized interface

Hello! I want to check the interface type and make error if it’s not correct.

interface prm_if #(parameter int P_MODE_PRM = 0) ();
...
endinterface

// I want to write like this, but it's compile errror.
module prm_if_dut (prm_if #( .P_MODE_PRM(1) ) p);
...
endmodule

module top

prm_if #(.P_MODE_PRM(2)) prm_bus();  // P_MODE_PRM is not correct for prm_if_dut
prm_if_dut dut(prm_bus);  // I want to make error because the Mode is not corect
                          // P_MODE_PRM must be 1 for prm_if_dut, but it's 2 so I expect to occur syntax error here.

Do I have some mistake or do you have any solution about this?

Thanks!

Unfortunately, you cannot parameterize an interface port declaration. It will inherit the parameterization of what’s connected to it.
You can put a check and create an elaboration error if the value is not 2.

module prm_if_dut (prm_if  p);
  if (p.P_MODE_PRM != 1) $error("p.P_MODE_PRM != 1"); // error at elaboration
// ...
endmodule
module top;
  prm_if #(.P_MODE_PRM(2)) prm_bus();
  prm_if_dut DUT(prm_bus);
endmodule

interface prm_if #(parameter int P_MODE_PRM = 0) ();
//...
endinterface
2 Likes

Thanks for replying!