Creating multiple instances of interface inside the interface

This post is just for reference on how to create a multiple instance of interface/module inside a interface or module.

There would be lots of situation where we would be required to take multiple instance of the same module/interface, one crude way is to use the hard coded names and the use some macros to use it.

The other way is to use a generate block and make it more generic.

With using generate block its slight different than using it with a normal for loop.

Here is the complete code,

interface if0;
   logic x,y; 
endinterface


interface intf;
  
logic a,b;
  genvar i;
  generate
    for (i =0;i<3;i++) begin:if0_1
      if0 if1();
    end
  endgenerate
endinterface


module top();
  
  intf intf_0();
  
  initial 
    begin
      intf_0.if0_1[0].if1.x = 1'b0;
      
    end
endmodule

If you observe, rather than declaring the

if0  if1[i];

its been declared just once, but while accessing its the block name if0_1 is used multiple times.

For more details refer to section 27.4 example 5 of LRM 1800-2012

Please let me know if there is better way to do this.

EDA playground link for ref





what advantage does it have over an array of interfaces , like if0 if1[3](); ?

回复

要查看或添加评论,请登录

社区洞察

其他会员也浏览了