2
0

irq.c 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #include "picorv32.h"
  2. #include "fw.h"
  3. #include "console.h"
  4. /* Invalid interrupt */
  5. static void spurious_irq_handler(unsigned int vector)
  6. {
  7. con_printf("spurious interrupt: %u\n", vector);
  8. mask_irq(vector);
  9. }
  10. /* Valid edge-triggered interrupt just to wake up waitirq */
  11. void null_irq_handler(unsigned int vector)
  12. {
  13. }
  14. irq_handler_t __irq_handler_table[IRQ_VECTORS] =
  15. { [0 ... IRQ_VECTORS-1] = spurious_irq_handler };
  16. irq_handler_t register_irq(unsigned int vector, irq_handler_t handler,
  17. bool enable)
  18. {
  19. irq_handler_t old_handler;
  20. if (vector >= IRQ_VECTORS)
  21. return NULL; /* Invalid vector */
  22. mask_irq(vector);
  23. if (!handler) {
  24. enable = false;
  25. handler = spurious_irq_handler;
  26. }
  27. old_handler = __irq_handler_table[vector];
  28. __irq_handler_table[vector] = handler;
  29. if (enable)
  30. unmask_irq(vector);
  31. if (old_handler == spurious_irq_handler)
  32. old_handler = NULL;
  33. con_printf("irq: register vector %u, handler = %p, mask = %08x\n",
  34. vector, handler, irqmask());
  35. return old_handler;
  36. }