A DMA test passes on its own. In a regression where the bench restarts the core in the middle of the copy, it fails with an empty destination word. Find the first transfer that broke what the test assumed, and say why.
The test copies 2,048 bytes of SRAM with the DMA and sleeps until the DMA's interrupt. It fills the source only on a cold boot, because SRAM keeps its words through a warm reset. On every boot it clears the destination first.
#include "hal.h"
#include "tb.h"
#include "irq.h"
#include "drivers/dma.h"
#define LEN 2048u
static volatile unsigned *const src = (volatile unsigned *)0x80004000u;
static volatile unsigned *const dst = (volatile unsigned *)0x80008000u;
static volatile unsigned done;
static void on_dma(void) { dma_ack(dma_status()); done = 1; }
int main(void)
{
tb_puts("boot, cause "); tb_put_hex(reg_read32(SYSCTL_RESET_CAUSE)); tb_putc('\n');
unsigned cause = reg_read32(SYSCTL_RESET_CAUSE);
if (cause == SYSCTL_RESET_CAUSE_POWER_ON_MASK) /* SRAM keeps the source through a warm reset */
for (unsigned i = 0; i < LEN / 4; i++) src[i] = 0xa5000000u | (i << 12) | i;
for (unsigned i = 0; i < LEN / 4; i++) dst[i] = 0; /* a clean destination */
irq_enable(DMA_IRQ, on_dma);
dma_start_copy(0x80004000u, 0x80008000u, LEN, DMA_IRQ_ENABLE_DONE_MASK);
tb_event(0x922); /* the copy runs */
while (!done) __asm__ volatile ("wfi"); /* sleep until the DMA's interrupt */
for (unsigned i = 0; i < LEN / 4; i++)
if (dst[i] != src[i]) {
tb_puts("dst word "); tb_put_hex(i); tb_puts(" = "); tb_put_hex(dst[i]); tb_putc('\n');
return 1;
}
tb_puts("copy ok\n");
return 0;
}
In this run the bench raised a debug reset 200 cycles after the test's event 0x922, while the first copy ran. A debug reset is one of the chip's five sources (V9.1). On v1.5 only the bench can raise it: the chip ties the debug module's request low. The test then ran again from the top and failed with code 1.
The reference model ran beside the chip for the whole run and reported no mismatch. The core executed the program as written.
dma_start_copy is the kit's: it reads STATUS, returns 0 if BUSY is set, and otherwise writes the registers and START. The full specification holds the driver.
The trace shows 12 of 1803 retired loads and stores, cycles 9374 to 22753. Name the first transfer whose data broke an assumption of the test. Give its cycle, the wrong part, its address and its register or variable. Then choose the cause.
Full specification
int dma_start_copy(unsigned src, unsigned dst, unsigned bytes, unsigned irq_enable)
{
if (dma_status() & DMA_STATUS_BUSY_MASK) return 0;
dma_ack(DMA_STATUS_DONE_MASK | DMA_STATUS_FAULT_MASK);
reg_write32(DMA_SRC, src);
reg_write32(DMA_DST, dst);
reg_write32(DMA_LEN, bytes);
reg_write32(DMA_IRQ_ENABLE, irq_enable & (DMA_IRQ_ENABLE_DONE_MASK | DMA_IRQ_ENABLE_FAULT_MASK));
reg_write32(DMA_START, DMA_START_START_MASK);
return 1;
}
The register list names every address the answer may use. Addresses in the trace are hex without 0x; write them with or without 0x in the form.
A load's data is what came back; a store's is what was written. A byte store shows its byte in the low eight bits.
Diagnose the Failing Run
Recorded Console and Result
CONSOLE 478: boot, cause 00000001 EVENT 8772: 00000922 CONSOLE 9923: boot, cause 00000011 EVENT 17247: 00000922 CONSOLE 22723: dst word 00000000 = 00000000 verdict=fail reason=status_fail status=bad00001 cycles=22761 traps=1 interrupts=1 mismatches=0 checker_errors=0 reset_debug=1 dma_bytes=2048 spi_frames=0
Retired Memory Transfers
| Cycle | PC (hex) | Operation | Address (hex) | Data (hex) |
|---|---|---|---|---|
| 9374 | 8000007c | store | 10004020 | 00000002 |
| 9698 | 80000340 | load | 10004004 | 00000011 |
| 9956 | 80000398 | store | 80008000 | 00000000 |
| 17108 | 80000398 | store | 800087fc | 00000000 |
| 17173 | 80000180 | store | 0c002000 | 00000020 |
| 17216 | 80000490 | load | 10006014 | 00000001 |
| 17248 | 800002f4 | store | 10004028 | 00000922 |
| 22231 | 80000474 | load | 10006014 | 00000002 |
| 22241 | 80000484 | store | 10006014 | 00000002 |
| 22326 | 800003f4 | load | 80008000 | 00000000 |
| 22328 | 800003f8 | load | 80004000 | a5000000 |
| 22753 | 80000284 | store | 10004020 | bad00001 |
Given Files
Use the register map to identify the transfer in the recording.
tb.h
#ifndef AP_TB_H
#define AP_TB_H
_Noreturn void tb_pass(void);
_Noreturn void tb_fail(unsigned code);
void tb_putc(char byte);
void tb_puts(const char *text);
void tb_put_hex(unsigned value);
void tb_event(unsigned id);
/* Slot zero is the single bench-to-firmware argument word. */
unsigned tb_arg(unsigned n);
void tb_wait_event(unsigned id);
#endif
irq.h
#ifndef AP_IRQ_H
#define AP_IRQ_H
typedef void (*irq_handler)(void);
unsigned plic_claim(void);
void plic_complete(unsigned id);
void irq_enable(unsigned id, irq_handler handler);
unsigned long long mtime_read(void);
void mtime_set_compare(unsigned long long deadline);
void msip_enable(irq_handler handler);
void mtime_enable(irq_handler handler);
#endif
drivers/dma.h
#ifndef AP_DMA_H
#define AP_DMA_H
#include "hal.h"
/* Addresses are chip byte addresses in either the CPU or the bus-manager seat.
* Start returns zero if a transfer already owns the engine. */
int dma_start_copy(unsigned src, unsigned dst, unsigned bytes, unsigned irq_enable);
unsigned dma_status(void);
unsigned dma_wait(void);
void dma_ack(unsigned status);
#endif
DMA · register manual
| Offset | Register | Bits | Field | Access | Reset | Held by | Meaning |
|---|---|---|---|---|---|---|---|
0x000 | SRC | 31:0 | address | rw | 0x00000000 | regs | The address of the first byte to read. Byte address. |
0x004 | DST | 31:0 | address | rw | 0x00000000 | regs | The address of the first byte to write. Byte address. |
0x008 | LEN | 31:0 | bytes | rw | 0x00000000 | regs | The number of bytes. Byte count. |
0x00C | START | 0 | start | wo | not stored | Bit 0 = 1 starts the job. Software writes it last. 1 starts the job. | |
0x014 | STATUS | 0 | busy | ro | block | Job state (new in v1.5). A job is running. | |
0x014 | STATUS | 1 | done | w1c | block | The last write of a job has finished. | |
0x014 | STATUS | 2 | fault | w1c | block | A bus error stopped the job. | |
0x018 | IRQ_ENABLE | 0 | done | rw | 0x0 | regs | Which status bits raise interrupt source 5 (new in v1.5). DONE raises the request. |
0x018 | IRQ_ENABLE | 1 | fault | rw | 0x0 | regs | FAULT raises the request. |
## DMA (base 0x1000_6000, interrupt source 5, clk_sys, PD_MAIN) | Offset | Register | Bits | Field | Access | Reset | Held by | Meaning | | --- | --- | --- | --- | --- | --- | --- | --- | | `0x000` | SRC | 31:0 | address | rw | `0x00000000` | regs | The address of the first byte to read. Byte address. | | `0x004` | DST | 31:0 | address | rw | `0x00000000` | regs | The address of the first byte to write. Byte address. | | `0x008` | LEN | 31:0 | bytes | rw | `0x00000000` | regs | The number of bytes. Byte count. | | `0x00C` | START | 0 | start | wo | | not stored | Bit 0 = 1 starts the job. Software writes it last. 1 starts the job. | | `0x014` | STATUS | 0 | busy | ro | | block | Job state (new in v1.5). A job is running. | | `0x014` | STATUS | 1 | done | w1c | | block | The last write of a job has finished. | | `0x014` | STATUS | 2 | fault | w1c | | block | A bus error stopped the job. | | `0x018` | IRQ_ENABLE | 0 | done | rw | `0x0` | regs | Which status bits raise interrupt source 5 (new in v1.5). DONE raises the request. | | `0x018` | IRQ_ENABLE | 1 | fault | rw | `0x0` | regs | FAULT raises the request. |
ap_sysctl · register manual
| Offset | Register | Bits | Field | Access | Reset | Held by | Meaning |
|---|---|---|---|---|---|---|---|
0x000 | CHIP_ID | 31:0 | value | ro | 0x2A5310C5 | const | The chip's identity: the IDCODE of the TAP. Fixed number. |
0x004 | RESET_CAUSE | 0 | power_on | ro | block | Sticky record of reset sources since power-on. Power-on reset. | |
0x004 | RESET_CAUSE | 1 | pin | ro | block | Reset pin. | |
0x004 | RESET_CAUSE | 2 | watchdog | ro | block | Watchdog. | |
0x004 | RESET_CAUSE | 3 | software | ro | block | Software request. | |
0x004 | RESET_CAUSE | 4 | debug | ro | block | Debug request. | |
0x008 | SOFT_RESET | 0 | timer | wo | not stored | Reset requests from software. 1 arms one restart of the timer. | |
0x008 | SOFT_RESET | 1 | chip | wo | not stored | 1 requests the software reset (new in v1.5). | |
0x00C | STRAPS | 0 | boot | ro | block | Straps as sampled at power-up (new in v1.5). 0: start in the boot ROM. 1: start in SRAM. | |
0x010 | PINMUX | 31:0 | select | rw | 0x00000000 | regs | Two bits for each of sixteen pads: 0 released, 1 GPIO, 2 serial, 3 auxiliary. Pad n uses bits 2n+1 and 2n. |
0x014 | CLK_GATE | 0 | uart0 | rw | 0x1 | regs | 1 lets that block's clock run (new in v1.5). UART0. |
0x014 | CLK_GATE | 1 | gpio | rw | 0x1 | regs | GPIO. |
0x014 | CLK_GATE | 2 | timer | rw | 0x1 | regs | Timer and PWM. |
0x014 | CLK_GATE | 3 | spi | rw | 0x1 | regs | SPI. |
0x014 | CLK_GATE | 4 | dma | rw | 0x1 | regs | DMA. |
0x018 | LOCK | 0 | pinmux | w1s | 0x0 | regs | Write-once locks. Only a reset clears one (new in v1.5). 1: PINMUX ignores writes. |
0x018 | LOCK | 1 | clk_gate | w1s | 0x0 | regs | 1: CLK_GATE ignores writes. |
0x018 | LOCK | 2 | debug | w1s | 0x0 | regs | 1: the debug lock is closed. |
0x020 | TB_STATUS | 31:0 | value | rw | 0x00000000 | regs (power-on reset only) | Scratch word 0. The firmware kit reports progress, pass and fail here. Plain storage. |
0x024 | TB_PUTC | 31:0 | value | rw | 0x00000000 | regs (power-on reset only) | Scratch word 1. The firmware kit writes one character here. Plain storage. |
0x028 | TB_EVENT | 31:0 | value | rw | 0x00000000 | regs (power-on reset only) | Scratch word 2. The firmware kit writes an event number here. Plain storage. |
0x02C | TB_ARG | 31:0 | value | rw | 0x00000000 | regs (power-on reset only) | Scratch word 3. A bench leaves a word for the firmware here. Plain storage. |
## ap_sysctl (base 0x1000_4000, clk_sys, PD_MAIN) | Offset | Register | Bits | Field | Access | Reset | Held by | Meaning | | --- | --- | --- | --- | --- | --- | --- | --- | | `0x000` | CHIP_ID | 31:0 | value | ro | `0x2A5310C5` | const | The chip's identity: the IDCODE of the TAP. Fixed number. | | `0x004` | RESET_CAUSE | 0 | power_on | ro | | block | Sticky record of reset sources since power-on. Power-on reset. | | `0x004` | RESET_CAUSE | 1 | pin | ro | | block | Reset pin. | | `0x004` | RESET_CAUSE | 2 | watchdog | ro | | block | Watchdog. | | `0x004` | RESET_CAUSE | 3 | software | ro | | block | Software request. | | `0x004` | RESET_CAUSE | 4 | debug | ro | | block | Debug request. | | `0x008` | SOFT_RESET | 0 | timer | wo | | not stored | Reset requests from software. 1 arms one restart of the timer. | | `0x008` | SOFT_RESET | 1 | chip | wo | | not stored | 1 requests the software reset (new in v1.5). | | `0x00C` | STRAPS | 0 | boot | ro | | block | Straps as sampled at power-up (new in v1.5). 0: start in the boot ROM. 1: start in SRAM. | | `0x010` | PINMUX | 31:0 | select | rw | `0x00000000` | regs | Two bits for each of sixteen pads: 0 released, 1 GPIO, 2 serial, 3 auxiliary. Pad n uses bits 2n+1 and 2n. | | `0x014` | CLK_GATE | 0 | uart0 | rw | `0x1` | regs | 1 lets that block's clock run (new in v1.5). UART0. | | `0x014` | CLK_GATE | 1 | gpio | rw | `0x1` | regs | GPIO. | | `0x014` | CLK_GATE | 2 | timer | rw | `0x1` | regs | Timer and PWM. | | `0x014` | CLK_GATE | 3 | spi | rw | `0x1` | regs | SPI. | | `0x014` | CLK_GATE | 4 | dma | rw | `0x1` | regs | DMA. | | `0x018` | LOCK | 0 | pinmux | w1s | `0x0` | regs | Write-once locks. Only a reset clears one (new in v1.5). 1: PINMUX ignores writes. | | `0x018` | LOCK | 1 | clk_gate | w1s | `0x0` | regs | 1: CLK_GATE ignores writes. | | `0x018` | LOCK | 2 | debug | w1s | `0x0` | regs | 1: the debug lock is closed. | | `0x020` | TB_STATUS | 31:0 | value | rw | `0x00000000` | regs (power-on reset only) | Scratch word 0. The firmware kit reports progress, pass and fail here. Plain storage. | | `0x024` | TB_PUTC | 31:0 | value | rw | `0x00000000` | regs (power-on reset only) | Scratch word 1. The firmware kit writes one character here. Plain storage. | | `0x028` | TB_EVENT | 31:0 | value | rw | `0x00000000` | regs (power-on reset only) | Scratch word 2. The firmware kit writes an event number here. Plain storage. | | `0x02C` | TB_ARG | 31:0 | value | rw | `0x00000000` | regs (power-on reset only) | Scratch word 3. A bench leaves a word for the firmware here. Plain storage. |