V0.2.2 Fix the Interrupt Acknowledge

MediumFix25 minVerilator + your C over DPI · serverReview the topic

Repair two GPIO helpers: one uses read-modify-write on a write-1-to-clear register, the other overwrites a register it shares.

Hardware context: Host-native models of ap_sysctl PINMUX and the GPIO interrupt words of ap_soc. An interrupt handler that acknowledges one GPIO pin without losing the others.

A chip test enables GPIO interrupts pin by pin and acknowledges each one in its handler. With three pins pending, the handler serves pin 3, and the other two interrupts vanish. A second bug hides behind the first: enabling pin 4 turns pin 0 off.

Fix gpio_ack and gpio_irq_enable in the file below. Keep their names and arguments. Pins are 0 to 15.

Full specification
AddressRegisterReadWrite
0x1000_1018GPIO IRQ ENABLEthe enablesthe new enables (1 lets that pin raise the request)
0x1000_1024GPIO STATUSthe edge flags, one per pina 1 clears that pin's flag; a 0 leaves it
hal.h (given, read only)
/* hal.h: register access for chip tests (ASIC Point, SoC Verification V0).
 * Host-native build: every call is one bus transfer, carried to the bench over DPI.
 * On the chip, the same two functions are volatile pointer accesses (lesson V0.1). */
#ifndef HAL_H
#define HAL_H
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
int bus_read(int addr);              /* provided by the bench */
void bus_write(int addr, int data);  /* provided by the bench */
#ifdef __cplusplus
}
#endif
static inline uint32_t reg_read32(uint32_t addr) { return (uint32_t)bus_read((int)addr); }
static inline void reg_write32(uint32_t addr, uint32_t value) { bus_write((int)addr, (int)value); }
#endif
gpio_task.h (given, read only)
/* gpio_task.h: the function you write. */
#ifndef GPIO_TASK_H
#define GPIO_TASK_H
#include "hal.h"
#ifdef __cplusplus
extern "C" {
#endif
void gpio_ack(int pin);
void gpio_irq_enable(int pin);
#ifdef __cplusplus
}
#endif
#endif

Examples

Example 1

Acknowledge Pin 3 of Three Pending
Input
STATUS = 0x0109, IRQ ENABLE = 0x0109; gpio_ack(3)
Output
register_after = 0x101, other_register_changed = 0x0, bad_accesses = 0

Flags 0109 are pins 0, 3 and 8. Serving pin 3 must leave 0101.

Example 2

Enable Pin 4 Beside Pin 0
Input
STATUS = 0x0000, IRQ ENABLE = 0x0001; gpio_irq_enable(4)
Output
register_after = 0x11, other_register_changed = 0x0, bad_accesses = 0

Enables 0001 plus pin 4 must give 0011.

Example 3

Acknowledge the Only Pending Pin
Input
STATUS = 0x0004, IRQ ENABLE = 0x0004; gpio_ack(2)
Output
register_after = 0x0, other_register_changed = 0x0, bad_accesses = 0

Only pin 2 is pending; after the acknowledge no flag is left.

Constraints and Contract

  • gpio_ack(pin) clears exactly that pin's flag. gpio_irq_enable(pin) sets exactly that pin's enable. Neither may change the other register or touch any other address.
  • Each case packs the register the call is about, after the call (16 bits). Then comes a byte that is E0 if the other register changed.
  • The last byte counts accesses to other addresses.

Hints

Hint 1

On STATUS, a write is a list of flags to clear. Writing back what you read clears every flag that was set.

Hint 2

IRQ ENABLE is shared by all pins. A plain write of one bit turns the others off.

Hint 3

One of the two functions needs a read; the other must not use one.

What the grader checks: A host-native bench with a register model of the two GPIO words. It checks the registers after each call, not the interrupt line.

11 checks on Verilator + your C over DPI · server. Run the examples first, then check the full regression. Full checks use the server judge. Downloads contain public samples only. 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

Acknowledge Pin 3 of Three Pending

Input
STATUS = 0x0109, IRQ ENABLE = 0x0109; gpio_ack(3)
Expected output
register_after = 0x101, other_register_changed = 0x0, bad_accesses = 0

Flags 0109 are pins 0, 3 and 8. Serving pin 3 must leave 0101.

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

Verilator + your C over DPI · server