Write the checker for a credited link. It rebuilds the sender's credit count from the wires. It catches a beat with no credit, a credit spent too early, a credit too many and noise in reset.
Hardware context: A FIFO sink with backpressure or credits between a source and a stalling consumer. Check a credited link from its valid and credit wires: no beat without a credit, next-edge use, no overflow, quiet reset.
Lesson P1.6 listed the rules a credit obeys. On the wires a credited link has only two signals that matter: valid, one beat crossing, and crdt, one credit given. Everything else is a count both ends must agree on.
Write module credit_checker. Rebuild the sender's credit count from valid and crdt, and add one to errors for every rule an edge breaks. The receiver has MAX slots, so it may never give more than MAX credits that are not yet spent.
Six links drive it. One keeps every rule. It starts with no credits and gets four from the receiver, one per cycle. It spends a credit only from the edge after it arrived. The other five each break one rule. You pass with zero on the first and at least one on each broken link.
Signals in the Timeline
| Signal | Width | Role |
|---|---|---|
clk | 1 | stimulus, the same for every design |
rst_n | 1 | stimulus, the same for every design |
valid | 1 | output of the design under test |
crdt | 1 | output of the design under test |
your errors | 32 | output of the design under test |
Full specification
module credit_checker #(parameter int MAX = 4) (
input logic clk,
input logic rst_n,
input logic valid, // a beat crosses the link at this edge
input logic crdt, // the receiver gives one credit at this edge
output int errors
);
// your checker
endmodule
| Rule | At an edge |
|---|---|
| quiet reset | While rst_n is 0, valid and crdt are both 0, and the sender's count is 0. |
| no beat without a credit | valid = 1 needs a credit given at an earlier edge and not yet spent. It spends that credit. |
| next-edge use | A credit given at an edge (crdt = 1) can pay only for a beat at a later edge. |
| no overflow | After the edge, the sender never holds more than MAX credits. |
Sample at the rising edge. Each of the four scenarios starts with two reset edges and runs 32 more. MAX is 4.
For each link you get alarm = yes or no. For the correct one you also get first_alarm_scenario and first_alarm_cycle.
Examples
Example 1
The Correct Link Must Not Raise an Alarm- Input
Link: keeps every rule Scenarios: A steady stream into a fast consumer; A burst into a slow consumer; Bursts with gaps; A stalled consumer drains while the sender is idle
- Output
alarm = no
The receiver hands over four credits in the first four cycles after reset. The sender spends each one from the edge after it arrived.
Example 2
A Beat with No Credit- Input
Link: The sender ignores its credits Scenarios: A steady stream into a fast consumer; A burst into a slow consumer; Bursts with gaps; A stalled consumer drains while the sender is idle
- Output
alarm = yes
Under a slow consumer the sender keeps offering beats after its four credits are spent.
Example 3
A Credit Spent Too Early- Input
Link: A credit is spent in the cycle it arrives Scenarios: A steady stream into a fast consumer; A burst into a slow consumer; Bursts with gaps; A stalled consumer drains while the sender is idle
- Output
alarm = yes
With no credits left, the sender offers a beat in the same cycle as the credit that pays for it. The count from earlier edges is 0 at that edge.
Constraints and Contract
- Every input is always 0 or 1. Use only your ports.
- errors never decreases; a reset edge leaves it as it is.
Hints
Hint 1
One integer is the whole model: the credits the sender holds after each edge.
Hint 2
At an edge, judge the beat against the count from before the edge, then add this edge's credit.
Hint 3
Reset clears the count. A link that starts the sender full is not the link in this problem.
What the grader checks: Your checker watches one correct and five faulty credited links over four traffic patterns. Passing shows that it catches these five faults and stays silent on a legal link.
6 checks on Icarus · browser samples / server checks. 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