V4.8.3 The Banner and the Checksum

HardOptimize25 minap_soc v1.5 · firmware · serverReview the topic

A test must send a long banner out of the UART pad and compute a checksum. Done one after the other, it misses its cycle budget. Make the chip do both at once.

Hardware context: A scenario on ap_soc v1.5 where the DMA, UART0, GPIO and ap_plic work at once. Overlapping a banner and a checksum inside a budget.

A test sends a 123-byte banner out of the UART transmit pad IO0. It also computes a CRC-8 over 96 bytes made from TB_ARG. Then it prints crc and the CRC. The given firmware does the two one after the other.

It must finish within 14,000 cycles. The banner on the pad and the console line must stay exactly as the given firmware makes them.

Full specification
WorkWhat sets its time (measured, ap_soc v1.5)
The bannerThe UART: about 88 cycles a byte at DIV = 8, about 10,800 cycles. The core only waits
The CRCThe core: tens of cycles a byte, bit by bit

The DMA can feed UART0 TXDATA: with TXDATA as its destination it waits for room before each byte. The kit has no DMA driver yet; the registers are in the DMA manual. UART0 can also raise an interrupt when it has room (IRQ_ENABLE bit 0).

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

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

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

DMA · register manual
OffsetRegisterBitsFieldAccessResetHeld byMeaning
0x000SRC31:0addressrw0x00000000regsThe address of the first byte to read. Byte address.
0x004DST31:0addressrw0x00000000regsThe address of the first byte to write. Byte address.
0x008LEN31:0bytesrw0x00000000regsThe number of bytes. Byte count.
0x00CSTART0startwonot storedBit 0 = 1 starts the job. Software writes it last. 1 starts the job.
0x014STATUS0busyroblockJob state (new in v1.5). A job is running.
0x014STATUS1donew1cblockThe last write of a job has finished.
0x014STATUS2faultw1cblockA bus error stopped the job.
0x018IRQ_ENABLE0donerw0x0regsWhich status bits raise interrupt source 5 (new in v1.5). DONE raises the request.
0x018IRQ_ENABLE1faultrw0x0regsFAULT raises the request.
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.

Examples

Example 1

TB_ARG = 7
Input
TB_ARG = 7
Output
console "crc ..."; pad: the 123-byte banner; cycles at most 14,000

The banner alone takes most of the budget, so the CRC must fit beside it.

Example 2

TB_ARG = 0
Input
TB_ARG = 0
Output
the same shape

TB_ARG | 1 is never 0, so the bytes are never all zero.

Example 3

TB_ARG = 0xFFFF_FFFF
Input
TB_ARG = 0xFFFF_FFFF
Output
the same shape

The cost does not depend on the data.

Constraints and Contract

  • C firmware with the kit, SRAM layout.
  • The run must end within 14,000 cycles, after the last byte of the banner has been handed to the UART.
  • Keep the banner, the CRC and the console line.

Hints

Hint 1

While the core waits for the UART, what is it not doing?

Hint 2

Which block can feed the UART without the core?

Hint 3

The test may end only after the banner has gone: how does main know?

What the grader checks: Each case compares the console line, the bytes on the UART pad and the run's cycle count against 14,000. The budget is a ceiling; how the work overlaps is up to you.

5 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

TB_ARG = 7

Input
TB_ARG = 7
Expected output
console "crc ..."; pad: the 123-byte banner; cycles at most 14,000

The banner alone takes most of the budget, so the CRC must fit beside it.

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

ap_soc v1.5 · firmware · server