A receive program gets nothing from UART0. It holds three faults, and each hides the next. Find and repair all three.
Hardware context: Four bring-up programs on a small processor model in front of ap_plic and the ap_clint timer, checked against the real ap_rv32. First firmware on a new chip or board
On a new board, steps 1 and 2 of the bring-up pass: the chip prints, and the timer ticks. Step 3 fails. The program below should take COUNT bytes from UART0 by interrupt and keep them in SRAM. It takes none.
The program holds three faults. Repair them. The structure of the program is right: every fault is in one or two rows.
Signals in the Timeline
| Signal | Width | Role |
|---|---|---|
trial | 8 | input of each check |
Full specification
| Item | Value |
|---|---|
| The count of bytes | the word at 0x8000_0000; it ends at COUNT |
| Byte number n, from 0 | the word at 0x8000_0040 + 4 times n |
| Interrupts taken | one for each byte |
| At the end | interrupts off, and a jump to itself |
| UART0 transmit | nothing is sent |
| Address | Name | What it does |
|---|---|---|
| 0x1000_000C | UART0 RXDATA | Read: the oldest received byte. The read removes it. |
| UART0 request | interrupt source 1 | It is 1 while a received byte waits. |
| 0x0C00_0000 + 4 times ID | ap_plic priority | 0 to 7. A source with priority 0 never competes. |
| 0x0C00_2000 | ap_plic enable | Bit number = ID. |
| 0x0C20_0000 | ap_plic threshold | The wire to the processor rises only for a priority above it. |
| 0x0C20_0004 | ap_plic claim and complete | Read: the ID of the winner; its pending bit clears. Write: that ID, when the handler is done. Until then the source cannot request again. |
| mie | bit 11 external, bit 7 timer, bit 3 software | The enable bits of the processor. |
| mstatus, bit 3 | MIE | The global enable. |
| Form | Meaning |
|---|---|
| i(LUI, a, 0, c) | x[a] = c shifted left by 12. c has at most 20 bits. |
| i(ADDI, a, b, c) | x[a] = x[b] + c. c is from -2048 to 2047. |
| i(LW, a, b, c) and i(SW, a, b, c) | load x[a] from, or store x[a] to, the address x[b] + c |
| i(BEQ, a, b, c), BNE, BLT, BGE | compare x[a] with x[b]; if true, go to address c |
| i(JAL, a, 0, c) and i(JALR, a, b, c) | x[a] = the address of the next row; go to c, or to x[b] + c |
| i(CSRR, a, 0, name), i(CSRW, a, 0, name) | read a CSR into x[a]; write x[a] to a CSR |
| i(CSRS, a, 0, name), i(CSRC, a, 0, name) | set, or clear, the bits of a CSR that are 1 in x[a] |
| i(MRET, 0, 0, 0) | return from a handler |
| at(address) | the rows that follow start at this address |
Examples
Example 1
Four Bytes, Far Apart- Input
COUNT = 4; the bytes 0x41 at tick 300, 0x42 at tick 500, 0x43 at tick 700, 0x44 at tick 900
- Output
program_stops = 1, no_exception = 1, count = 1, buffer = 1, one_interrupt_per_byte = 1, nothing_else_written = 1
Four bytes arrive 200 ticks apart. Each causes one interrupt.
Example 2
Six Bytes, Far Apart- Input
COUNT = 6; the bytes 0x41 at tick 300, 0x42 at tick 500, 0x43 at tick 700, 0x44 at tick 900, 0x45 at tick 1100, 0x46 at tick 1300
- Output
program_stops = 1, no_exception = 1, count = 1, buffer = 1, one_interrupt_per_byte = 1, nothing_else_written = 1
With COUNT at 6 the program waits for six bytes.
Example 3
Bytes in Pairs- Input
COUNT = 4; the bytes 0x61 at tick 300, 0x01 at tick 304, 0x00 at tick 800, 0x7f at tick 803
- Output
program_stops = 1, no_exception = 1, count = 1, buffer = 1, one_interrupt_per_byte = 1, nothing_else_written = 1
Two bytes arrive four ticks apart: the second waits while the handler serves the first.
Constraints and Contract
- Keep module my_receive, its parameter and the declarations below the task. Change only the rows of the_program.
- Use COUNT. The bench builds the module twice, with different values. At most 128 rows.
Hints
Hint 1
Walk the path of a request: device, pending bit, priority, enable, threshold, the wire, mie, mstatus. The first break stops everything.
Hint 2
After the first repair, expect the same symptom. Go on along the path.
Hint 3
When one byte arrives and no more, look at what ends the handler.
What the grader checks: Each trial sends COUNT bytes at planned ticks and runs the model until the program stops. It checks the count, every buffer word, the number of interrupts and the word after the buffer. Plans include bytes four ticks apart, the values 0 and 1, and values drawn for each submission.
9 checks on Icarus Verilog · server. Run the examples first, then check the full regression. Full checks use the server judge. Downloads contain your source only; samples require the simulation service. A passing result establishes the tested cases, not a proof for all possible inputs.
See all 2 problems on this path