Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RFC: register new Interrupt Service Routine (ISR) funtions for additional interrupts #1807

Closed
hvegh opened this issue Oct 22, 2023 · 2 comments

Comments

@hvegh
Copy link

hvegh commented Oct 22, 2023

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);
}
@AndrewD
Copy link
Collaborator

AndrewD commented Oct 23, 2023

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.

@hvegh
Copy link
Author

hvegh commented Nov 10, 2023

Now made obsolete by the pull request Andrew is working on. #1815
Thanks!

@hvegh hvegh closed this as completed Nov 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants