irq.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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);
  7. extern irqhandler_t __irq_handler_table[];
  8. #define IRQHANDLER_DECL(x,n) \
  9. void irqhandler_##x##_##n (unsigned int vector __unused)
  10. #define IRQHANDLER(x,n) \
  11. IRQHANDLER_DECL(x,n); \
  12. __hot __text_hot IRQHANDLER_DECL(x,n)
  13. IRQHANDLER_DECL(spurious,0);
  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. #define IRQ_PC_REGISTER "s10"
  63. #define IRQ_VECTOR_MASK_REGISTER "s11"
  64. #endif /* IRQ_H */