Modports are defined inside the interface using the modport keyword:
interface ahb_if (input logic HCLK);
// Signals
logic HRESETn;
logic [31:0] HADDR;
logic [1:0] HTRANS;
logic HWRITE;
logic [2:0] HSIZE;
logic [31:0] HWDATA;
logic [31:0] HRDATA;
logic HREADY;
logic [1:0] HRESP;
// Master's view - drives address/control, receives data/response
modport master (
input HCLK, HRESETn,
output HADDR, HTRANS, HWRITE, HSIZE, HWDATA,
input HRDATA, HREADY, HRESP
);
// Slave's view - receives address/control, drives data/response
modport slave (
input HCLK, HRESETn,
input HADDR, HTRANS, HWRITE, HSIZE, HWDATA,
output HRDATA, HREADY, HRESP
);
// Monitor's view - only observes, never drives
modport monitor (
input HCLK, HRESETn,
input HADDR, HTRANS, HWRITE, HSIZE, HWDATA,
input HRDATA, HREADY, HRESP
);
endinterface
Direction is Relative!
input and output are from the module's
perspective. What's an output for master is an input for slave.