Advanced Interfaces
Advanced Interfaces
Interfaces
By Rashmi B K
Agenda
• Why we use interface?
• Testbench with physical interface.
• Testbench with virtual interface.
• Modport
• Clocking block
• Connecting the testbench to interface in port list.
• Connecting test to interface with XMR.
• Using Typedef with virtual interface
• Procedural code in interface
• Limitation of interface code
Why we use interface?
• Abstraction and Encapsulation:
• Interfaces allow you to abstract away the details of signal connections and behaviors between
modules or blocks.
• By encapsulating signals and their associated behaviors within an interface, you can hide the
implementation details from the module using the interface..
module Memory (input clk, input rst, input [31:0] address, inout );
[31:0] data);
// CPU logic using the memory interface
// Memory implementation goes here
// ...
endmodule
endmodule
Testbench with physical interface
// demo interface with 2 inputs and 1 output. module tb_top(); Output:
interface demo_intf; demo_intf intf();
logic in1; ex_dut dut(intf);
initial begin
logic in2;
intf.in1 <= 1'b1;
logic out1;
intf.in2 <= 1’b0;
endinterface //demo_intf
$monitor("in1 = %b, in2 = %b, out1 =
%b",intf.in1, intf.in2, intf.out1);
// example rtl which outputs and of 2 inputs #20;
module ex_dut(demo_intf intf); intf.in1 <= 1'b1;
assign intf.out1 = intf.in1 & intf.in2; intf.in2 <= 1’b1;
endmodule $monitor("in1 = %b, in2 = %b, out1 =
%b",intf.in1, intf.in2, intf.out1);
end
endmodule
Virtual Interface
• The most common use for a virtual interface is to allow objects in a testbench to refer to
items in a replicated interface using a generic handle rather than the actual name.
• Virtual interfaces are the only mechanism that can bridge the dynamic world of objects
with the static world of modules and interfaces.
Testbench with virtual interface