Write one firmware test that takes the chip through a pin, a software and a watchdog reset. It checks the cause register after each. It must pass on ap_soc and fail visibly on every faulty chip of a hidden set.
Hardware context: ap_soc v1.5's reset controller ap_crg with its five reset sources and the RESET_CAUSE record. A firmware chain through the pin, software and watchdog resets.
A chip can be reset from five places. The test of each source asks three questions. Did the reset happen? Did it reach what it should? Did the chip record why? This test walks one chip through three sources in a row and checks the record after each.
Start at power-on. Ask the board for a pin reset with TB_EVENT 2. After it, make a software reset with SOFT_RESET bit 1 (CHIP). After that, arm the watchdog and never kick it. After its reset, print causes and the cause word as eight hex digits, then pass.
After every boot, check RESET_CAUSE before anything else. Bits 3 to 0 must hold exactly the sources so far. The bench may add a debug reset (bit 4) before main; accept bit 4 and print it. If a reset does not come within a few thousand cycles, fail with your own code.
Keep the step in TB_ARG. It is a scratch register that only power-on clears, so it survives the warm resets. In one hidden case the supply fails in the middle of the chain; the whole chain must start again and still pass.
The test runs on the good chip and on each hidden faulty chip. A faulty chip is caught when your test writes a fail word, or a check of the bench fails. A chip that runs to the cycle limit is not caught.
Full specification
| Source | How to raise it | RESET_CAUSE bit | What it resets |
|---|---|---|---|
| Power-on | the supply (the bench) | 0, and it clears every other bit | everything, the scratch words included |
| Reset pin | TB_EVENT 2: the board pulls RST_N for 200 ns | 1 | core, bus and peripherals |
| Watchdog | KEY 0x51, KEY 0xA2, CONTROL 1, then no kick | 2 | core, bus and peripherals |
| Software | SOFT_RESET (0x1000_4008) bit 1 | 3 | core, bus and peripherals |
| Debug | the bench only: the chip ties the debug module's request low | 4 | the core only |
| Register | Address | Use |
|---|---|---|
| RESET_CAUSE | 0x1000_4004 | Sticky: a bit stays set until the next power-on, which sets the word to 0x01 |
| TB_ARG | 0x1000_402C | Scratch; cleared by power-on only. The bench writes nothing here in this problem |
| WATCHDOG KEY, CONTROL | 0x1000_3000, 0x1000_3004 | Write-only; a read answers ERROR |
mtime_read() from irq.h counts cycles of clk_sys and restarts with every reset of the bus. Write the step before you ask for a reset: once the reset comes, no instruction after the request runs.
Given Files
Read-only files supplied by the bench.
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
hal.h
#ifndef AP_HAL_H
#define AP_HAL_H
#include "ap_soc_regs.h"
/* V13.4 supplies these two functions through DPI in a host-native build. */
#ifdef AP_HOST_DPI
unsigned reg_read32(unsigned address);
void reg_write32(unsigned address, unsigned value);
#else
static inline unsigned reg_read32(unsigned address)
{
return *(volatile unsigned *)address;
}
static inline void reg_write32(unsigned address, unsigned value)
{
*(volatile unsigned *)address = value;
}
#endif
#define FIELD_GET(field, word) (((word) & field##_MASK) >> field##_SHIFT)
#define FIELD_PREP(field, value) (((unsigned)(value) << field##_SHIFT) & field##_MASK)
#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
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. |
Watchdog · register manual
| Offset | Register | Bits | Field | Access | Reset | Held by | Meaning |
|---|---|---|---|---|---|---|---|
0x000 | KEY | 31:0 | value | wo | not stored | 0x51, then 0xA2 on the next watchdog write, unlocks one write to CONTROL. Key word. | |
0x004 | CONTROL | 31:0 | value | wo | not stored | Write 1 while unlocked: armed. Arms once. 1 arms the watchdog. | |
0x008 | SERVICE | 31:0 | value | wo | not stored | Write 1: the kick. 1 is a kick. |
## Watchdog (base 0x1000_3000, interrupt source 6, clk_aon, PD_AON) | Offset | Register | Bits | Field | Access | Reset | Held by | Meaning | | --- | --- | --- | --- | --- | --- | --- | --- | | `0x000` | KEY | 31:0 | value | wo | | not stored | 0x51, then 0xA2 on the next watchdog write, unlocks one write to CONTROL. Key word. | | `0x004` | CONTROL | 31:0 | value | wo | | not stored | Write 1 while unlocked: armed. Arms once. 1 arms the watchdog. | | `0x008` | SERVICE | 31:0 | value | wo | | not stored | Write 1: the kick. 1 is a kick. |
Examples
Example 1
The Good Chip- Input
Power-on, then each source in turn
- Output
console "causes 0000000f"; pass
Four boots: power-on, then the pin, software and watchdog resets. The cause word grows 0x1, 0x3, 0xB, 0xF.
Example 2
A Debug Reset Before Main- Input
The bench adds a debug reset before main
- Output
console "causes 0000001f"; pass
The bench restarted the core before main. Bit 4 joins the record and stays, and bits 3 to 0 grow as before.
Example 3
A Chip That Records the Wrong Source- Input
a hidden chip
- Output
your fail word
The reset happens, but its bit is missing. Only a check of the cause word after that reset sees it.
Constraints and Contract
- C firmware with the kit, SRAM layout.
- Print exactly one line,
causesand the word, and only after the watchdog reset. - Every wait for a reset needs a limit and a fail code.
Hints
Hint 1
Why must the step live in a register, and not in a C variable? What does start-up code do to .bss?
Hint 2
Which bits of RESET_CAUSE are you sure of after each reset, and which one may the bench set?
Hint 3
What does your test do on a chip whose software reset never comes?
What the grader checks: Each case runs your firmware on the good chip and on every hidden faulty chip, with the same bench. The good chip must print the expected line and pass. Each faulty chip must end with a fail word or a bench check; the page never says which chip escaped. The bench's reset counters are shown, not graded.
4 checks on ap_soc v1.5 · firmware · server. Run the examples first, then check the full regression. Full checks use the server judge. Downloads contain your text only; the chip, the bench and the hidden checks stay on the server. A passing result establishes the tested cases, not a proof for all possible inputs.
See all 2 problems on this path