RFC: register new Interrupt Service Routine (ISR) funtions for additional interrupts
hvegh opened this issue · comments
Dear Litex community,
Question: how to handle additional interrupts in software?
(I don't see currently an generic way of extending this. )
Currently the isr.c only handles the uart.
A possible API might look like:
int set_handler(unsigned int irq, void (*handler)(void));
void (*handler)(void) get_handler(unsigned int irq);
int remove_handler(unsigned int irq);
My hack for the moment is a callback function in the Litex isr routine shown below.
My little hack to extend the isr routine:
diff --git a/litex/soc/software/libbase/isr.c b/litex/soc/software/libbase/isr.c
index ac7a7920..898eb40a 100644
--- a/litex/soc/software/libbase/isr.c
+++ b/litex/soc/software/libbase/isr.c
@@ -191,6 +191,9 @@ void isr(void)
}
#else
+
+void (*isr_next)(unsigned int irqs) = NULL;
+
void isr(void)
{
__attribute__((unused)) unsigned int irqs;
@@ -203,6 +206,8 @@ void isr(void)
uart_isr();
#endif
#endif
+ if(isr_next)
+ (*isr_next)(irqs);
}
#endif
Code snippet using the callback function for my pps core:
extern void (*isr_next)(unsigned int irqs);
void isr_pps(unsigned int irqs)
{
if (irqs & (1 << PPS0_INTERRUPT)) {
// handle stuff
}
}
static void pps_init(void) {
isr_next = &isr_pps;
irq_setmask(irq_getmask() | (1 << PPS0_INTERRUPT));
pps0_ev_enable_write(1);
}
There is another pr for a different approach to this.
I've got a more traditional irq handler registration (proof of concept) in our tree I've been meaning to push for discussion.
Now made obsolete by the pull request Andrew is working on. #1815
Thanks!