A1.8.3 Count the Active Lanes

EasyImplementIcarus · browser samples / server checksReview the topic

Write two lane-count rules for a multi-lane link: a minimum count with $countones, and a driven-pad count with $countbits.

Hardware context: An eight-lane serial link whose unpowered lanes leave their pads floating. Count powered lanes as a number and count driven pads by their 0 and 1 bits.

An eight-lane link powers some lanes, shown by lane_en. A powered lane drives its pad bit to 0 or 1. An unpowered lane leaves its pad floating at z.

Write two immediate assertions, checked at each rising edge of clk while link_up is 1. Rule two_lanes: at least two lanes are powered.

Rule pads_match: the number of pads driven to 0 or 1 equals the number of powered lanes. Count each failure of each rule in its own counter.

Signals in the Timeline

SignalWidthRole
clk1stimulus, the same for every design
link_up1stimulus, the same for every design
lane_en8stimulus, the same for every design
pad8stimulus, the same for every design
your min_errors32stimulus, the same for every design
your pad_errors32stimulus, the same for every design
Full specification
The ports (keep them)
module lane_check (
  input  logic       clk,
  input  logic       link_up,     // 1 while the link is trained
  input  logic [7:0] lane_en,     // 1 = the lane is powered
  input  tri   [7:0] pad,         // a powered lane drives 0 or 1; an unpowered lane floats (z)
  output int         min_errors,  // trained edges with fewer than two powered lanes
  output int         pad_errors   // trained edges where the number of driven pads differs from the number of powered lanes
);
  // two_lanes: while link_up, at least two lanes are powered.
  // pads_match: while link_up, the number of pads driven to 0 or 1 equals the number of powered lanes.
endmodule
OutputGoes up when
min_errorsa trained edge sees fewer than two powered lanes
pad_errorsa trained edge sees a driven-pad count different from the powered-lane count

This problem runs on Icarus 12, which keeps z values. Its immediate assertions run at the rising edge, inside always @(posedge clk).

The program shown here trains with two lanes, then four. It has one bug of each kind: one lane at 35, and a powered lane whose pad floats at 45. At 55 two lanes drive 0: a driven 0 is still a driven pad.

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

Examples

Example 1

One Lane Is Too Few
Input
Program: 2, 4, 1, 4, 2 lanes
Output
min_errors = 1

Only the edge at 35 sees a single powered lane.

Example 2

A Powered Lane That Floats
Input
Program: 2, 4, 1, 4, 2 lanes
Output
pad_errors = 1

At 45 four lanes are powered and three pads are driven.

Example 3

A Driven 0 Is Still Driven
Input
Program: 2, 4, 1, 4, 2 lanes
Output
pad_errors = 0

At 55 two lanes are powered and both pads drive 0. Two driven pads match two lanes, so nothing fails after t=50.

Constraints and Contract

  • Use $countones for two_lanes and $countbits on pad for pads_match, each in an immediate assertion.
  • Check only while link_up is 1. Count failures in min_errors and pad_errors.
  • Do not change the ports.

Hints

Hint 1

Used alone as a condition, a count means "not zero". Is that "at least two"?

Hint 2

A driven pad holds 0 or 1. Which control bits pick exactly those?

Hint 3

A pad driven to 0 is still driven. Does counting only '1 work when a lane sends a 0?

What the grader checks: Two copies of your checker each watch a fixed program on Icarus 12. One is shown here; the other is hidden, with another clock and other lane counts. Graded on each: the two failure counts. The source must use $countones for two_lanes and $countbits on pad for pads_match.

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

One Lane Is Too Few

Input
Program: 2, 4, 1, 4, 2 lanes
Expected output
min_errors = 1

Only the edge at 35 sees a single powered lane.

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

Icarus · browser samples / server checks