V8.3.1 Every Function on Every Pad

HardVerify40 minap_soc v1.5 · firmware · serverReview the topic

Write firmware that takes each pad function of ap_soc through the pin mux and proves it reaches its pad. It must pass on the good chip and fail on every faulty chip of a hidden set.

Hardware context: The pin mux of ap_soc v1.5: PINMUX, pins.csv and the board's UART and flash models. Every pad function from firmware.

The pin table below is the specification. Each row is one function on one pad, chosen by two bits of PINMUX. Write C firmware that selects each function in turn and shows it works at the pad.

Cover UART TX on IO0 and UART RX on IO1, and the SPI flash on IO2 to IO5. Cover PWM on IO0 and IO2, and the timer's event input on IO4. Cover the wake detector on IO15, which listens whatever PINMUX says. GPIO on every pad is the module's toggle test. Capture (select 3 on IO1 and IO3) is left out. The timer keeps only the slot number at which a capture fired. A check would need a timed pulse against a running counter. Its wiring, with the OR of the two pads, is a job for the proof of the pad rows.

The bench's side is fixed. After your TB_EVENT 0x831 it expects the byte 0x83 on IO0, then sends 0x38 on IO1. The SPI flash answers C0 FF EE to the command 9F. TB_EVENT 0x0200_0014 makes the board pulse IO4, and TB_EVENT 1 pulses IO15.

GPIO IN reads every pad whatever PINMUX says. That is your loopback for an output function the board does not check. Print pins ok and pass if every check holds; fail with your own code if one does not. Every wait needs a limit: a faulty chip that hangs your test to the cycle limit is not caught.

Full specification
Select 0, the reset value, leaves every pad undriven. pins.csv of ap_soc v1.5; facts §27.11.
PadSelect 1Select 2Select 3
IO0GPIOUART TX (out)PWM (out)
IO1GPIOUART RX (in)capture (in)
IO2GPIOSPI clock (out)PWM (out)
IO3GPIOSPI data in (in)capture (in)
IO4GPIOSPI data out (out)timer event (in)
IO5GPIOSPI select (out)—
IO6 to IO15GPIO——
IO15, alwaysthe wake detector of ap_pwrctl
RegisterAddressUse
PINMUX0x1000_4010Pad n at bits 2n+1:2n
GPIO IN0x1000_1004Bit n: the level of pad n, whatever PINMUX says
TIMER_EVENT0x1000_2020Bit 0 ENABLE; bit 3 PENDING: an edge of the event input was seen, write 1 to clear
PWRCTL REQUEST, STATUS, WAKE_ENABLE, WAKE_CAUSE0x1000_8000 to 0x1000_800CSleep: write 1 to REQUEST, wait for STATE 3. A wake completes at STATE 0 and sets its bit in WAKE_CAUSE (bit 0 PAD)

timer_start(top, duty, compare) of drivers/timer.h runs the PWM. Duty 4 holds the output high for the whole period; duty 0 holds it low. spi_transfer(0x9f) of drivers/spi.h returns the 24 bits the flash sent back.

Given Files

Read-only files supplied by the bench.

drivers/uart.h
#ifndef AP_UART_H
#define AP_UART_H
#include "hal.h"

static inline void uart_flush(void)
{
    while (!FIELD_GET(UART0_STATUS_ROOM, reg_read32(UART0_STATUS))) { }
}

static inline void uart_putc(unsigned char byte)
{
    uart_flush();
    reg_write32(UART0_TXDATA, byte);
}

static inline unsigned char uart_getc(void)
{
    while (!FIELD_GET(UART0_STATUS_RX_READY, reg_read32(UART0_STATUS))) { }
    return reg_read32(UART0_RXDATA);
}

static inline void uart_enable_rx_irq(void)
{
    reg_write32(UART0_IRQ_ENABLE, UART0_IRQ_ENABLE_RX_READY_MASK);
}
#endif

drivers/spi.h
#ifndef AP_SPI_H
#define AP_SPI_H
#include "hal.h"

static inline unsigned spi_transfer(unsigned char command)
{
    while (reg_read32(SPI_STATUS) & SPI_STATUS_BUSY_MASK) { }
    reg_write32(SPI_STATUS, SPI_STATUS_DONE_MASK);
    reg_write32(SPI_DATA, command);
    while (!FIELD_GET(SPI_STATUS_DONE, reg_read32(SPI_STATUS))) { }
    return FIELD_GET(SPI_DATA_RECEIVED, reg_read32(SPI_DATA));
}
#endif

drivers/timer.h
#ifndef AP_TIMER_H
#define AP_TIMER_H
#include "hal.h"

static inline void timer_stop(void)
{
    reg_write32(TIMER_RUN, 0);
    reg_write32(TIMER_IRQ_CLEAR, TIMER_IRQ_CLEAR_MATCH_MASK);
}

static inline void timer_start(unsigned top, unsigned duty, unsigned compare)
{
    timer_stop();
    reg_write32(TIMER_DIV_TOP, FIELD_PREP(TIMER_DIV_TOP_TOP, top));
    reg_write32(TIMER_DUTY, FIELD_PREP(TIMER_DUTY_SLOTS, duty));
    reg_write32(TIMER_COMPARE, FIELD_PREP(TIMER_COMPARE_SLOT, compare));
    reg_write32(TIMER_IRQ_ENABLE, TIMER_IRQ_ENABLE_MATCH_MASK);
    reg_write32(TIMER_RUN, TIMER_RUN_RUN_MASK);
}
#endif

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

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.
ap_pwrctl · register manual
OffsetRegisterBitsFieldAccessResetHeld byMeaning
0x000REQUEST0sleepwonot storedStarts a power sequence of PD_PER. 1 starts the switch-off.
0x000REQUEST1wakewonot stored1 starts the switch-on.
0x004STATUS2:0stateroblockWhere the sequencer is, and the levels it drives. 0 on, 1 isolate, 2 save, 3 off, 4 switch on, 5 restore.
0x004STATUS4isolateroblockIsolation enable.
0x004STATUS5saveroblockRetention save level.
0x004STATUS6power_onroblockPower switch closed.
0x008WAKE_ENABLE0padrw0x0regsWhich events may wake PD_PER. The wake detector.
0x008WAKE_ENABLE1watchdogrw0x0regsThe watchdog's early warning.
0x00CWAKE_CAUSE0padw1cblockWhy the last wake happened. A written 1 clears a bit. The wake detector.
0x00CWAKE_CAUSE1watchdogw1cblockThe watchdog's early warning.
0x00CWAKE_CAUSE2softwarew1cblockREQUEST bit 1.
0x010IRQ_ENABLE2:0causerw0x0regsWhich wake causes raise interrupt source 9. Numbered as WAKE_CAUSE.
Timer and PWM · register manual
OffsetRegisterBitsFieldAccessResetHeld byMeaning
0x000RUN0runrw0x0regsStarts and stops the counter. 1: the counter runs.
0x004DUTY2:0slotsrw0x0regsHow many of the four slots drive the PWM pin high. 0 to 4.
0x008CAPTURED1:0slotroblockThe slot number saved when the capture input fired. Slot number.
0x00CDIV_TOP7:0toprw0x00regsPrescaler: the last count before the slot number steps. A write restarts the prescaler. Last prescaler count.
0x010COMPARE1:0slotrw0x0regsThe slot number that raises match. Slot number.
0x014IRQ_CLEAR0matchwonot storedWriting 1 to bit 0 clears the stored match flag. 1 clears the flag.
0x018IRQ_ENABLE0matchrw0x0regsLets the stored match flag raise interrupt source 3. 1 enables the request.
0x020EVENT0enablerw0x0regsSix teaching fields (S6.8). Plain read and write.
0x020EVENT1onlineroblockA level from the hardware.
0x020EVENT2kickwonot storedA written 1 makes one pulse.
0x020EVENT3pendingw1cblockSet by an event; a written 1 clears it.
0x020EVENT4seenrcblockSet by an event; a read clears it.
0x020EVENT5routerw0x0blockTakes the first write only.
0x024EVENT_COUNT_LOW31:0valueroblockLow 32 bits of the 64-bit event counter. Count, low word.
0x028EVENT_COUNT_HIGH31:0valueroblockHigh 32 bits of the event counter. Count, high word.

Examples

Example 1

The Good Chip
Input
your firmware
Output
console "pins ok"; pass

The bench sees 0x83 on IO0 and the flash answers C0 FF EE. Both PWM pads follow the duty, IO4's pulse sets PENDING, and the wake names the pad.

Example 2

A Hidden Faulty Chip
Input
your firmware on a faulty chip
Output
your fail word

Each hidden chip breaks one function between its block and its pad. Your check of that function must notice and return its code.

Example 3

What Does Not Count
Input
firmware that only routes the UART
Output
refused

A function you never selected can be miswired and your test still passes.

Constraints and Contract

  • C firmware with the kit, SRAM layout.
  • Pass on the good chip with the console line pins ok; fail visibly on every hidden chip.
  • The good chip runs the case first; the hidden chips run the same case.

Hints

Hint 1

An output the board does not watch can still be read: what does GPIO IN show while PWM drives a pad?

Hint 2

Which single transfer of the SPI flash needs all four of its pads to work?

Hint 3

For the wake pad, check what woke the chip, not only that it woke.

What the grader checks: Your firmware runs on the pre-built ap_soc v1.5 bench, on the good chip and on several hidden faulty chips. The good chip must pass with pins ok and one byte on the UART pad. The grader cannot see which function caught a faulty chip. Nor can it see your checks of PWM, the event input or the received byte: no hidden chip needs them. Capture is not covered by this problem.

1 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
your firmware
Expected output
console "pins ok"; pass

The bench sees 0x83 on IO0 and the flash answers C0 FF EE. Both PWM pads follow the duty, IO4's pulse sets PENDING, and the wake names the pad.

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

ap_soc v1.5 · firmware · server