-
Notifications
You must be signed in to change notification settings - Fork 5
/
interrupts.c
47 lines (36 loc) · 959 Bytes
/
interrupts.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include "libci20/interrupts.h"
#include "libci20/uart.h"
#include "inttypes.h"
/* Interrupt dispatch table */
#define IRQ_COUNT 64
static irqhandler handlers[IRQ_COUNT];
void intc_register_handler_raw(int index, irqhandler handler)
{
handlers[index] = handler;
}
static void intc_dummy_handler(void)
{
uart_print("Ignoring unexpected interrupt!\r\n");
}
void intc_init(void)
{
for(int i = 0; i < IRQ_COUNT; i++)
intc_register_handler_raw(i, intc_dummy_handler);
}
/* Helper function for main interrupt dispatch routine */
static inline void libci20_interrupt_dispatch_bank(int offset)
{
uint32_t pending = peek32(INTC_ICPR0 + offset);
int idx;
while((idx = __builtin_ffs(pending))) {
idx --;
handlers[idx + offset]();
pending &= ~(1 << idx);
}
}
/* Main interrupt dispatch routine, called from asm (see kernel/start.S) */
void libci20_interrupt(void)
{
libci20_interrupt_dispatch_bank(0);
libci20_interrupt_dispatch_bank(0x20);
}