irq.h 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #ifndef IRQ_H
  2. #define IRQ_H
  3. #include "compiler.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_DECL(x) \
  8. void __hot __text_hot irqhandler_ ##x (unsigned int vector __unused, \
  9. size_t pc __unused)
  10. #define IRQHANDLER(x) \
  11. IRQHANDLER_DECL(x); \
  12. IRQHANDLER_DECL(x)
  13. typedef unsigned int irqmask_t;
  14. static inline irqmask_t disable_irqs(void)
  15. {
  16. return p_maskirq(~0U, 0);
  17. }
  18. static inline irqmask_t restore_irqs(irqmask_t mask)
  19. {
  20. return p_maskirq(mask, 0);
  21. }
  22. static inline irqmask_t restore_irq(irqmask_t mask, unsigned int vector)
  23. {
  24. const irqmask_t bit = 1U << vector;
  25. return p_maskirq(mask & bit, ~bit);
  26. }
  27. static inline irqmask_t mask_irqs(irqmask_t mask)
  28. {
  29. return p_maskirq(mask, ~mask);
  30. }
  31. static inline irqmask_t mask_irq(unsigned int vector)
  32. {
  33. return mask_irqs(1U << vector);
  34. }
  35. static inline irqmask_t unmask_irqs(irqmask_t mask)
  36. {
  37. return p_maskirq(0, ~mask);
  38. }
  39. static inline irqmask_t unmask_irq(unsigned int vector)
  40. {
  41. return unmask_irqs(1U << vector);
  42. }
  43. static inline irqmask_t irqmask(void)
  44. {
  45. return p_maskirq(0, ~0);
  46. }
  47. static inline irqmask_t waitfor(unsigned int vector)
  48. {
  49. const irqmask_t mask = 1U << vector;
  50. return p_waitirq(mask, 0);
  51. }
  52. /* Wait for any enabled IRQ */
  53. static inline irqmask_t wait_for_irq(void)
  54. {
  55. const irqmask_t mask = irqmask();
  56. return p_waitirq(mask, mask);
  57. }
  58. size_t rdxreg(unsigned int reg);
  59. void wrxreg(unsigned int reg, size_t val);
  60. #endif /* IRQ_H */