Write the half of a bench's UART model that listens to the chip's transmit pad. Find each start bit, sample every bit in its middle, and keep the bytes whose stop bit is right.
Hardware context: The board's devices as models on the pads of ap_soc v1.5: UART, GPIO, SPI flash, JTAG. Writing the receiver of a UART model.
The chip's UART talks to the board through one pad. On the bench, the board is a model, and that model decides every byte. If it samples in the wrong place, a good chip fails; if it ignores a bad stop bit, a broken chip passes.
Write the receiver of uart_rx_model. A frame is a start bit (0), eight data bits low bit first, and a stop bit (1), each bit_ns long. Two of the cases replay frames the chip itself sent on its pad.
A bad stop bit leaves a choice. The chip's own receiver, ap_uart, drops the byte of such a frame. soc_tb's UART model keeps it and counts a frame error, so a test can see what the broken frame carried. This model follows ap_uart: drop the byte and count the frame error. Either way the error is counted, and that is what fails a run.
Signals in the Timeline
| Signal | Width | Role |
|---|---|---|
scenario | 4 | input of each check |
Full specification
| Time after the falling edge | The line | What the model does |
|---|---|---|
| bit_ns / 2 | the middle of the start bit | Still 0: a frame. Already 1: a glitch; count it and wait for the next falling edge. |
| (1.5 + i) × bit_ns, i = 0 to 7 | the middle of data bit i | Take bit i of the byte. |
| 9.5 × bit_ns | the middle of the stop bit | 1: keep the byte in got[got_n], add 1 to got_n. 0: drop it, add 1 to frame_errors. |
Then wait for the next falling edge: a frame may follow its stop bit at once. Read bit_ns at each falling edge; the bench may change it between cases. The board's clock and the chip's are never exactly equal. Sampling in the middle of each bit tolerates the difference.
Examples
Example 1
The Chip Sends O, K and a New Line (Recorded)- Input
bit_ns = 80; 2880 ns of the line
- Output
bytes = 3, frame_errors = 0, glitches = 0, byte0 = 0x4f, byte1 = 0x4b, byte2 = 0xa, byte3 = 0x0, byte4 = 0x0, byte5 = 0x0, byte6 = 0x0
The chip sent O, K and a new line at 8 cycles a bit, 80 ns. The model takes all three: 4F, 4B, 0A.
Example 2
The Chip at 13 Cycles a Bit (Recorded)- Input
bit_ns = 130; 2840 ns of the line
- Output
bytes = 2, frame_errors = 0, glitches = 0, byte0 = 0x41, byte1 = 0xc3, byte2 = 0x0, byte3 = 0x0, byte4 = 0x0, byte5 = 0x0, byte6 = 0x0
At 13 cycles a bit the same rules read 41 and C3: the bit time comes from bit_ns, read at each start.
Example 3
Three Frames with No Idle Bit Between Them- Input
bit_ns = 50; 1750 ns of the line
- Output
bytes = 3, frame_errors = 0, glitches = 0, byte0 = 0x55, byte1 = 0x0, byte2 = 0xff, byte3 = 0x0, byte4 = 0x0, byte5 = 0x0, byte6 = 0x0
With no idle bit between them, each start bit begins right where the stop bit ends. A model that pauses after a frame misses the next one.
Constraints and Contract
- Keep the module name, the ports, got, got_n, frame_errors and glitches.
- Between cases the bench sets the counters to 0 with the line idle. At most seven bytes arrive in a case.
Hints
Hint 1
One process: wait for the falling edge, then step through the frame with delays.
Hint 2
Wait half a bit first, then one whole bit at a time.
Hint 3
The middle matters when the two clocks differ by a few percent.
What the grader checks: Nine scripts of the line, two recorded from ap_soc v1.5's UART TX pad by an Icarus probe, seven made in the bench. Each case reports the bytes kept, the frame errors, the glitches and the first seven bytes. The bench does not test more than seven bytes in a case.
9 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 problems on this path