| SystemVerilog Interfaces Introduction A simple interface is a named bundle of signals which can be referenced throughout a design to simplify hierarchical connections and module instantiation. More complex interfaces can contain functional code to encapsulate communication between design blocks. Tutorial
module mem (input logic clk, req, start,
logic [7:0] addr, output logic [7:0] data, logic gnt, rdy); ...
module cpu (input logic clk, gnt, rdy,
logic [7:0] data, output logic req, start, logic [7:0] addr); ...
module top;
Here a connection between the modules mem and cpu is composed of the signals reg, gnt, start, rdy, mode, addr and data. Each of these connections must be declared in modules mem, cpu and top. As each port must be declared in several places, initial construction of the hierarchy is time-consuming and maintenance is difficult, as multiple alternations are required to multiple modules if the bus changes.
Creating a SystemVerilog Interface
SystemVerilog allows the bus to be declared once as an interface. An interface is a design unit in SystemVerilog like a module, i.e. it is declared in a separate file and compiled separately.
Here the signals reg, gnt, start, rdy, mode, addr and data are declared in an interface named bus_if.
The interface name is then used as a type for a port declaration in a module port list. Since a single interface can contain both input and output ports, the interface port is directionless.
A port of type bus_if and name bus is added to modules mem and cpu.
The interface is then instantiated in the module top and the instantiated interface name mapped to the interface ports of the modules.
An interface named busA of type bus_if is instantiated and mapped to the interface ports of mem and cpu in the module instantiations. Note that the interface instantiation makes the interface signals visible in module top, so we only need to declare clk.
Accessing Interface Signals
Modports A simple interface does not contain any direction information for the interface signals. Therefore a module to which the interface is connected can read or write to any interface signal.
Typically a bus connection between 2 modules will have a direction associated with it – a signal will be an input to one module and an output of the other. This gives us 2 views of the bus signal. These views can be defined in an interface using modports.
In the next tutorial we will examine the use of modports in interfaces.
Previous Tutorial | Next Tutorial |


