A faulty chip has one wire of its interrupt map crossed. Every block still works alone. Write the firmware that passes on the good chip and makes the faulty one fail visibly.
Hardware context: A scenario on ap_soc v1.5 where the DMA, UART0, GPIO and ap_plic work at once. Making a crossed interrupt wire fail visibly.
Here is the faulty chip, stated plainly. Its generated top level wires ap_plic input 2 to the request of the Timer and PWM block. Input 2 belongs to GPIO. The timer still asks on its own input 3, and GPIO itself works. Every block bench would pass it.
Write firmware that passes on the good chip and fails visibly on this one. A fail word of yours counts, and so does a bench check. A hang to the cycle limit does not count. On the good chip, print timer and gpio apart and pass.
Full specification
| Source | Device | Kit |
|---|---|---|
| 2 | GPIO | gpio_rising_irq(mask) enables a rising-edge interrupt; gpio_ack(mask) clears it. TB_EVENT 5 makes the board pulse IO8 |
| 3 | Timer and PWM | timer_start(top, duty, compare) enables its match interrupt; timer_stop clears it |
irq_enable(id, handler) enables a source at ap_plic with priority 1 and gives it a handler. The kit claims each external interrupt once and calls the handler of the claimed number. Of two pending sources of equal priority, the smaller number is claimed first.
Given Files
Read-only files supplied by the bench.
drivers/gpio.h
#ifndef AP_GPIO_H
#define AP_GPIO_H
#include "hal.h"
static inline void gpio_drive(unsigned outputs, unsigned value)
{
reg_write32(GPIO_OUT, value);
reg_write32(GPIO_DIR, outputs);
}
static inline unsigned gpio_read(void)
{
return reg_read32(GPIO_IN);
}
/* Select the rising-edge inputs for this test and discard stale edges. */
static inline void gpio_rising_irq(unsigned pins)
{
reg_write32(GPIO_LEVEL_MODE, 0);
reg_write32(GPIO_ACTIVE_HIGH, pins);
reg_write32(GPIO_STATUS, pins);
reg_write32(GPIO_IRQ_ENABLE, pins);
}
static inline void gpio_ack(unsigned pins)
{
reg_write32(GPIO_STATUS, pins);
}
#endif
drivers/timer.h
#ifndef AP_TIMER_H
#define AP_TIMER_H
#include "hal.h"
static inline void timer_stop(void)
{
reg_write32(TIMER_RUN, 0);
reg_write32(TIMER_IRQ_CLEAR, TIMER_IRQ_CLEAR_MATCH_MASK);
}
static inline void timer_start(unsigned top, unsigned duty, unsigned compare)
{
timer_stop();
reg_write32(TIMER_DIV_TOP, FIELD_PREP(TIMER_DIV_TOP_TOP, top));
reg_write32(TIMER_DUTY, FIELD_PREP(TIMER_DUTY_SLOTS, duty));
reg_write32(TIMER_COMPARE, FIELD_PREP(TIMER_COMPARE_SLOT, compare));
reg_write32(TIMER_IRQ_ENABLE, TIMER_IRQ_ENABLE_MATCH_MASK);
reg_write32(TIMER_RUN, TIMER_RUN_RUN_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
GPIO · register manual
| Offset | Register | Bits | Field | Access | Reset | Held by | Meaning |
|---|---|---|---|---|---|---|---|
0x000 | DIR | 15:0 | value | rw | 0x0000 | regs | 1 turns the output driver of that pin on. One bit for each pin. |
0x004 | IN | 15:0 | value | ro | block | The pin levels, after two sampling flip-flops. One bit for each pin. | |
0x008 | OUT | 15:0 | value | rw | 0x0000 | regs | The saved output value. One bit for each pin. |
0x00C | SET | 15:0 | value | w1s | acts on OUT.value | A 1 sets that bit of OUT. One bit for each pin. | |
0x010 | CLR | 15:0 | value | w1c | acts on OUT.value | A 1 clears that bit of OUT. One bit for each pin. | |
0x014 | TGL | 15:0 | value | w1t | acts on OUT.value | A 1 inverts that bit of OUT. One bit for each pin. | |
0x018 | IRQ_ENABLE | 15:0 | value | rw | 0x0000 | regs | A 1 lets that pin's status bit raise interrupt source 2. One bit for each pin. |
0x01C | LEVEL_MODE | 15:0 | value | rw | 0x0000 | regs | 1: the pin is a level cause. 0: an edge cause. One bit for each pin. |
0x020 | ACTIVE_HIGH | 15:0 | value | rw | 0xFFFF | regs | 1: a high level, or a rising edge, is the event. One bit for each pin. |
0x024 | STATUS | 15:0 | value | w1c | block | Raw status. A written 1 clears the saved edge flag of that pin. One bit for each pin. | |
0x028 | MASKED_STATUS | 15:0 | value | ro | block | STATUS AND IRQ_ENABLE. One bit for each pin. |
## GPIO (base 0x1000_1000, interrupt source 2, clk_sys, PD_MAIN) | Offset | Register | Bits | Field | Access | Reset | Held by | Meaning | | --- | --- | --- | --- | --- | --- | --- | --- | | `0x000` | DIR | 15:0 | value | rw | `0x0000` | regs | 1 turns the output driver of that pin on. One bit for each pin. | | `0x004` | IN | 15:0 | value | ro | | block | The pin levels, after two sampling flip-flops. One bit for each pin. | | `0x008` | OUT | 15:0 | value | rw | `0x0000` | regs | The saved output value. One bit for each pin. | | `0x00C` | SET | 15:0 | value | w1s | | acts on OUT.value | A 1 sets that bit of OUT. One bit for each pin. | | `0x010` | CLR | 15:0 | value | w1c | | acts on OUT.value | A 1 clears that bit of OUT. One bit for each pin. | | `0x014` | TGL | 15:0 | value | w1t | | acts on OUT.value | A 1 inverts that bit of OUT. One bit for each pin. | | `0x018` | IRQ_ENABLE | 15:0 | value | rw | `0x0000` | regs | A 1 lets that pin's status bit raise interrupt source 2. One bit for each pin. | | `0x01C` | LEVEL_MODE | 15:0 | value | rw | `0x0000` | regs | 1: the pin is a level cause. 0: an edge cause. One bit for each pin. | | `0x020` | ACTIVE_HIGH | 15:0 | value | rw | `0xFFFF` | regs | 1: a high level, or a rising edge, is the event. One bit for each pin. | | `0x024` | STATUS | 15:0 | value | w1c | | block | Raw status. A written 1 clears the saved edge flag of that pin. One bit for each pin. | | `0x028` | MASKED_STATUS | 15:0 | value | ro | | block | STATUS AND IRQ_ENABLE. One bit for each pin. |
Timer and PWM · register manual
| Offset | Register | Bits | Field | Access | Reset | Held by | Meaning |
|---|---|---|---|---|---|---|---|
0x000 | RUN | 0 | run | rw | 0x0 | regs | Starts and stops the counter. 1: the counter runs. |
0x004 | DUTY | 2:0 | slots | rw | 0x0 | regs | How many of the four slots drive the PWM pin high. 0 to 4. |
0x008 | CAPTURED | 1:0 | slot | ro | block | The slot number saved when the capture input fired. Slot number. | |
0x00C | DIV_TOP | 7:0 | top | rw | 0x00 | regs | Prescaler: the last count before the slot number steps. A write restarts the prescaler. Last prescaler count. |
0x010 | COMPARE | 1:0 | slot | rw | 0x0 | regs | The slot number that raises match. Slot number. |
0x014 | IRQ_CLEAR | 0 | match | wo | not stored | Writing 1 to bit 0 clears the stored match flag. 1 clears the flag. | |
0x018 | IRQ_ENABLE | 0 | match | rw | 0x0 | regs | Lets the stored match flag raise interrupt source 3. 1 enables the request. |
0x020 | EVENT | 0 | enable | rw | 0x0 | regs | Six teaching fields (S6.8). Plain read and write. |
0x020 | EVENT | 1 | online | ro | block | A level from the hardware. | |
0x020 | EVENT | 2 | kick | wo | not stored | A written 1 makes one pulse. | |
0x020 | EVENT | 3 | pending | w1c | block | Set by an event; a written 1 clears it. | |
0x020 | EVENT | 4 | seen | rc | block | Set by an event; a read clears it. | |
0x020 | EVENT | 5 | route | rw | 0x0 | block | Takes the first write only. |
0x024 | EVENT_COUNT_LOW | 31:0 | value | ro | block | Low 32 bits of the 64-bit event counter. Count, low word. | |
0x028 | EVENT_COUNT_HIGH | 31:0 | value | ro | block | High 32 bits of the event counter. Count, high word. |
## Timer and PWM (base 0x1000_2000, interrupt source 3, clk_sys, PD_PER) | Offset | Register | Bits | Field | Access | Reset | Held by | Meaning | | --- | --- | --- | --- | --- | --- | --- | --- | | `0x000` | RUN | 0 | run | rw | `0x0` | regs | Starts and stops the counter. 1: the counter runs. | | `0x004` | DUTY | 2:0 | slots | rw | `0x0` | regs | How many of the four slots drive the PWM pin high. 0 to 4. | | `0x008` | CAPTURED | 1:0 | slot | ro | | block | The slot number saved when the capture input fired. Slot number. | | `0x00C` | DIV_TOP | 7:0 | top | rw | `0x00` | regs | Prescaler: the last count before the slot number steps. A write restarts the prescaler. Last prescaler count. | | `0x010` | COMPARE | 1:0 | slot | rw | `0x0` | regs | The slot number that raises match. Slot number. | | `0x014` | IRQ_CLEAR | 0 | match | wo | | not stored | Writing 1 to bit 0 clears the stored match flag. 1 clears the flag. | | `0x018` | IRQ_ENABLE | 0 | match | rw | `0x0` | regs | Lets the stored match flag raise interrupt source 3. 1 enables the request. | | `0x020` | EVENT | 0 | enable | rw | `0x0` | regs | Six teaching fields (S6.8). Plain read and write. | | `0x020` | EVENT | 1 | online | ro | | block | A level from the hardware. | | `0x020` | EVENT | 2 | kick | wo | | not stored | A written 1 makes one pulse. | | `0x020` | EVENT | 3 | pending | w1c | | block | Set by an event; a written 1 clears it. | | `0x020` | EVENT | 4 | seen | rc | | block | Set by an event; a read clears it. | | `0x020` | EVENT | 5 | route | rw | `0x0` | block | Takes the first write only. | | `0x024` | EVENT_COUNT_LOW | 31:0 | value | ro | | block | Low 32 bits of the 64-bit event counter. Count, low word. | | `0x028` | EVENT_COUNT_HIGH | 31:0 | value | ro | | block | High 32 bits of the event counter. Count, high word. |
ap_plic · register manual
| Offset | Register | Bits | Field | Access | Reset | Held by | Meaning |
|---|---|---|---|---|---|---|---|
0x004 + 4 × (n − 1), n = 1 to 16 | PRIORITY | 2:0 | level | rw | 0x0 | block | Priority of source n, 0 to 7. 0 never competes. Priority. |
0x001000 | PENDING | 16:1 | sources | ro | block | Pending bits; bit number = source ID. One bit for each source. | |
0x002000 | ENABLE | 16:1 | sources | rw | 0x0000 | block | Enable bits; bit number = source ID. One bit for each source. |
0x200000 | THRESHOLD | 2:0 | level | rw | 0x0 | block | The core sees a request only above this priority. Threshold. |
0x200004 | CLAIM | 4:0 | id | rw | 0x00 | block | Read: claim, returns the winner's ID and clears its pending bit. Write: complete, names the ID that is done. Source ID. |
## ap_plic (base 0x0C00_0000, clk_sys, PD_MAIN) | Offset | Register | Bits | Field | Access | Reset | Held by | Meaning | | --- | --- | --- | --- | --- | --- | --- | --- | | `0x004` + 4 × (n − 1), n = 1 to 16 | PRIORITY | 2:0 | level | rw | `0x0` | block | Priority of source n, 0 to 7. 0 never competes. Priority. | | `0x001000` | PENDING | 16:1 | sources | ro | | block | Pending bits; bit number = source ID. One bit for each source. | | `0x002000` | ENABLE | 16:1 | sources | rw | `0x0000` | block | Enable bits; bit number = source ID. One bit for each source. | | `0x200000` | THRESHOLD | 2:0 | level | rw | `0x0` | block | The core sees a request only above this priority. Threshold. | | `0x200004` | CLAIM | 4:0 | id | rw | `0x00` | block | Read: claim, returns the winner's ID and clears its pending bit. Write: complete, names the ID that is done. Source ID. |
Examples
Example 1
The Good Chip- Input
one run
- Output
console "timer and gpio apart"; pass
The timer's interrupt runs only its own handler; GPIO's runs only for an edge.
Example 2
The Faulty Chip- Input
one run
- Output
a fail word
When the timer matches, GPIO's handler runs too. The test sees a handler that should not have run.
Example 3
What Does Not Count- Input
a test that hangs
- Output
not a catch
A wait for the edge with no limit never ends on the faulty chip; the judge needs a visible failure.
Constraints and Contract
- C firmware with the kit, SRAM layout.
- The good chip runs first and must pass with the console line; the faulty chip must then fail visibly.
Hints
Hint 1
On the faulty chip, what does ap_plic see when the timer matches and both sources are enabled?
Hint 2
Which handler would run, and how would your test know it should not have?
Hint 3
A wait that never ends is not a failure the judge can see.
What the grader checks: Your firmware runs on the good chip, which must pass with the console line. Then it runs on the stated faulty chip, which must fail visibly.
1 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