Write one case property for a latency that depends on a mode, and one if-else property for writes and reads.
Hardware context: A transfer engine with latency modes and a bus with writes and reads. Pick the property to check from a mode with case and from the transfer kind with if-else.
Write two concurrent assertions on the rising edge of clk. Rule by_mode is a case property on mode: when v is 1, done comes 1, 2 or 3 edges later for mode 0, 1 or 2.
Mode 3 is not checked. Rule by_kind is an if-else property: when req is 1, a write gets ack after one edge and a read gets rdy after two.
Count each failure of each rule in its own counter.
Signals in the Timeline
| Signal | Width | Role |
|---|---|---|
clk | 1 | stimulus, the same for every design |
v | 1 | stimulus, the same for every design |
mode | 2 | stimulus, the same for every design |
done | 1 | stimulus, the same for every design |
req | 1 | stimulus, the same for every design |
wr | 1 | stimulus, the same for every design |
ack | 1 | stimulus, the same for every design |
rdy | 1 | stimulus, the same for every design |
your mode_errors | 32 | stimulus, the same for every design |
your kind_errors | 32 | stimulus, the same for every design |
Full specification
module mode_rules (
input logic clk,
input logic v, // a transfer starts
input logic [1:0] mode, // its latency mode
input logic done, // the transfer's completion
input logic req, wr, // a request, and whether it is a write
input logic ack, rdy, // write acknowledge, read data ready
output int mode_errors, // rule by_mode
output int kind_errors // rule by_kind
);
// by_mode: when v is 1, done comes 1, 2 or 3 edges later for mode 0, 1 or 2. Mode 3 is not checked.
// by_kind: when req is 1, a write (wr = 1) gets ack after one edge, a read gets rdy after two.
endmodule
The program shown here gives the sampled value of each signal at each rising edge (at 5, 15, 25, ...):
| Edge | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| v | 1 | 0 | 1 | 0 | 0 | 1 | 0 | 1 | 0 | 0 | 0 | 0 |
| mode | 0 | 0 | 1 | 0 | 0 | 2 | 0 | 3 | 0 | 0 | 0 | 0 |
| done | 0 | 1 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| req | 1 | 0 | 1 | 0 | 0 | 1 | 1 | 0 | 0 | 0 | 0 | 0 |
| wr | 1 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 |
| ack | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| rdy | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 |
The full check also runs a second program that this page does not show, with another clock and other modes.
Examples
Example 1
Mode 2 Answered Too Late- Input
Program: modes 0, 1, 2, 3; 2 writes, 2 reads
- Output
mode_errors = 1
Modes 0 and 1 are answered in time. Mode 2 at edge 6 never sees done at edge 9. Mode 3 is not checked.
Example 2
A Read and a Write Unanswered- Input
Program: modes 0, 1, 2, 3; 2 writes, 2 reads
- Output
kind_errors = 2
The read at edge 3 has no rdy at edge 5. The write at edge 6 has no ack at edge 7.
Example 3
Three Failures in All- Input
Program: modes 0, 1, 2, 3; 2 writes, 2 reads
- Output
total = 3
One from by_mode and two from by_kind.
Constraints and Contract
- Write by_mode with a case property and by_kind with an if-else property.
- Count failures in mode_errors and kind_errors.
- Do not change the ports.
Hints
Hint 1
Each case item is a whole property, such as ##2 done.
Hint 2
Mode 3 is not checked. What should its item, or the default, say?
Hint 3
Without an else, reads are never checked.
What the grader checks: Two copies of your rules each watch a fixed program. One is shown here; the other is hidden, with another clock. Graded on each: the two failure counts. The source must use a case property and an if-else property.
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 2 steps and the final capstone