使用modport可以将interface中的信号分组并指定方向
1.在interface模块中增加modport
interface cnt_if (input bit clk);
logic rstn;
logic load_en;
logic [3:0] load;
logic [3:0] count;
modport TEST (input clk, count,
output rstn,load_en,load);
modport DUT (input clk,rstn,load_en,load,
output count);
endinterface
2.两种方法来使用modport名
2.1在相应的模块中使用,如下所示。
module counter_ud (cnt_if.DUT cnt_if0);
.......
endmodule
module test (cnt_if.TEST cnt_if0);
......
endmodule
2.2在顶层模块中使用
module top;
bit clk;
always #5 clk = ~clk;
cnt_if cnt_if0 (clk);
counter_ud u0 (cnt_if0.DUT);
test t1 (cnt_if0.TEST);
endmodule