V4.4.1 Vectors from the Bench

MediumImplement25 minap_soc v1.5 · firmware · serverReview the topic

The bench loads test vectors into SRAM by the back door, one at a time, and the firmware works on each. Write the hand-shake so that the firmware never reads a vector before it is there, and never reads one twice.

Hardware context: Hand-shakes between firmware and the bench of ap_soc v1.5 through TB_EVENT and TB_ARG. Test vectors loaded by the bench, one hand-shake each.

A test of a checksum routine takes its input from the bench. TB_ARG holds n, the number of vectors, when the test starts. For each vector r = 1 to n, the firmware asks with TB_EVENT = 0xA000 + r. The bench writes four words at 0x8000_9000 by the back door and then puts 0xB000 + r into TB_ARG.

For each vector, print vector, r, sum , the sum of the four words, xor and their exclusive or. Use eight hex digits each, and end the line. After the last vector print done and return 0.

Full specification
FirmwareBench
reads n from TB_ARGhas put n there before the first instruction
TB_EVENT = 0xA000 + rwaits for it; writes the four words of vector r
waits for TB_ARG = 0xB000 + rTB_ARG = 0xB000 + r
reads the four words, prints the linewaits for the next request

A back-door write takes no bus cycle and leaves no trace on the bus. Only the reply tells the firmware that the words are there. In some runs the bench takes over a thousand cycles before it writes.

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

Examples

Example 1

One Vector
Input
one vector
Output
vector 00000001 sum ... xor ..., then done

One request, one reply, four words.

Example 2

Two Vectors
Input
two vectors
Output
two lines, one a vector

The second request is 0xA002, and its reply is 0xB002.

Example 3

A Late Vector
Input
three vectors, the second one late
Output
three lines

The bench takes 900 cycles for the second vector. The firmware waits for 0xB002, however long it takes.

Constraints and Contract

  • C firmware with the kit, SRAM layout.
  • Keep the event and reply numbers and the line format.
  • n is from 1 to 8.

Hints

Hint 1

Which kit call waits until TB_ARG holds a number?

Hint 2

Why does each reply carry its own number?

Hint 3

Two vectors can be equal, or all zeros: the data cannot tell you that new data came.

What the grader checks: Each case runs n hand-shakes with the bench writing the vectors after chosen delays, and compares the console text. It cannot see when your firmware read the words, only what it printed.

8 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 3 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

One Vector

Input
one vector
Expected output
vector 00000001 sum ... xor ..., then done

One request, one reply, four words.

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

ap_soc v1.5 · firmware · server