What you practice
modports (1.8). Use modports to define and enforce input/output directions for master and slave endpoints. It is in Interfaces — Part 1 · Design in SV of the SystemVerilog Masterclass. Synthesizable SystemVerilog that removes Verilog ambiguity and cuts boilerplate.
The same IDE is the SystemVerilog simulator. Slang lints the file, Verilator runs it, and the waveform viewer sits next to the source.
What you will learn
This lesson teaches how to use SystemVerilog modports to enforce signal direction contracts on shared interfaces, enabling clear separation of master and slave roles in hardware designs.
Learning objectives
- Define modport declarations inside an interface to specify input/output directions.
- Ensure testbench stimulus respects the direction contracts defined by modports.
Theory
A modport inside an interface declares which signals are inputs or outputs *from the perspective of a specific module endpoint*. This prevents accidental cross-direction connections and improves design clarity.
| Modport Role | Signal Direction | Purpose |
|---|---|---|
master | output valid, data; input ready | Drives control and data, samples handshake |
slave | input valid, data; output ready | Samples control and data, drives handshake |
The interface itself does not drive signals; modports only describe how each module *views* the interface signals.
Practice
Open RtlStudio and select this chapter. Files appear automatically in Explore.
- Open
student/rtl/design.svin the editor. - In the
data_ifinterface, replace the__TODO__placeholders inside themodport master(...)andmodport slave(...)declarations with the correct signal direction keywords (inputoroutput). - Run Simulation from the sidebar and check the Log panel.
- Verify the log matches the expected output and ends with
INFO: PASS.
Summary
You practiced defining modport direction contracts inside a SystemVerilog interface to distinguish master and slave roles. By correctly specifying inputs and outputs for each endpoint, you enforced signal directionality and prevented misuse at compile time. Connecting the DUT to these modports ensured the design respected the agreed-upon handshake protocol. Simulation confirmed the direction contracts were honored, as shown by the expected INFO messages and waveform alignment.
Run it in the Verilog IDE
- Open the lesson in the IDE. The SystemVerilog for this topic is already in the editor.
- Lint with Slang before you simulate. It covers both Verilog and SystemVerilog in this IDE.
- Run Verilator and inspect the VCD. Interfaces, classes, and assertions count only if the simulator agrees.
- Run Yosys when the lesson is synthesizable RTL, and keep testbench-only constructs out of that module.
The lesson is done when the simulation matches modports. Change the source, run the Verilog simulator again, and read the waveform without leaving the IDE. Simulation guide · Yosys guide.