For source, valid, data, and last are outputs, while ready is an input. sink reverses those directions. Read directions from the perspective of the module using the modport.
A module can receive the interface instead of repeating every signal:
module stream_register ( input logic i_rst, simple_stream_if.sink upstream, simple_stream_if.source downstream); always_ff @(posedge upstream.clk) begin if (i_rst) begin downstream.valid <= 1'b0; downstream.data <= '0; downstream.last <= 1'b0; end else if (upstream.valid && upstream.ready) begin downstream.data <= upstream.data; downstream.last <= upstream.last; downstream.valid <= 1'b1; end else if (downstream.ready) begin downstream.valid <= 1'b0; end end assign upstream.ready = downstream.ready || !downstream.valid;endmodule
The register accepts new data when empty or when the receiver consumes the previous item. It holds data and valid during a stall. Explicit reset prevents a startup transaction. Both sides must share a clock domain and compatible widths.
Set testbench exchange timing
In tb_cb, input #1step samples one precision step before the edge. output #0 drives at the current edge using clocking-block scheduling.
@bus.tb_cb;bus.tb_cb.valid <= 1'b1;bus.tb_cb.data <= value;do @bus.tb_cb; while (!bus.tb_cb.ready);bus.tb_cb.valid <= 1'b0;
Use nonblocking assignments for clocking outputs and wait for its event. Writing bus.valid directly bypasses these rules. This fragment omits last; a complete driver must initialize it and hold it with the data.
A clocking block has one clock expression. Define separate timing views for multiple domains; an interface does not perform CDC.
Access the bus from a class
A physical interface is static; a class is created dynamically. A virtual interface is a handle to that instance:
The tb modport limits the driver's view. This declaration uses the default width. Parameterize the virtual type too when using another width.
Connect the top level
simple_stream_if #(.WIDTH(16)) link (.clk(i_clk));producer u_producer (.bus(link.source));consumer u_consumer (.bus(link.sink));
link contains the shared signals. The contract still needs transfer on valid && ready, stability under stall, and reset behavior. Modports do not enforce those rules.
Many tools support simple interfaces. Check limits on methods, interface arrays, parameters, and IP boundaries before exposing one as a public interface.