VF.3.1 Change the First Test

EasyFix15 minap_soc v1.5 · firmware · serverReview the topic

Take the test from the guided tour and change three lines. Send the byte the bench asks for, at the speed it listens. Refuse a request that is not a printable character.

Hardware context: One C test on ap_soc v1.5, from power-good to the pass word. Changing the tour's test in three lines.

In the guided tour, first_test.c sent the letter K out of pad IO0, at the speed UART0 has after reset. A regression wants one test that sends any byte it is asked for, at the speed the bench listens. Change three lines, at the three marks in the starter.

Change 1, the byte. Replace the letter K with tb_arg(0), the word the bench leaves in the mailbox register TB_ARG before the run. Why: one compiled test then serves many runs.

Change 2, refuse a bad request. Printable characters are 0x20 (space) to 0x7E (tilde), both ends included. The whole 32-bit word must be in that range: a word with any higher bit set is not printable. For any other value, send nothing and return 2;. Why: a test that cannot do what it was asked must say so with its own fail code.

Change 3, the speed. This bench's UART receiver listens at 8 clk_sys cycles a bit. UART0 sends at the number of cycles in its divider register, DIV, which is 16 after reset. Write 8 to UART0_DIV before the write to TXDATA. Why: at the wrong speed, the bench reads a different byte, two bytes, or a broken frame that its UART monitor reports.

Order matters: the range check and the DIV write must both come before the write to TXDATA, which starts the byte. Keep the two console lines, the identity check, the pin mux write and the wait for ROOM exactly as they are.

Full specification
Request in TB_ARGOn pad IO0ConsoleTB_STATUS
0x20 to 0x7Ethat one byte, at 8 cycles a bithello from ap_soc, byte sent0x0000_900D (pass)
anything elsenothinghello from ap_soc0xBAD0_0002 (fail code 2)

reg_read32(address) reads one 32-bit register of the chip, and reg_write32(address, value) writes one; hal.h names the registers. tb_arg(0) reads TB_ARG, the mailbox word the bench sets before the run (tb.h). Only slot 0 exists: any other slot ends the test with fail code 0xFFFE.

UART0 is at 0x1000_0000: TXDATA at 0x00, STATUS at 0x04 (bit 0 ROOM), DIV at 0x10 (16 bits, reset value 16). ap_sysctl is at 0x1000_4000: CHIP_ID at 0x00, PINMUX at 0x10. The header names them UART0_TXDATA, UART0_STATUS, UART0_DIV, SYSCTL_CHIP_ID and SYSCTL_PINMUX.

Returning a nonzero code from main makes the start-up code write the fail word 0xBAD0_0000 + code. Returning 0 writes the pass word 0x900D.

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

UART0 · register manual
OffsetRegisterBitsFieldAccessResetHeld byMeaning
0x000TXDATA7:0datawonot storedThe low byte is the next byte to send. Byte to send.
0x004STATUS0roomroblockTransmit room and receive queue state. The transmitter can take a byte.
0x004STATUS1rx_readyroblockAt least one received byte waits.
0x004STATUS2rx_fullroblockThe receive queue is full.
0x008IRQ_ENABLE0roomrw0x0regsWhich status bits raise interrupt source 1. ROOM raises the request.
0x008IRQ_ENABLE1rx_readyrw0x0regsRX_READY raises the request (new in v1.5).
0x00CRXDATA7:0dataroblockThe oldest received byte. The read removes it from the queue. Received byte.
0x010DIV15:0cyclesrw0x0010regsBit time in clk_sys cycles (new in v1.5). clk_sys cycles a bit.
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

Asked for A
Input
the bench asks for A (0x41)
Output
console "hello from ap_soc", "byte sent"; pad: 1 byte, hash c40bf6cc; TB_STATUS = 0x900D

A is 0x41, inside the printable range, so the test sends it at 8 cycles a bit and passes.

Example 2

Asked for the Tilde
Input
the bench asks for the tilde, 0x7E, the last printable character
Output
console "hello from ap_soc", "byte sent"; pad: 1 byte, hash fb0c4d61; TB_STATUS = 0x900D

0x7E is the upper end of the range, and the range includes its ends.

Example 3

Asked for a Bell
Input
the bench asks for 0x07, a bell, which is not printable
Output
console "hello from ap_soc"; pad: no byte; TB_STATUS = 0xBAD0_0002

0x07 is not printable. The test sends nothing and fails with code 2.

Constraints and Contract

  • C firmware with the kit, ROM layout, as in the tour.
  • Keep the console lines exactly: the bench compares the text.
  • The bench decodes pad IO0 at 8 cycles a bit, whatever DIV says. It counts and hashes every byte it receives.

Hints

Hint 1

Which kit call reads the word the bench left in TB_ARG?

Hint 2

Printable is a range with two ends. Test both ends, and remember that TB_ARG is 32 bits wide.

Hint 3

Which register sets the bit time of UART0, and must it be written before or after TXDATA?

What the grader checks: Each case runs your firmware once on the chip bench. The bench puts the request in TB_ARG and listens on pad IO0 at 8 cycles a bit. It compares the console text, the status word, and the number and a hash of the bytes it received. It does not grade cycle counts, and it cannot see what your program does between those writes.

10 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

Asked for A

Input
the bench asks for A (0x41)
Expected output
console "hello from ap_soc", "byte sent"; pad: 1 byte, hash c40bf6cc; TB_STATUS = 0x900D

A is 0x41, inside the printable range, so the test sends it at 8 cycles a bit and passes.

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

ap_soc v1.5 · firmware · server