irq.h 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #ifndef IRQ_H
  2. #define IRQ_H
  3. #include <stddef.h>
  4. #include "picorv32.h"
  5. typedef void (*irqhandler_t)(unsigned int vector, size_t pc);
  6. extern irqhandler_t __irq_handler_table[];
  7. #define IRQHANDLER(x) \
  8. void irqhandler_ ##x (unsigned int, size_t); \
  9. void irqhandler_ ##x (unsigned int vector __attribute__((unused)), \
  10. size_t pc __attribute__((unused)))
  11. typedef unsigned int irqmask_t;
  12. static inline irqmask_t disable_irqs(void)
  13. {
  14. return p_maskirq(~0U, 0);
  15. }
  16. static inline irqmask_t restore_irqs(irqmask_t mask)
  17. {
  18. return p_maskirq(mask, 0);
  19. }
  20. static inline irqmask_t restore_irq(irqmask_t mask, unsigned int vector)
  21. {
  22. const irqmask_t bit = 1U << vector;
  23. return p_maskirq(mask & bit, ~bit);
  24. }
  25. static inline irqmask_t mask_irqs(irqmask_t mask)
  26. {
  27. return p_maskirq(mask, ~mask);
  28. }
  29. static inline irqmask_t mask_irq(unsigned int vector)
  30. {
  31. return mask_irqs(1U << vector);
  32. }
  33. static inline irqmask_t unmask_irqs(irqmask_t mask)
  34. {
  35. return p_maskirq(0, ~mask);
  36. }
  37. static inline irqmask_t unmask_irq(unsigned int vector)
  38. {
  39. return unmask_irqs(1U << vector);
  40. }
  41. static inline irqmask_t irqmask(void)
  42. {
  43. return p_maskirq(0, ~0);
  44. }
  45. static inline irqmask_t waitfor(unsigned int vector)
  46. {
  47. const irqmask_t mask = 1U << vector;
  48. return p_waitirq(mask, 0);
  49. }
  50. /* Wait for any enabled IRQ */
  51. static inline irqmask_t wait_for_irq(void)
  52. {
  53. const irqmask_t mask = irqmask();
  54. return p_waitirq(mask, mask);
  55. }
  56. #endif /* IRQ_H */