1 #include <lunaix/isrm.h>
2 #include <lunaix/spike.h>
8 0~31: reserved for sys use (x32)
9 32~47: reserved for os use (x16)
10 48~ : free to allocate for external hardware use. (x208)
13 static char iv_bmp[(IV_EX_END - IV_BASE_END) / 8];
14 static isr_cb handlers[TOTAL_IV];
17 intr_routine_fallback(const isr_param* param);
22 for (size_t i = 0; i < TOTAL_IV; i++) {
23 handlers[i] = intr_routine_fallback;
28 __ivalloc_within(size_t a, size_t b, isr_cb handler)
30 a = (a - IV_BASE_END);
31 b = (b - IV_BASE_END);
35 for (size_t i = a / 8; i < b / 8; i++, k += 8) {
36 u8_t chunk = iv_bmp[i];
42 while ((chunk & 0x1) && k <= b) {
54 int iv = IV_BASE_END + i * 8 + j;
55 handlers[iv] = handler ? handler : intr_routine_fallback;
64 isrm_ivosalloc(isr_cb handler)
66 return __ivalloc_within(IV_BASE_END, IV_EX_BEGIN, handler);
70 isrm_ivexalloc(isr_cb handler)
72 return __ivalloc_within(IV_EX_BEGIN, IV_EX_END, handler);
80 if (iv >= IV_BASE_END) {
81 iv_bmp[(iv - IV_BASE_END) / 8] &= ~(1 << ((iv - IV_BASE_END) % 8));
84 handlers[iv] = intr_routine_fallback;
88 isrm_bindirq(int irq, isr_cb irq_handler)
91 if (!(iv = isrm_ivexalloc(irq_handler))) {
92 panickf("out of IV resource. (irq=%d)", irq);
93 return 0; // never reach
96 // fixed, edge trigged, polarity=high
97 intc_irq_attach(irq, iv, 0, IRQ_DEFAULT);
103 isrm_bindiv(int iv, isr_cb handler)
107 if (iv >= IV_BASE_END) {
108 iv_bmp[(iv - IV_BASE_END) / 8] |= 1 << ((iv - IV_BASE_END) % 8);
111 handlers[iv] = handler;