Fix a DMA channel that takes a stale response from its previous transfer as its own.
Hardware context: Memory-to-memory DMA with owned descriptors and bounded bus bursts. Verify independent DMA channels under stalls, interrupts and cancellation.
Two DMA channels passed every short test. In a longer test, a late response from a channel's first transfer arrived during its second one. The channel took it as its own.
The module dma_channel copies bytes one at a time. For each byte it offers a read request and waits for the response. Then it offers a write request and waits for the acknowledgment. Every request carries the epoch, a number that grows on each start. Each response carries back the epoch of its request as a tag.
The tests run two channels side by side for 256 clock edges, each with its own memory port. The ports take requests on different edges and answer after 1 to 3 edges. The tests add write errors, resets during a transfer and stale responses with an old tag. abort_transfer stays 0.
After every edge, the status of both channels is recorded. The whole record and the final memory are compared. Find the bug and fix it.
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
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
| 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_transfer stays 0 in this problem, so aborts are never tested here.
| 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. |
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 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
Two Clean Transfers- Input
lengths 4 and 5, responses after 2 edges, no errors, no stale responses
- Output
report_length = 5892, expected_length = 5892, match = yes
Each channel counts a byte only when its write is acknowledged. Channel 0 pulses done after edge 24 with 4 bytes, and channel 1 after edge 49 with 5. The second transfers, in epoch 2, end after edges 147 and 144.
Example 2
Write Errors- Input
lengths 5 and 4, responses after 3 edges, write 2 of channel 0 and write 0 of channel 1 fail
- Output
report_length = 5892, expected_length = 5892, match = yes
Channel 1 ends with error = 1 after edge 10, with 0 bytes. Channel 0 ends after edge 26 with 2 bytes: bytes 64 and 65 are written, 66 is not. Both second transfers then run normally.
Example 3
Stale Responses- Input
lengths 5 and 3, responses after 1 edge, write 1 of channel 0 fails, stale tag-1 responses
- Output
report_length = 5892, expected_length = 5892, match = yes
In epoch 2, a response with tag 1 and junk data comes before each real one. The channel must ignore it. Both second transfers end with the right counts, and no junk byte reaches memory.
Example 4
Reset in the Middle- Input
lengths 6 and 5, responses after 1 edge, reset on edge 6
- Output
report_length = 5892, expected_length = 5892, match = yes
Each channel has written one byte when reset comes. Reset clears the status and epoch to 0 with no done pulse. The written bytes stay. The second transfers then run in epoch 1.
Example 5
Zero-Length Transfers- Input
lengths 0 and 0, responses after 2 edges
- Output
report_length = 5892, expected_length = 5892, match = yes
Both channels pulse done after edge 0 without going busy. The second transfers then copy their bytes normally.
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 module name and the ports.
Hints
Hint 1
A response belongs to the request that carried the same tag. How does the channel know a response is its own?
Hint 2
In the third example, a response with tag 1 comes one edge early during the second transfer. The channel's epoch is then 2. What should it do with that response?
Hint 3
Look at the two states that wait for a response, states 2 and 4. Both take any response_valid. Also require response_tag == epoch.
What the grader checks: Two real channels run against independent memory ports for 256 edges. An independent model checks every status entry and every memory byte. Passing covers these stalls, errors, resets and stale responses, not every bus.
14 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 8 steps and the final capstone