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];
15 static ptr_t ivhand_payload[TOTAL_IV];
18 intr_routine_fallback(const isr_param* param);
23 for (size_t i = 0; i < TOTAL_IV; i++) {
24 handlers[i] = intr_routine_fallback;
29 __ivalloc_within(size_t a, size_t b, isr_cb handler)
31 a = (a - IV_BASE_END);
32 b = (b - IV_BASE_END);
36 for (size_t i = a / 8; i < b / 8; i++, k += 8) {
37 u8_t chunk = iv_bmp[i];
43 while ((chunk & 0x1) && k <= b) {
55 int iv = IV_BASE_END + i * 8 + j;
56 handlers[iv] = handler ? handler : intr_routine_fallback;
65 isrm_ivosalloc(isr_cb handler)
67 return __ivalloc_within(IV_BASE_END, IV_EX_BEGIN, handler);
71 isrm_ivexalloc(isr_cb handler)
73 return __ivalloc_within(IV_EX_BEGIN, IV_EX_END, handler);
81 if (iv >= IV_BASE_END) {
82 iv_bmp[(iv - IV_BASE_END) / 8] &= ~(1 << ((iv - IV_BASE_END) % 8));
85 handlers[iv] = intr_routine_fallback;
89 isrm_bindirq(int irq, isr_cb irq_handler)
92 if (!(iv = isrm_ivexalloc(irq_handler))) {
93 panickf("out of IV resource. (irq=%d)", irq);
94 return 0; // never reach
97 // fixed, edge trigged, polarity=high
98 intc_irq_attach(irq, iv, 0, IRQ_DEFAULT);
104 isrm_bindiv(int iv, isr_cb handler)
108 if (iv >= IV_BASE_END) {
109 iv_bmp[(iv - IV_BASE_END) / 8] |= 1 << ((iv - IV_BASE_END) % 8);
112 handlers[iv] = handler;
124 isrm_get_payload(const isr_param* param)
126 int iv = param->execp->vector;
129 return ivhand_payload[iv];
133 isrm_set_payload(int iv, ptr_t payload)
137 ivhand_payload[iv] = payload;