V9.1.1 A Test for Every Reset Source

HardVerify35 minap_soc v1.5 · firmware · serverReview the topic

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
SourceHow to raise itRESET_CAUSE bitWhat it resets
Power-onthe supply (the bench)0, and it clears every other biteverything, the scratch words included
Reset pinTB_EVENT 2: the board pulls RST_N for 200 ns1core, bus and peripherals
WatchdogKEY 0x51, KEY 0xA2, CONTROL 1, then no kick2core, bus and peripherals
SoftwareSOFT_RESET (0x1000_4008) bit 13core, bus and peripherals
Debugthe bench only: the chip ties the debug module's request low4the core only
RegisterAddressUse
RESET_CAUSE0x1000_4004Sticky: a bit stays set until the next power-on, which sets the word to 0x01
TB_ARG0x1000_402CScratch; cleared by power-on only. The bench writes nothing here in this problem
WATCHDOG KEY, CONTROL0x1000_3000, 0x1000_3004Write-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
OffsetRegisterBitsFieldAccessResetHeld byMeaning
0x000CHIP_ID31:0valuero0x2A5310C5constThe chip's identity: the IDCODE of the TAP. Fixed number.
0x004RESET_CAUSE0power_onroblockSticky record of reset sources since power-on. Power-on reset.
0x004RESET_CAUSE1pinroblockReset pin.
0x004RESET_CAUSE2watchdogroblockWatchdog.
0x004RESET_CAUSE3softwareroblockSoftware request.
0x004RESET_CAUSE4debugroblockDebug request.
0x008SOFT_RESET0timerwonot storedReset requests from software. 1 arms one restart of the timer.
0x008SOFT_RESET1chipwonot stored1 requests the software reset (new in v1.5).
0x00CSTRAPS0bootroblockStraps as sampled at power-up (new in v1.5). 0: start in the boot ROM. 1: start in SRAM.
0x010PINMUX31:0selectrw0x00000000regsTwo bits for each of sixteen pads: 0 released, 1 GPIO, 2 serial, 3 auxiliary. Pad n uses bits 2n+1 and 2n.
0x014CLK_GATE0uart0rw0x1regs1 lets that block's clock run (new in v1.5). UART0.
0x014CLK_GATE1gpiorw0x1regsGPIO.
0x014CLK_GATE2timerrw0x1regsTimer and PWM.
0x014CLK_GATE3spirw0x1regsSPI.
0x014CLK_GATE4dmarw0x1regsDMA.
0x018LOCK0pinmuxw1s0x0regsWrite-once locks. Only a reset clears one (new in v1.5). 1: PINMUX ignores writes.
0x018LOCK1clk_gatew1s0x0regs1: CLK_GATE ignores writes.
0x018LOCK2debugw1s0x0regs1: the debug lock is closed.
0x020TB_STATUS31:0valuerw0x00000000regs (power-on reset only)Scratch word 0. The firmware kit reports progress, pass and fail here. Plain storage.
0x024TB_PUTC31:0valuerw0x00000000regs (power-on reset only)Scratch word 1. The firmware kit writes one character here. Plain storage.
0x028TB_EVENT31:0valuerw0x00000000regs (power-on reset only)Scratch word 2. The firmware kit writes an event number here. Plain storage.
0x02CTB_ARG31:0valuerw0x00000000regs (power-on reset only)Scratch word 3. A bench leaves a word for the firmware here. Plain storage.
Watchdog · register manual
OffsetRegisterBitsFieldAccessResetHeld byMeaning
0x000KEY31:0valuewonot stored0x51, then 0xA2 on the next watchdog write, unlocks one write to CONTROL. Key word.
0x004CONTROL31:0valuewonot storedWrite 1 while unlocked: armed. Arms once. 1 arms the watchdog.
0x008SERVICE31:0valuewonot storedWrite 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, causes and 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

Report a problem with this page

Your code CSaved locally
Ln 1, Col 1Tab indents · Ctrl/⌘ + Enter runs samples
Not run yet

The Good Chip

Input
Power-on, then each source in turn
Expected output
console "causes 0000000f"; pass

Four boots: power-on, then the pin, software and watchdog resets. The cause word grows 0x1, 0x3, 0xB, 0xF.

Run samples executes all 2 public checks. Check all tests runs 4 checks on the server.

ap_soc v1.5 · firmware · server