A7.1.3 Bind into a Black Box

MediumImplementVerilator · serverReview the topic

Write rules for a VHDL-style entity on its ports only, bound into the entity.

Hardware context: A UART transmitter delivered as a VHDL entity, with only its ports visible. Write and bind datasheet rules on the ports of a block whose inside is hidden.

A UART transmitter arrives as a VHDL entity: SystemVerilog sees its ports and nothing inside. Two rules come from its datasheet. A start while busy is illegal, and a start makes the block busy at the next edge.

Write uart_rules, and fix the bind into vhdl_uart, the entity, so it connects the right ports. The entity's body here is a Verilog stand-in; do not use anything inside it. A wrapper, uart_wrap, has ports with the same names but other meanings.

Signals in the Timeline

SignalWidthRole
clk1stimulus, the same for every design
go1stimulus, the same for every design
tx_busy1stimulus, the same for every design
Full specification
The entity stand-in and the wrapper (given)
// A stand-in for a VHDL entity. Treat its body as unknown: only the ports are part of the contract.
module vhdl_uart (input logic clk, tx_start, output logic tx_busy);
  logic [1:0] n = 0;
  logic busy_q = 0;                            // internal: a delayed copy, not part of the contract
  always @(posedge clk) begin
    if (tx_start || n != 0) n <= n + 2'd1;
    busy_q <= (n != 0);
  end
  assign tx_busy = (n != 0);
endmodule
// A wrapper that also has ports named tx_start and tx_busy, with other meanings.
module uart_wrap (input logic clk, go, output logic tx_busy, output logic tx_start);
  vhdl_uart core (.clk(clk), .tx_start(go), .tx_busy(tx_busy));
  assign tx_start = go && !tx_busy;            // a filtered request, not the raw one
endmodule
The rule module ports (keep them)
module uart_rules (
  input  logic clk, tx_start, tx_busy,
  output int   restart,     // tx_start while busy
  output int   no_busy      // tx_start not followed by busy at the next edge
);
  // two rules
endmodule
// and one bind statement
EdgeWhat the program shown here doesExpected
15a start: busy from 25nothing
35a second start while busyrestart fails once

The full check also runs a second program, which this page does not show. Counts are read from the bound instance: u_wrap.core.rules.

Examples

Example 1

One Restart
Input
Program: a start at 15, another at 35
Output
restart = 1

The start at 35 comes while the block is busy.

Example 2

Every Start Makes It Busy
Input
Program: a start at 15, another at 35
Output
no_busy = 0

Busy follows each start at the next edge.

Example 3

None by 30
Input
Program: only the first start
Output
restart = 0

The only start before 30 comes while the block is idle.

Constraints and Contract

  • Write uart_rules with two concurrent assertions on its ports only.
  • Keep the bind into vhdl_uart (the entity), instance name rules, on the entity's ports.
  • Do not change the ports of uart_rules.

Hints

Hint 1

A VHDL entity exposes only its ports to a bind.

Hint 2

The wrapper also has a tx_start port, but it is a filtered copy. Bind to the entity itself.

Hint 3

The counters are outputs; a bind may leave them unconnected with .restart().

What the grader checks: Your module and bind are compiled with a fixed bench of two programs: the one shown here and a hidden one. Graded: both failure counts of the bound instance in each.

5 checks on Verilator · server. Run the examples first, then check the full regression. Full checks use the server judge. Downloads contain public samples only. A passing result establishes the tested cases, not a proof for all possible inputs.

See all 4 steps and the final capstone

Report a problem with this page

Your code SystemVerilogSaved locally
Ln 1, Col 1Tab indents · Ctrl/⌘ + Enter runs samples
Not run yet

One Restart

Input
Program: a start at 15, another at 35
Expected output
restart = 1

The start at 35 comes while the block is busy.

Run samples executes all 3 public checks. Check all tests runs 5 checks on the server.

Verilator · server