Interface

Welcome to the System Verilog tutorial series! If you have any doubts / suggestions, please let us know!  Dear visitor, please Sign up / Login for Free and get privileged access! You can copy code, download free tutorials and do more when you’re logged in!

The communication between blocks of a digital system is a critical area. In Verilog, modules are connected using module ports. For large modules, this is not productive as it involves.

  • Manually connecting hundreds of ports may lead to errors.
  • Detailed knowledge of all the port is required.
  • Difficult to change if the design changes.
  • More time consuming.
  • Most port declaration work is duplicated in many modules.

Let us see a verilog example:

module Dut (input clk, read, enable,
Input [7:0] addr,
output [7:0] data);
....
assign data = temp1 ? temp2 : temp3 ;
always @(posedge clk)
....
endmodule
module Testbench(input clk,
Output read, enable,
output [7:0] addr,
input [7:0] data );
endmodule

Integrating the above two modules in top module.

1-22
module top();
reg clk;
wire read, enable;
wire [7:0] addr;
wire [7:0] data;
Dut D (clk,read,enable,Addr,data);
Testbench TB(clk,read,enable,Addr,data);
endmodule

All the connection clk, read, enable, addr, data are done manually. Line 7 and 9 has same code structure which is duplicating work. If a new port is added, it needs changes in DUT ports, TestBench Ports, and in 7, 10 lines of Top module. This is timeconsuming and maintaining it is complex as the port lists increases.

To resolve the above issues, SystemVerilog added a new powerful features called interface. Interface encapsulates the interconnection and communication between blocks.

Interface declaration for the above example:

interface intf #(parameter BW = 8)(input clk);
logic read, enable;
logic [BW -1 :0] addr,data;
endinterface :intf

Here the signals read, enable, addr, data are grouped in to “intf”. Interfaces can have direction as input, output and inout also. In the above example, clk signal is used as input to interface. Interfaces can also have parameters like modules. Interface declaration is just like a module declaration. Uses keywords interface, endinterface for defining. Inside a module, use hierarchical names for signals in an interface.

TIP: Use wire type in case of multiple drivers. Use logic type in case of a single
driver.

Let use see the DUT and Testbench modules using the above declared interface.

module Dut (intf dut_if); // declaring the interface
always @(posedge dut_if.clk)
if(dut_if.read) // sampling the signal
$display(" Read is asserted");
endmodule
module Testbench(intf tb_if);
initial
begin
tb_if.read = 0;
repeat(3) #20 tb_if.read = ~tb_if.read;// driving a signal
$finish;
end
endmodule

Integrating the above two modules in top module.

1-23

module top();
bit clk;
initial
forever #5 clk = ~clk;
intf bus_if(clk); // interface instantiation
Dut d(bus_if); // use interface for connecting D and TB
Testbench TB (bus_if);
endmodule

See, how much code we got reduced in this small example itself. In the above example, I demonstrated the connectivity between DUT and TestBench. Interfaces can also be used for connectivity between the DUT sub modules also.

Advantages Of Using Inteface:

  • An interface can be passed as single item.
  • It allows structured information flow between blocks.
  • It can contain anything that could be in a module except other module definitions or instance.
  • Port definitions are independent from modules.
  • Increases the reusability.
  • It Interface can be declared in a separate file and can be compiled separately.
  • Interfaces can contain tasks and functions; with this methods shared by all modules connecting to this information can be in one place.
  • Interface can contain protocol checking using assertions and functional coverage blocks.
  • Reduces errors which can cause during module connections.
  • Easy to add or remove a signal. Easy maintainability.