irq.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /****************************************************************************
  2. * arch/risc-v/include/irq.h
  3. *
  4. * Licensed to the Apache Software Foundation (ASF) under one or more
  5. * contributor license agreements. See the NOTICE file distributed with
  6. * this work for additional information regarding copyright ownership. The
  7. * ASF licenses this file to you under the Apache License, Version 2.0 (the
  8. * "License"); you may not use this file except in compliance with the
  9. * License. You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing, software
  14. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  15. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  16. * License for the specific language governing permissions and limitations
  17. * under the License.
  18. *
  19. ****************************************************************************/
  20. /* This file should never be included directly but, rather, only indirectly
  21. * through nuttx/irq.h
  22. */
  23. #ifndef __ARCH_RISCV_INCLUDE_IRQ_H
  24. #define __ARCH_RISCV_INCLUDE_IRQ_H
  25. /****************************************************************************
  26. * Included Files
  27. ****************************************************************************/
  28. /* Include chip-specific IRQ definitions (including IRQ numbers) */
  29. #include <stdint.h>
  30. #include <nuttx/irq.h>
  31. #include <arch/csr.h>
  32. #include <arch/chip/irq.h>
  33. /* Include RISC-V architecture-specific IRQ definitions */
  34. #if defined(CONFIG_ARCH_RV32IM) || defined(CONFIG_ARCH_RV32I)
  35. # include <arch/rv32im/irq.h>
  36. #endif
  37. #if defined(CONFIG_ARCH_RV64GC)
  38. # include <arch/rv64gc/irq.h>
  39. #endif
  40. /****************************************************************************
  41. * Public Types
  42. ****************************************************************************/
  43. #ifndef __ASSEMBLY__
  44. /****************************************************************************
  45. * Public Data
  46. ****************************************************************************/
  47. #undef EXTERN
  48. #if defined(__cplusplus)
  49. #define EXTERN extern "C"
  50. extern "C"
  51. {
  52. #else
  53. #define EXTERN extern
  54. #endif
  55. /****************************************************************************
  56. * Inline Functions
  57. ****************************************************************************/
  58. /****************************************************************************
  59. * Name: up_irq_save
  60. *
  61. * Description:
  62. * Disable interrupts and return the previous value of the mstatus register
  63. *
  64. ****************************************************************************/
  65. static inline irqstate_t up_irq_save(void)
  66. {
  67. irqstate_t flags;
  68. /* Read mstatus & clear machine interrupt enable (MIE) in mstatus */
  69. __asm__ __volatile__
  70. (
  71. "csrrc %0, mstatus, %1\n"
  72. : "=r" (flags)
  73. : "r"(MSTATUS_MIE)
  74. : "memory"
  75. );
  76. /* Return the previous mstatus value so that it can be restored with
  77. * up_irq_restore().
  78. */
  79. return flags;
  80. }
  81. /****************************************************************************
  82. * Name: up_irq_restore
  83. *
  84. * Description:
  85. * Restore the value of the mstatus register
  86. *
  87. ****************************************************************************/
  88. static inline void up_irq_restore(irqstate_t flags)
  89. {
  90. __asm__ __volatile__
  91. (
  92. "csrw mstatus, %0\n"
  93. : /* no output */
  94. : "r" (flags)
  95. : "memory"
  96. );
  97. }
  98. /****************************************************************************
  99. * Public Function Prototypes
  100. ****************************************************************************/
  101. /****************************************************************************
  102. * Name: up_irq_enable
  103. *
  104. * Description:
  105. * Return the current interrupt state and enable interrupts
  106. *
  107. ****************************************************************************/
  108. EXTERN irqstate_t up_irq_enable(void);
  109. #undef EXTERN
  110. #if defined(__cplusplus)
  111. }
  112. #endif
  113. #endif /* __ASSEMBLY__ */
  114. #endif /* __ARCH_RISCV_INCLUDE_IRQ_H */