V13.4.1 A Portable Flash-Table Check

MediumImplement25 minap_soc v1.5 · host C · serverReview the topic

Write a C test that checks a table in the SPI flash and runs unchanged on any target. The grader runs it on the host, through DPI on the chip's bus-manager seat: no processor, the real RTL, the real pads.

Hardware context: One C test built for the host (DPI on the bus-manager seat), the core, the VP and the hybrid. A flash-table check run host-native.

A portable test is written once, against hal.h and tb.h only. It is built for every target: the chip's processor, the virtual platform, the hybrid and the host. On the host it runs as a separate program. Each reg_read32 and reg_write32 becomes one transfer of the bus-manager seat, through DPI, on the real RTL.

Write main.c. Set PINMUX to 0xAAA. Check the flash identity (command 0x9F, C0FFEE), else return 1. Send 0x66, then read the table with 0x03 frames. Frame 0 holds A, P and the record count n. Frames 1 to n are records. Frame n + 1 holds the XOR of the records.

Return 2 if the frame 0 does not start with AP, and 3 if n is above 60. Otherwise print records , n and xor and the XOR you computed, each as eight hex digits (tb_put_hex), and a newline. Return 4 if it differs from the stored XOR, else 0.

Full specification
FrameBytesMeaning
00x41, 0x50, n"AP" and the number of records
1 to nthree eachone 24-bit record, first byte on top
n + 1threethe XOR of the n records
ResultReturn
wrong identity1
no "AP"2
n above 603
stored XOR differs (after the line)4
all good (after the line)0

On the host there is no processor: no CSR, no inline assembly, no interrupt, and no pointer to a register address. A transfer that answers ERROR ends the test with fail code 0xFFFF.

Given Files

Read-only files supplied by the bench.

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

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

soc_host.h
/* soc_host.h: what a C test that runs on the host may call besides hal.h and tb.h (stage E7).
   The test is built as an executable with soc_host_shim.c and no C library (soc-bench.mjs,
   buildHostTest; tools/soc-run.mjs) and started by the pre-built bench, as a process of its own,
   with +core=bfm +ctest=<file>. reg_read32 and reg_write32 of hal.h, and so every call of
   tb.h and of the drivers, become transfers of the bus-manager seat on the chip's data port.
   A transfer that answers ERROR ends the test with fail code 0xffff, as the trap does in firmware;
   the calls below return the error instead, for tests that look for it. */
#ifndef SOC_HOST_H
#define SOC_HOST_H
/* One transfer: size 1, 2 or 4 bytes. Returns 1 when the bus answered ERROR. */
int host_read(unsigned address, unsigned size, unsigned *value);
int host_write(unsigned address, unsigned size, unsigned value);
/* Let cycles of clk_sys pass with the bus idle. */
void host_idle(unsigned cycles);
/* The interrupt pins of the seat: bit 0 software, bit 1 timer, bit 2 external. */
unsigned host_irq_pins(void);
/* A word of ROM or SRAM by the back door. */
unsigned host_peek(unsigned address);
void host_poke(unsigned address, unsigned value);
#endif

SPI · register manual
OffsetRegisterBitsFieldAccessResetHeld byMeaning
0x000DATA7:0commandwonot storedWrite: a command byte; the write starts a frame of 32 serial clocks. Read: the last 24 bits received. Command byte.
0x000DATA23:0receivedroblockLast 24 bits received.
0x004STATUS0busyroblockFrame state. A frame is running, and chip select is low.
0x004STATUS1donew1cblockA frame has ended (new in v1.5).
0x008IRQ_ENABLE0donerw0x0regsLets DONE raise interrupt source 4 (new in v1.5). 1 enables the request.
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.

Examples

Example 1

Three Records
Input
A table of three records
Output
one line, then pass

The XOR of three records matches frame 4.

Example 2

Eight Records
Input
A table of eight records
Output
one line, then pass

A longer table.

Example 3

A Wrong Stored XOR
Input
A table whose stored xor is wrong
Output
the line, then fail code 4

The test prints what it computed and fails: the stored XOR differs in one bit.

Constraints and Contract

  • C for the host-native build (AP_HOST_DPI): hal.h, tb.h and the kit drivers only.
  • Print exactly one line, and only when the header is good.
  • Return the codes of the table.

Hints

Hint 1

What would a test that only prints the XOR, and never compares it, report for a corrupted table?

Hint 2

Read the stored XOR after the records: the flash gives frames in order.

Hint 3

Check the header before you trust n.

What the grader checks: Each case runs your test host-native on the chip bench, with its own flash image. It checks the console and the pass or fail word. The flash identity is fixed, so the check for return code 1 is not exercised. The grader cannot see whether the same source also builds for the core; V13.4.2 is about that.

8 checks on ap_soc v1.5 · host C · 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 3 problems on this path

Report a problem with this page

Your code C (host)Saved locally
Ln 1, Col 1Tab indents · Ctrl/⌘ + Enter runs samples
Not run yet

Three Records

Input
A table of three records
Expected output
one line, then pass

The XOR of three records matches frame 4.

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

ap_soc v1.5 · host C · server