A1.6.2 Bus Rules Through a Clocking Block

EasyImplementVerilator · serverReview the topic

Clock a checker with a default clocking block, read its signals through the block, and wait with a cycle delay.

Hardware context: A request/acknowledge bus sampled on the rising clock edge. Read the bus through a default clocking block and wait in clock cycles.

Write the checker bus_rules. Give it a default clocking block cb on the rising edge of clk, with inputs req and ack and the default skew.

Rule ack_in_two: a request seen at an edge is acknowledged exactly two edges later. Write it in the assert statement with no clock of its own, reading cb.req and cb.ack.

The checker also arms itself: an initial block waits three edges with ##3 and then records armed_at = $time.

Signals in the Timeline

SignalWidthRole
clk1stimulus, the same for every design
req1stimulus, the same for every design
ack1stimulus, the same for every design
your errors32your checker's error count
Full specification
The ports (keep them)
module bus_rules (
  input  logic clk,
  input  logic req, ack,
  output int   errors,      // failures of the ack rule
  output int   armed_at     // $time when the checker arms itself
);
  // your clocking block, rule and arming
endmodule

The program shown here changes req 1 ns before the edge at 15. A skew of 1 ns or more would read the old value there.

Requests are seen at 15 and 65. The first is acknowledged at 35. The second never is.

The full check also runs a second program that this page does not show, with another clock period and other pulses.

Simulator note: The standard lets an assertion read a clocking block input only with the default #1step skew (IEEE 1800-2023 16.5.1). Verilator 5.052 accepts another skew without an error and reads the older value (measured).

Examples

Example 1

The Answered Request
Input
A request at 15, ack at 35
Output
early_errors = 0

cb.req samples 1 just before the edge at 15, and cb.ack is 1 at 35: no failure.

Example 2

The Lost Request
Input
A request at 65, no ack at 85
Output
late_errors = 1

The request seen at 65 has no ack at 85: one failure.

Example 3

Three Rising Edges
Input
##3 from time 0
Output
armed_at = 25

The default clock rises at 5, 15 and 25, so the checker arms at 25.

Constraints and Contract

  • Read req and ack through the clocking block, in a rule with no clock of its own.
  • Keep the default input skew.
  • Count failures in errors.

Hints

Hint 1

An explicit clock in an assertion makes the default unused. Leave the clock out of the property.

Hint 2

A clocking block input with the default skew, #1step, samples just before the edge.

Hint 3

##3; in procedural code needs a default clocking in the same module.

What the grader checks: Two copies of your checker each watch a fixed program: the one shown here and a hidden one with other timing. Graded on each: failures before and after a set time, and the arming time. The source must read cb.req and cb.ack in a rule with no clock of its own.

6 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 3 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

The Answered Request

Input
A request at 15, ack at 35
Expected output
early_errors = 0

cb.req samples 1 just before the edge at 15, and cb.ack is 1 at 35: no failure.

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

Verilator · server