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
| Work | What sets its time (measured, ap_soc v1.5) |
|---|---|
| The banner | The UART: about 88 cycles a byte at DIV = 8, about 10,800 cycles. The core only waits |
| The CRC | The 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
| Offset | Register | Bits | Field | Access | Reset | Held by | Meaning |
|---|---|---|---|---|---|---|---|
0x000 | SRC | 31:0 | address | rw | 0x00000000 | regs | The address of the first byte to read. Byte address. |
0x004 | DST | 31:0 | address | rw | 0x00000000 | regs | The address of the first byte to write. Byte address. |
0x008 | LEN | 31:0 | bytes | rw | 0x00000000 | regs | The number of bytes. Byte count. |
0x00C | START | 0 | start | wo | not stored | Bit 0 = 1 starts the job. Software writes it last. 1 starts the job. | |
0x014 | STATUS | 0 | busy | ro | block | Job state (new in v1.5). A job is running. | |
0x014 | STATUS | 1 | done | w1c | block | The last write of a job has finished. | |
0x014 | STATUS | 2 | fault | w1c | block | A bus error stopped the job. | |
0x018 | IRQ_ENABLE | 0 | done | rw | 0x0 | regs | Which status bits raise interrupt source 5 (new in v1.5). DONE raises the request. |
0x018 | IRQ_ENABLE | 1 | fault | rw | 0x0 | regs | FAULT raises the request. |
## DMA (base 0x1000_6000, interrupt source 5, clk_sys, PD_MAIN) | Offset | Register | Bits | Field | Access | Reset | Held by | Meaning | | --- | --- | --- | --- | --- | --- | --- | --- | | `0x000` | SRC | 31:0 | address | rw | `0x00000000` | regs | The address of the first byte to read. Byte address. | | `0x004` | DST | 31:0 | address | rw | `0x00000000` | regs | The address of the first byte to write. Byte address. | | `0x008` | LEN | 31:0 | bytes | rw | `0x00000000` | regs | The number of bytes. Byte count. | | `0x00C` | START | 0 | start | wo | | not stored | Bit 0 = 1 starts the job. Software writes it last. 1 starts the job. | | `0x014` | STATUS | 0 | busy | ro | | block | Job state (new in v1.5). A job is running. | | `0x014` | STATUS | 1 | done | w1c | | block | The last write of a job has finished. | | `0x014` | STATUS | 2 | fault | w1c | | block | A bus error stopped the job. | | `0x018` | IRQ_ENABLE | 0 | done | rw | `0x0` | regs | Which status bits raise interrupt source 5 (new in v1.5). DONE raises the request. | | `0x018` | IRQ_ENABLE | 1 | fault | rw | `0x0` | regs | FAULT raises the request. |
UART0 · register manual
| Offset | Register | Bits | Field | Access | Reset | Held by | Meaning |
|---|---|---|---|---|---|---|---|
0x000 | TXDATA | 7:0 | data | wo | not stored | The low byte is the next byte to send. Byte to send. | |
0x004 | STATUS | 0 | room | ro | block | Transmit room and receive queue state. The transmitter can take a byte. | |
0x004 | STATUS | 1 | rx_ready | ro | block | At least one received byte waits. | |
0x004 | STATUS | 2 | rx_full | ro | block | The receive queue is full. | |
0x008 | IRQ_ENABLE | 0 | room | rw | 0x0 | regs | Which status bits raise interrupt source 1. ROOM raises the request. |
0x008 | IRQ_ENABLE | 1 | rx_ready | rw | 0x0 | regs | RX_READY raises the request (new in v1.5). |
0x00C | RXDATA | 7:0 | data | ro | block | The oldest received byte. The read removes it from the queue. Received byte. | |
0x010 | DIV | 15:0 | cycles | rw | 0x0010 | regs | Bit time in clk_sys cycles (new in v1.5). clk_sys cycles a bit. |
## UART0 (base 0x1000_0000, interrupt source 1, clk_sys, PD_MAIN) | Offset | Register | Bits | Field | Access | Reset | Held by | Meaning | | --- | --- | --- | --- | --- | --- | --- | --- | | `0x000` | TXDATA | 7:0 | data | wo | | not stored | The low byte is the next byte to send. Byte to send. | | `0x004` | STATUS | 0 | room | ro | | block | Transmit room and receive queue state. The transmitter can take a byte. | | `0x004` | STATUS | 1 | rx_ready | ro | | block | At least one received byte waits. | | `0x004` | STATUS | 2 | rx_full | ro | | block | The receive queue is full. | | `0x008` | IRQ_ENABLE | 0 | room | rw | `0x0` | regs | Which status bits raise interrupt source 1. ROOM raises the request. | | `0x008` | IRQ_ENABLE | 1 | rx_ready | rw | `0x0` | regs | RX_READY raises the request (new in v1.5). | | `0x00C` | RXDATA | 7:0 | data | ro | | block | The oldest received byte. The read removes it from the queue. Received byte. | | `0x010` | DIV | 15:0 | cycles | rw | `0x0010` | regs | Bit 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