irq.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #ifndef IRQ_H
  2. #define IRQ_H
  3. #include "compiler.h"
  4. #include "picorv32.h"
  5. #include "iodevs.h" /* For _IRQ constants */
  6. typedef void (*irqhandler_t)(unsigned int vector, size_t pc);
  7. extern irqhandler_t __irq_handler_table[];
  8. #define IRQHANDLER_DECL(x,n) \
  9. void irqhandler_##x##_##n (unsigned int vector __unused, \
  10. size_t pc __unused)
  11. #define IRQHANDLER(x,n) \
  12. IRQHANDLER_DECL(x,n); \
  13. __hot __text_hot IRQHANDLER_DECL(x,n)
  14. typedef unsigned int irqmask_t;
  15. /* Disable IRQs except fatal system errors (to facilitate debugging) */
  16. static inline irqmask_t disable_irqs(void)
  17. {
  18. return p_maskirq(~((1 << EBREAK_IRQ)|(1 << BUSERR_IRQ)), 0);
  19. }
  20. static inline irqmask_t restore_irqs(irqmask_t mask)
  21. {
  22. return p_maskirq(mask, 0);
  23. }
  24. static inline irqmask_t restore_irq(irqmask_t mask, unsigned int vector)
  25. {
  26. const irqmask_t bit = 1U << vector;
  27. return p_maskirq(mask & bit, ~bit);
  28. }
  29. static inline irqmask_t mask_irqs(irqmask_t mask)
  30. {
  31. return p_maskirq(mask, ~mask);
  32. }
  33. static inline irqmask_t mask_irq(unsigned int vector)
  34. {
  35. return mask_irqs(1U << vector);
  36. }
  37. static inline irqmask_t unmask_irqs(irqmask_t mask)
  38. {
  39. return p_maskirq(0, ~mask);
  40. }
  41. static inline irqmask_t unmask_irq(unsigned int vector)
  42. {
  43. return unmask_irqs(1U << vector);
  44. }
  45. static inline irqmask_t irqmask(void)
  46. {
  47. return p_maskirq(0, ~0);
  48. }
  49. static inline irqmask_t waitfor(unsigned int vector)
  50. {
  51. const irqmask_t mask = 1U << vector;
  52. return p_waitirq(mask, 0);
  53. }
  54. /* Wait for any enabled IRQ */
  55. static inline irqmask_t wait_for_irq(void)
  56. {
  57. const irqmask_t mask = irqmask();
  58. return p_waitirq(mask, mask);
  59. }
  60. size_t rdxreg(unsigned int reg);
  61. void wrxreg(unsigned int reg, size_t val);
  62. #endif /* IRQ_H */