Module 9: SystemVerilog for Design & Verification · 9.1 SystemVerilog Design Enhancements

Interfaces and Modports

Digital hardware protocols require groups of signals that operate synchronously together. In classic Verilog, every communicating module redeclares all protocol signals individually. SystemVerilog interfaces encapsulate entire signal groups into unified, reusable communication channels.

The Problem: Repetitive Port Lists

In classic Verilog, communicating blocks redeclare identical signal lists:

// Classic Verilog: repetitive signal declarations across modules
module producer (
    output wire [7:0] wdata,
    output wire        wr_en,
    input  wire        full
);
endmodule

module consumer (
    input  wire [7:0] rdata,
    output wire        rd_en,
    input  wire        empty
);
endmodule

These separate declarations increase the likelihood of bus width mismatches and typographical wiring errors. Top-level netlists become verbose and difficult to maintain.

Protocol Encapsulation with Interfaces

SystemVerilog solves this problem by defining an interface:

interface fifo_if #(parameter DATA_WIDTH = 8);
    logic [DATA_WIDTH-1:0] wdata, rdata;
    logic                  wr_en, rd_en;
    logic                  full, empty;
endinterface

Modules reference the interface bundle directly in their port definitions:

module producer (fifo_if.producer_port fifo);
    // Access signals as fifo.wdata, fifo.wr_en, and fifo.full
endmodule

module consumer (fifo_if.consumer_port fifo);
    // Access signals as fifo.rdata, fifo.rd_en, and fifo.empty
endmodule

This construct simplifies port lists and guarantees that all connected modules use matching bus parameters.

Directional Access Control with Modports

Different modules view shared interface signals in opposing directions. The modport construct specifies signal directions for each functional role:

interface fifo_if #(parameter DATA_WIDTH = 8);
    logic [DATA_WIDTH-1:0] wdata, rdata;
    logic                  wr_en, rd_en;
    logic                  full, empty;

    modport producer_port (
        output wdata, wr_en,
        input  full
    );

    modport consumer_port (
        input  rdata,
        output rd_en,
        input  empty
    );
endinterface

A module bound to fifo_if.producer_port can drive wdata and wr_en, but cannot drive full. Attempting to drive an input signal causes a compile-time syntax error. Modports prevent accidental multi-driver conflicts across module boundaries.

One interface instance, two modports with opposite directions
Figure 1: Modports give each side its own view of signal direction

Module Instantiation and Connection

At the structural top level, an interface instantiates like a module:

module top;
    fifo_if #(.DATA_WIDTH(16)) my_fifo_bus();

    producer u_producer (.fifo(my_fifo_bus.producer_port));
    consumer u_consumer (.fifo(my_fifo_bus.consumer_port));
endmodule

This approach replaces extensive point-to-point wire declarations with a single interface instance. Industry-standard protocols like AXI, APB, and Wishbone rely on interfaces to enforce robust system connectivity.

Practice Exercise

Define a third modport named monitor_port for the fifo_if interface. This modport must observe all six interface signals without driving any net.

Solution
modport monitor_port (
    input wdata, rdata, wr_en, rd_en, full, empty
);

Every signal is defined as an input. A verification monitor connected via monitor_port observes bus activity passively. The compiler prohibits the monitor from driving any signal on the interface.

SystemVerilog interfaces group protocol nets into structured communication bundles. Modports enforce signal direction rules for each connected component at compile time. This completes Section 9.1 on SystemVerilog design enhancements. Section 9.2 introduces object-oriented class constructs for digital verification.

← typedef, struct, union and enum Classes and Objects for Verification →