V12.2.2 Report a Scenario Only When It Held

MediumImplement30 minap_soc v1.5 · firmware · serverReview the topic

Write firmware that checks two scenarios on the chip and reports each to the bench's coverage model only when it really happened.

Hardware context: The bench-side sampler of ap_soc v1.5 and the firmware coverage channel through TB_EVENT. Firmware scenario points reported only after a check.

Some chip events have no wire the bench can sample. A byte arrived and was the right one. An edge was seen by software. Firmware reports such a scenario to the coverage model itself, through the mailbox. That makes the report only as honest as the code in front of it.

Write C firmware for two scenarios. rx_checked: a byte from the board's UART arrives at UART0 and equals the low byte of TB_ARG. gpio_edge: an edge on pad IO11 is latched in GPIO STATUS bit 11. Report each scenario with tb_cover only after its check passed, and print one line per scenario, as in the examples.

First give pads 0 and 1 to the UART and enable the receive interrupt (UART0 IRQ_ENABLE bit 1). Make IO11 a rising-edge input with its interrupt enabled, and clear its old status. Then write TB_EVENT 0x51: the board waits for that event before it sends anything. Each case's board sends one byte and pulses IO11, or leaves something out.

If no byte comes within your limit print rx none; if a byte comes but differs, print rx mismatch; if it matches, report and print rx ok. Do the same for the edge with gpio ok and gpio none. Every run must pass: a failed scenario is reported by not reporting it, never by a fail word.

Full specification
The two firmware points pair with two bench points: the firmware says it checked, the bench says the hardware event happened.
BinWhat earns a hit
firmware.rx_checkedFirmware called tb_cover(TB_COV_RX_CHECKED): a full-word write of TB_EVENT with the scenario's planned number
firmware.gpio_edgeFirmware called tb_cover(TB_COV_GPIO_EDGE)
irq.raised.1The bench saw UART0's request rise at ap_plic: RX_READY with its enable on
irq.raised.2The bench saw GPIO's request rise: a latched, enabled edge
RegisterAddressUse
SYSCTL_PINMUX0x1000_4010Two bits a pad; value 2 on pads 0 and 1 gives them to UART0
UART0_STATUS, UART0_RXDATA0x1000_0004, 0x1000_000CSTATUS bit 1 RX_READY; RXDATA holds the byte
UART0_IRQ_ENABLE0x1000_0008Bit 1: RX_READY raises source 1
GPIO_LEVEL_MODE, GPIO_ACTIVE_HIGH0x1000_101C, 0x1000_10200 and 1 for a rising edge
GPIO_STATUS, GPIO_IRQ_ENABLE0x1000_1024, 0x1000_1018A written 1 clears a latched edge; bit 11 enables IO11

tb_cover.h is in the kit, and TB_COV_RX_CHECKED and TB_COV_GPIO_EDGE are defined for this problem. The bench promises that nothing happens on the UART line or on IO11 before your TB_EVENT 0x51. After it, the board sends at the UART0 divider in use, 16 cycles a bit at reset. Then it pulses IO11 for four cycles.

Coverage Goal

Hit at least 4 of 4 declared bins across the runs. firmware.rx_checked, firmware.gpio_edge, irq.raised.1, irq.raised.2.

Report firmware points with tb_cover(TB_COV_RX_CHECKED), tb_cover(TB_COV_GPIO_EDGE).

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

tb_cover.h
#ifndef AP_TB_COVER_H
#define AP_TB_COVER_H

#include "tb.h"

/* Bench plan IDs carried in the reserved TB_EVENT range 0xc07e0000..0xc07e000f. */
enum tb_scenario { TB_COV_WAKE_CLAIM = 1, TB_COV_FLASH_ID, TB_COV_DMA_COPY };
/* Problems may name IDs 4..15 with their own enum constants. */
static inline void tb_cover(unsigned scenario)
{
    if (scenario < TB_COV_WAKE_CLAIM || scenario > 15u) tb_fail(0xfffdu);
    tb_event(0xc07e0000u | scenario);
}

#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.
GPIO · register manual
OffsetRegisterBitsFieldAccessResetHeld byMeaning
0x000DIR15:0valuerw0x0000regs1 turns the output driver of that pin on. One bit for each pin.
0x004IN15:0valueroblockThe pin levels, after two sampling flip-flops. One bit for each pin.
0x008OUT15:0valuerw0x0000regsThe saved output value. One bit for each pin.
0x00CSET15:0valuew1sacts on OUT.valueA 1 sets that bit of OUT. One bit for each pin.
0x010CLR15:0valuew1cacts on OUT.valueA 1 clears that bit of OUT. One bit for each pin.
0x014TGL15:0valuew1tacts on OUT.valueA 1 inverts that bit of OUT. One bit for each pin.
0x018IRQ_ENABLE15:0valuerw0x0000regsA 1 lets that pin's status bit raise interrupt source 2. One bit for each pin.
0x01CLEVEL_MODE15:0valuerw0x0000regs1: the pin is a level cause. 0: an edge cause. One bit for each pin.
0x020ACTIVE_HIGH15:0valuerw0xFFFFregs1: a high level, or a rising edge, is the event. One bit for each pin.
0x024STATUS15:0valuew1cblockRaw status. A written 1 clears the saved edge flag of that pin. One bit for each pin.
0x028MASKED_STATUS15:0valueroblockSTATUS AND IRQ_ENABLE. One bit for each pin.
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

Byte and Edge Both Come
Input
the board sends 5A; TB_ARG = 5A
Output
console "rx ok", "gpio ok"; 3 TB_EVENT writes; pass

The ready word and two reports. Both firmware bins and both request bins are hit.

Example 2

Another Byte
Input
the board sends C3; TB_ARG = C3
Output
the same lines and count

The expected byte comes from TB_ARG, so a constant in the program cannot pass both cases.

Example 3

A Byte That Differs
Input
a hidden case: the byte and TB_ARG differ
Output
"rx mismatch", "gpio ok"; 2 TB_EVENT writes; pass

The scenario did not hold, so it is not reported. The run still passes: a coverage test reports what happened.

Constraints and Contract

  • C firmware with the kit, SRAM layout.
  • Write TB_EVENT only for the ready word and through tb_cover: the bench counts every TB_EVENT write, and a case checks the count.
  • Every wait needs a limit; every run ends with the pass word.

Hints

Hint 1

A coverage point is a claim. What has to be true before you make it?

Hint 2

What happens to your program in a case where the byte never comes, or is not the expected one?

Hint 3

The bench counts the TB_EVENT writes of each run. How many should a run with one failed scenario make?

What the grader checks: Four cases run your firmware on the coverage build of the bench. Each must pass, print the expected lines and make the expected number of TB_EVENT writes. The four bins are merged over all cases and must all be hit. The grader cannot see what you compared; it sees the console, the event count and the bins.

4 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

Byte and Edge Both Come

Input
the board sends 5A; TB_ARG = 5A
Expected output
console "rx ok", "gpio ok"; 3 TB_EVENT writes; pass

The ready word and two reports. Both firmware bins and both request bins are hit.

Run samples executes all 2 public checks. Check all tests runs 4 checks on the server.

ap_soc v1.5 · firmware · server