2018-10-11 16:33:31 -05:00
|
|
|
|
|
|
|
|
|
|
|
module TopModule(
|
|
|
|
input logic clk,
|
|
|
|
input logic rst,
|
|
|
|
input logic [1:0] sig,
|
|
|
|
output logic [1:0] sig_out);
|
|
|
|
|
|
|
|
MyInterface #(.WIDTH(4)) MyInterfaceInstance();
|
|
|
|
|
|
|
|
SubModule1 u_SubModule1 (
|
|
|
|
.clk(clk),
|
|
|
|
.rst(rst),
|
|
|
|
.u_MyInterface(MyInterfaceInstance),
|
|
|
|
.sig (sig)
|
|
|
|
);
|
|
|
|
|
|
|
|
assign sig_out = MyInterfaceInstance.mysig_out;
|
|
|
|
|
|
|
|
|
|
|
|
assign MyInterfaceInstance.setting = 1;
|
2018-10-12 13:58:37 -05:00
|
|
|
// assign MyInterfaceInstance.other_setting[2:0] = 3'b101;
|
2018-10-11 16:33:31 -05:00
|
|
|
|
|
|
|
endmodule
|
|
|
|
|
|
|
|
interface MyInterface #(
|
|
|
|
parameter WIDTH = 3)(
|
|
|
|
);
|
|
|
|
|
|
|
|
logic setting;
|
|
|
|
logic [WIDTH-1:0] other_setting;
|
|
|
|
|
|
|
|
logic [1:0] mysig_out;
|
|
|
|
|
2018-10-12 13:58:37 -05:00
|
|
|
modport submodule1 (
|
|
|
|
input setting,
|
|
|
|
output other_setting,
|
|
|
|
output mysig_out
|
|
|
|
);
|
|
|
|
|
|
|
|
modport submodule2 (
|
|
|
|
input setting,
|
|
|
|
output other_setting,
|
|
|
|
input mysig_out
|
|
|
|
);
|
|
|
|
|
2018-10-11 16:33:31 -05:00
|
|
|
endinterface
|
|
|
|
|
|
|
|
|
|
|
|
module SubModule1(
|
|
|
|
input logic clk,
|
|
|
|
input logic rst,
|
2018-10-12 13:58:37 -05:00
|
|
|
MyInterface.submodule1 u_MyInterface,
|
2018-10-11 16:33:31 -05:00
|
|
|
input logic [1:0] sig
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
always_ff @(posedge clk or posedge rst)
|
|
|
|
if(rst)
|
|
|
|
u_MyInterface.mysig_out <= 0;
|
|
|
|
else begin
|
|
|
|
if(u_MyInterface.setting)
|
|
|
|
u_MyInterface.mysig_out <= sig;
|
|
|
|
else
|
|
|
|
u_MyInterface.mysig_out <= ~sig;
|
|
|
|
end
|
|
|
|
|
|
|
|
MyInterface #(.WIDTH(22)) MyInterfaceInstanceInSub();
|
|
|
|
|
|
|
|
SubModule2 u_SubModule2 (
|
|
|
|
.clk(clk),
|
|
|
|
.rst(rst),
|
|
|
|
.u_MyInterfaceInSub2(u_MyInterface),
|
|
|
|
.sig (sig)
|
|
|
|
);
|
|
|
|
|
|
|
|
endmodule
|
|
|
|
|
|
|
|
module SubModule2(
|
|
|
|
|
|
|
|
input logic clk,
|
|
|
|
input logic rst,
|
2018-10-12 13:58:37 -05:00
|
|
|
MyInterface.submodule2 u_MyInterfaceInSub2,
|
2018-10-11 16:33:31 -05:00
|
|
|
input logic [1:0] sig
|
|
|
|
|
|
|
|
);
|
|
|
|
|
2018-10-12 13:58:37 -05:00
|
|
|
assign u_MyInterfaceInSub2.other_setting[2:0] = 9;
|
|
|
|
|
2018-10-11 16:33:31 -05:00
|
|
|
endmodule
|