HAL Interrupt Controller
An interrupt controller is represented by the chi_interrupt_t structure and provides methods to register handlers, enable/disable lines, acknowledge events, and dispatch.
-
typedef void (*chi_irq_handler_t)(int irq, void *arg)
IRQ handler function type.
Handlers registered via
register_handlerwill be invoked with the IRQ number and a user-provided context pointer.- Param irq:
Interrupt number.
- Param arg:
User-provided context pointer.
-
struct chi_interrupt
- #include <interrupt_api.h>
Represents a generic interrupt controller.
Forward declaration of the interrupt controller instance.
Holds the API function pointers, the optional MMIO base address, and any controller-specific configuration.
-
struct chi_interrupt_api
- #include <interrupt_api.h>
Defines function pointers for interrupt-controller operations.
Forward declaration of the interrupt API structure.
This API covers initialization, handler registration, enabling/disabling IRQ lines, priority setting, acknowledgement, and optional dispatch.
Public Members
-
int (*init)(const chi_interrupt_t *ctrl)
Initialize the interrupt controller.
Perform any hardware setup needed before use.
- Param ctrl:
Controller instance.
- Return:
0 on success, negative on failure.
-
int (*register_handler)(const chi_interrupt_t *ctrl, int irq, chi_irq_handler_t h, void *arg)
Register or replace an IRQ handler.
Associates a handler function with a given interrupt number.
- Param ctrl:
Controller instance.
- Param irq:
Interrupt number.
- Param h:
Handler function.
- Param arg:
Context pointer for handler.
- Return:
0 on success, negative on failure.
-
int (*enable_irq)(const chi_interrupt_t *ctrl, int irq)
Enable a specific IRQ line.
- Param ctrl:
Controller instance.
- Param irq:
Interrupt number.
- Return:
0 on success, negative on failure.
-
int (*disable_irq)(const chi_interrupt_t *ctrl, int irq)
Disable a specific IRQ line.
- Param ctrl:
Controller instance.
- Param irq:
Interrupt number.
- Return:
0 on success, negative on failure.
-
int (*set_priority)(const chi_interrupt_t *ctrl, int irq, int prio)
Set the priority of an IRQ (if supported).
Some controllers (PLIC, CLIC) support configurable priorities.
- Param ctrl:
Controller instance.
- Param irq:
Interrupt number.
- Param prio:
Priority level.
- Return:
0 on success, -ENOSYS if not supported.
-
int (*acknowledge)(const chi_interrupt_t *ctrl, int irq)
Acknowledge (clear) a pending IRQ.
Use for edge- or level-triggered interrupts.
- Param ctrl:
Controller instance.
- Param irq:
Interrupt number.
- Return:
0 on success, negative on failure.
-
void (*dispatch)(const chi_interrupt_t *ctrl)
Dispatch pending IRQs (optional).
Some bare-metal setups drive interrupt handling in software via dispatch.
- Param ctrl:
Controller instance.
-
int (*init)(const chi_interrupt_t *ctrl)