Find and fix one bug in a descriptor model and one in a clocked DMA channel, checked together.
Hardware context: Memory-to-memory DMA with owned descriptors and bounded bus bursts. Qualify the DMA subsystem against descriptor, data-path and outstanding-traffic reset faults.
A DMA subsystem has two parts. A descriptor model decides which copies a chain asks for. Two hardware channels move the bytes. In the full regression, a chain ran on through an empty slot, and channels reported too many bytes after a write error.
You submit both parts: the function descriptor_walk and the module dma_channel. Their full rules are in the specification.
Each test runs one chain through descriptor_walk, then runs two channels for 256 edges. The two reports are joined with | and compared in full. The tests cover valid chains, loops, bad pointers, write errors, aborts, resets and stale responses.
Each part has exactly one bug. Find both and fix them.
Signals in the Timeline
| Signal | Width | Role |
|---|---|---|
response_latency | 2 | input of each check |
stale_response | 1 | input of each check |
first_length | 3 | input of each check |
Full specification
function automatic string descriptor_walk(input logic [511:0] descriptors, input int start_index);
module dma_channel(
input logic clk, reset, start, abort_transfer,
input logic [6:0] source_address, destination,
input logic [7:0] length,
input logic bus_ready, response_valid, response_error,
input logic [7:0] response_data, response_tag,
output wire bus_valid, bus_write,
output wire [6:0] bus_address,
output wire [7:0] bus_data, bus_tag,
output logic busy, done, error, canceled,
output logic [7:0] bytes_done, epoch);
// your channel
endmodule
The descriptor walk:
| Bits of a slot | Holds |
|---|---|
| 7:0 | Source byte address. |
| 15:8 | Destination byte address. |
| 23:16 | Length in bytes. |
| 31:24 | Next slot. 255 ends the chain. |
| 32 | Valid bit. |
| 63:33 | Always 0. |
| Error | Checked in this order for the current slot |
|---|---|
| 1, pointer | The slot number is not 0 to 7. |
| 2, loop | This slot already ran in this walk. |
| 3, invalid | The valid bit is 0. |
| 4, bounds | The length is above 32, or source + length or destination + length is above 128. |
| 5, overlap | The length is above 0 and the two ranges overlap. |
Slot k sits in bits 64k + 63 down to 64k of descriptors. Memory has 128 bytes.
The walk stops at the first failed check. A failed slot copies nothing. Copies made before it stay made.
A slot that passes copies its bytes in address order, then the walk moves to its next slot. A later slot may read bytes that an earlier slot wrote.
After eight slots have run, the walk stops. If the next slot is not 255, it reports error 1 for a number outside 0 to 7 and error 2 otherwise.
Memory byte a starts as (17 × a + 0x5a) mod 256. So byte 0 is 0x5a, byte 1 is 0x6b and byte 64 is 0x9a.
Each slot that runs adds slot:source>destination/length; in decimal, for example 0:0>64/4;. Then comes E=error|NODE=slot|DONE=count|BYTES=total|MEM=. After it come all 128 bytes as two hex digits each, address 0 first. NODE is the slot where the walk stopped, or 255 after a clean end.
The channel:
| Channel rule | Meaning |
|---|---|
| Start | Taken when start = 1, busy = 0 and abort_transfer = 0. Capture the three inputs, add 1 to epoch and clear error, canceled and bytes_done. Length 0 pulses done and stays idle. Otherwise busy = 1 and a read request starts. |
| Requests | bus_valid = 1 while a request is offered, and bus_write = 1 for a write. bus_address is the source for a read and the destination for a write. bus_data is the byte read, or 0 for a read. bus_tag = epoch. |
| Hold | A request stays offered, unchanged, until an edge with bus_ready = 1 takes it. |
| Responses | After a request is taken, wait for response_valid = 1 with response_tag = epoch. Ignore a response with any other tag. |
| Read response | An error ends the transfer with error = 1. Otherwise keep response_data and offer the write. |
| Write response | An error ends the transfer with error = 1, and the byte is not counted. Otherwise add 1 to bytes_done. After the last byte, end the transfer. Otherwise move both addresses on by 1 and read again. |
| End | done = 1 for one edge and busy = 0. error, canceled and bytes_done keep their values until the next start. |
| Reset | Synchronous and active high. Clears every register, epoch included, to 0. It gives no done pulse. |
| Abort rule | Meaning |
|---|---|
| Remember | A pulse on abort_transfer while busy is remembered until the transfer ends. |
| Drain | A request already offered stays offered until taken. Its response is still awaited. |
| Read response | After an abort, a read response with no error ends the transfer with canceled = 1. No write is offered. |
| Write response | After an abort, a write response with no error still counts its byte. Then the transfer ends with canceled = 1, even if that was the last byte. |
| Same edge | An abort on the same edge as a matching response counts too. |
| Errors | A response with an error ends the transfer with error = 1 and canceled = 0. |
| Test bench | What it does |
|---|---|
| Setup | Two channels run side by side, each with its own memory port. One reset edge comes before edge 0. Edges are counted from 0. |
| Memory | 128 bytes shared by both ports. Memory byte a starts as (17 × a + 0x5a) mod 256. |
| Ready | Channel 0's port is ready on edges whose number is not a multiple of 3. Channel 1's port is ready when the edge number mod 5 is 2 or more. A port is never ready while its response is pending, or during reset. |
| Memory effect | A write changes memory on the edge that takes it. A read returns the byte at that moment. |
| Latency | The response comes 1, 2 or 3 edges after the edge that took the request. The value is fixed for each test. |
| Transfers | Edge 0 starts channel 0 copying from 0 to 64 and channel 1 from 8 to 88, with lengths from the test. Edge 128 starts channel 0 copying 3 bytes from 16 to 80, and channel 1 copying 2 bytes from 24 to 104. |
| Failing write | In some tests, write number k of the first transfer, counting from 0, returns an error and changes nothing. |
| Stale response | Some tests add fake responses while a channel's epoch is 2. Each has tag 1 and junk data that changes from edge to edge, and comes one edge before a real response. |
| Reset | In some tests, reset is high for one edge during the first transfer. It drops pending responses but keeps memory. |
| Abort | In some tests, abort_transfer is high for one edge on each channel during the first transfer. |
After each edge, each channel adds one entry, channel 0 first. An entry starts with four bits: busy, done, error and canceled. Then come a colon, bytes_done in two hex digits, a colon, epoch in two hex digits and a semicolon. For example, 1000:02:01; is busy with 2 bytes done in epoch 1. After 256 edges, MEM: and all 128 bytes follow as two hex digits each.
The expected result is the walk report, then |, then the channel record. The walk and the channels start from separate copies of memory.
The whole report string is compared with the expected one. The result shows the length of your report, the expected length and whether the two match.
Examples
Example 1
Everything Clean- Input
Walk: slot 0 copies 4 bytes from 0 to 64, then slot 1 copies them on to 80. Channels: lengths 4 and 5, responses after 2 edges.
- Output
report_length = 6200, expected_length = 6200, match = yes
The walk ends cleanly with E=0|NODE=255|DONE=2|BYTES=8. Each channel finishes both transfers: 4 and 5 bytes first, then 3 and 2.
Example 2
A Loop and Two Write Errors- Input
Walk: slot 0 copies 4 bytes from 0 to 64 and points to itself. Channels: lengths 5 and 4, responses after 3 edges, write 2 of channel 0 and write 0 of channel 1 fail.
- Output
report_length = 6188, expected_length = 6188, match = yes
The walk stops with error 2 after one copy. Channel 0 ends with error = 1 and 2 bytes, and channel 1 with error = 1 and 0 bytes.
Example 3
A Bad Copy and Two Aborts- Input
Walk: slot 0 copies 16 bytes from 120. Channels: lengths 6 and 5, responses after 3 edges, aborts on edges 13 and 27, stale responses.
- Output
report_length = 6179, expected_length = 6179, match = yes
The walk stops with error 4 and writes nothing. The aborts end the first transfers canceled, with 1 and 3 bytes.
Example 4
An Empty Chain and One Write Error- Input
Walk: start_index 255. Channels: lengths 5 and 3, responses after 1 edge, write 1 of channel 0 fails, stale responses.
- Output
report_length = 6181, expected_length = 6181, match = yes
The walk has nothing to do, so it reports E=0|NODE=255|DONE=0|BYTES=0. Channel 0's second write fails, so it ends with error = 1 and bytes_done = 1.
Example 5
An Empty Slot and a Late Abort- Input
Walk: slot 0 copies 4 bytes from 0 to 64 and points to slot 7, which is all zeros. Channels: lengths 5 and 3, responses after 1 edge, aborts on edges 27 and 30.
- Output
report_length = 6188, expected_length = 6188, match = yes
Slot 7 has its valid bit clear, so the walk stops with error 3 after one copy. Channel 0 is aborted during its last write. It ends with 5 bytes but canceled = 1.
Constraints and Contract
- Each channel has at most one request waiting for a response.
- The source and destination ranges of one transfer never overlap. The two channels write different bytes.
- Keep the function name, the module name and all ports.
Hints
Hint 1
Debug the two parts apart. Split the report at the | after the walk's memory dump. The left side is the walk and the right side is the channels.
Hint 2
For the walk, trace a chain that points to an empty slot. For the channels, trace a test with a write error and watch bytes_done.
Hint 3
In descriptor_walk, the valid-bit check is missing: stop with error 3 when bit 32 is 0. In dma_channel, the write-error branch of state 4 adds 1 to bytes_done. A failed write must not count.
What the grader checks: Each test checks a descriptor chain and two real channels for 256 edges against independent models. The tests cover every walk error and the channel stalls, errors, aborts, resets and stale responses. The walk is a model; no hardware fetches the descriptors.
55 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 8 steps and the final capstone