irq_ctrl.h 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. /**************************************************************************//**
  2. * @file irq_ctrl.h
  3. * @brief Interrupt Controller API header file
  4. * @version V1.0.0
  5. * @date 23. June 2017
  6. ******************************************************************************/
  7. /*
  8. * Copyright (c) 2017 ARM Limited. All rights reserved.
  9. *
  10. * SPDX-License-Identifier: Apache-2.0
  11. *
  12. * Licensed under the Apache License, Version 2.0 (the License); you may
  13. * not use this file except in compliance with the License.
  14. * You may obtain a copy of the License at
  15. *
  16. * www.apache.org/licenses/LICENSE-2.0
  17. *
  18. * Unless required by applicable law or agreed to in writing, software
  19. * distributed under the License is distributed on an AS IS BASIS, WITHOUT
  20. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  21. * See the License for the specific language governing permissions and
  22. * limitations under the License.
  23. */
  24. #if defined ( __ICCARM__ )
  25. #pragma system_include /* treat file as system include file for MISRA check */
  26. #elif defined (__clang__)
  27. #pragma clang system_header /* treat file as system include file */
  28. #endif
  29. #ifndef IRQ_CTRL_H_
  30. #define IRQ_CTRL_H_
  31. #include <stdint.h>
  32. #ifndef IRQHANDLER_T
  33. #define IRQHANDLER_T
  34. /// Interrupt handler data type
  35. typedef void (*IRQHandler_t) (void);
  36. #endif
  37. #ifndef IRQN_ID_T
  38. #define IRQN_ID_T
  39. /// Interrupt ID number data type
  40. typedef int32_t IRQn_ID_t;
  41. #endif
  42. /* Interrupt mode bit-masks */
  43. #define IRQ_MODE_TRIG_Pos (0U)
  44. #define IRQ_MODE_TRIG_Msk (0x07UL /*<< IRQ_MODE_TRIG_Pos*/)
  45. #define IRQ_MODE_TRIG_LEVEL (0x00UL /*<< IRQ_MODE_TRIG_Pos*/) ///< Trigger: level triggered interrupt
  46. #define IRQ_MODE_TRIG_LEVEL_LOW (0x01UL /*<< IRQ_MODE_TRIG_Pos*/) ///< Trigger: low level triggered interrupt
  47. #define IRQ_MODE_TRIG_LEVEL_HIGH (0x02UL /*<< IRQ_MODE_TRIG_Pos*/) ///< Trigger: high level triggered interrupt
  48. #define IRQ_MODE_TRIG_EDGE (0x04UL /*<< IRQ_MODE_TRIG_Pos*/) ///< Trigger: edge triggered interrupt
  49. #define IRQ_MODE_TRIG_EDGE_RISING (0x05UL /*<< IRQ_MODE_TRIG_Pos*/) ///< Trigger: rising edge triggered interrupt
  50. #define IRQ_MODE_TRIG_EDGE_FALLING (0x06UL /*<< IRQ_MODE_TRIG_Pos*/) ///< Trigger: falling edge triggered interrupt
  51. #define IRQ_MODE_TRIG_EDGE_BOTH (0x07UL /*<< IRQ_MODE_TRIG_Pos*/) ///< Trigger: rising and falling edge triggered interrupt
  52. #define IRQ_MODE_TYPE_Pos (3U)
  53. #define IRQ_MODE_TYPE_Msk (0x01UL << IRQ_MODE_TYPE_Pos)
  54. #define IRQ_MODE_TYPE_IRQ (0x00UL << IRQ_MODE_TYPE_Pos) ///< Type: interrupt source triggers CPU IRQ line
  55. #define IRQ_MODE_TYPE_FIQ (0x01UL << IRQ_MODE_TYPE_Pos) ///< Type: interrupt source triggers CPU FIQ line
  56. #define IRQ_MODE_DOMAIN_Pos (4U)
  57. #define IRQ_MODE_DOMAIN_Msk (0x01UL << IRQ_MODE_DOMAIN_Pos)
  58. #define IRQ_MODE_DOMAIN_NONSECURE (0x00UL << IRQ_MODE_DOMAIN_Pos) ///< Domain: interrupt is targeting non-secure domain
  59. #define IRQ_MODE_DOMAIN_SECURE (0x01UL << IRQ_MODE_DOMAIN_Pos) ///< Domain: interrupt is targeting secure domain
  60. #define IRQ_MODE_CPU_Pos (5U)
  61. #define IRQ_MODE_CPU_Msk (0xFFUL << IRQ_MODE_CPU_Pos)
  62. #define IRQ_MODE_CPU_ALL (0x00UL << IRQ_MODE_CPU_Pos) ///< CPU: interrupt targets all CPUs
  63. #define IRQ_MODE_CPU_0 (0x01UL << IRQ_MODE_CPU_Pos) ///< CPU: interrupt targets CPU 0
  64. #define IRQ_MODE_CPU_1 (0x02UL << IRQ_MODE_CPU_Pos) ///< CPU: interrupt targets CPU 1
  65. #define IRQ_MODE_CPU_2 (0x04UL << IRQ_MODE_CPU_Pos) ///< CPU: interrupt targets CPU 2
  66. #define IRQ_MODE_CPU_3 (0x08UL << IRQ_MODE_CPU_Pos) ///< CPU: interrupt targets CPU 3
  67. #define IRQ_MODE_CPU_4 (0x10UL << IRQ_MODE_CPU_Pos) ///< CPU: interrupt targets CPU 4
  68. #define IRQ_MODE_CPU_5 (0x20UL << IRQ_MODE_CPU_Pos) ///< CPU: interrupt targets CPU 5
  69. #define IRQ_MODE_CPU_6 (0x40UL << IRQ_MODE_CPU_Pos) ///< CPU: interrupt targets CPU 6
  70. #define IRQ_MODE_CPU_7 (0x80UL << IRQ_MODE_CPU_Pos) ///< CPU: interrupt targets CPU 7
  71. #define IRQ_MODE_ERROR (0x80000000UL) ///< Bit indicating mode value error
  72. /* Interrupt priority bit-masks */
  73. #define IRQ_PRIORITY_Msk (0x0000FFFFUL) ///< Interrupt priority value bit-mask
  74. #define IRQ_PRIORITY_ERROR (0x80000000UL) ///< Bit indicating priority value error
  75. /// Initialize interrupt controller.
  76. /// \return 0 on success, -1 on error.
  77. int32_t IRQ_Initialize (void);
  78. /// Register interrupt handler.
  79. /// \param[in] irqn interrupt ID number
  80. /// \param[in] handler interrupt handler function address
  81. /// \return 0 on success, -1 on error.
  82. int32_t IRQ_SetHandler (IRQn_ID_t irqn, IRQHandler_t handler);
  83. /// Get the registered interrupt handler.
  84. /// \param[in] irqn interrupt ID number
  85. /// \return registered interrupt handler function address.
  86. IRQHandler_t IRQ_GetHandler (IRQn_ID_t irqn);
  87. /// Enable interrupt.
  88. /// \param[in] irqn interrupt ID number
  89. /// \return 0 on success, -1 on error.
  90. int32_t IRQ_Enable (IRQn_ID_t irqn);
  91. /// Disable interrupt.
  92. /// \param[in] irqn interrupt ID number
  93. /// \return 0 on success, -1 on error.
  94. int32_t IRQ_Disable (IRQn_ID_t irqn);
  95. /// Get interrupt enable state.
  96. /// \param[in] irqn interrupt ID number
  97. /// \return 0 - interrupt is disabled, 1 - interrupt is enabled.
  98. uint32_t IRQ_GetEnableState (IRQn_ID_t irqn);
  99. /// Configure interrupt request mode.
  100. /// \param[in] irqn interrupt ID number
  101. /// \param[in] mode mode configuration
  102. /// \return 0 on success, -1 on error.
  103. int32_t IRQ_SetMode (IRQn_ID_t irqn, uint32_t mode);
  104. /// Get interrupt mode configuration.
  105. /// \param[in] irqn interrupt ID number
  106. /// \return current interrupt mode configuration with optional IRQ_MODE_ERROR bit set.
  107. uint32_t IRQ_GetMode (IRQn_ID_t irqn);
  108. /// Get ID number of current interrupt request (IRQ).
  109. /// \return interrupt ID number.
  110. IRQn_ID_t IRQ_GetActiveIRQ (void);
  111. /// Get ID number of current fast interrupt request (FIQ).
  112. /// \return interrupt ID number.
  113. IRQn_ID_t IRQ_GetActiveFIQ (void);
  114. /// Signal end of interrupt processing.
  115. /// \param[in] irqn interrupt ID number
  116. /// \return 0 on success, -1 on error.
  117. int32_t IRQ_EndOfInterrupt (IRQn_ID_t irqn);
  118. /// Set interrupt pending flag.
  119. /// \param[in] irqn interrupt ID number
  120. /// \return 0 on success, -1 on error.
  121. int32_t IRQ_SetPending (IRQn_ID_t irqn);
  122. /// Get interrupt pending flag.
  123. /// \param[in] irqn interrupt ID number
  124. /// \return 0 - interrupt is not pending, 1 - interrupt is pending.
  125. uint32_t IRQ_GetPending (IRQn_ID_t irqn);
  126. /// Clear interrupt pending flag.
  127. /// \param[in] irqn interrupt ID number
  128. /// \return 0 on success, -1 on error.
  129. int32_t IRQ_ClearPending (IRQn_ID_t irqn);
  130. /// Set interrupt priority value.
  131. /// \param[in] irqn interrupt ID number
  132. /// \param[in] priority interrupt priority value
  133. /// \return 0 on success, -1 on error.
  134. int32_t IRQ_SetPriority (IRQn_ID_t irqn, uint32_t priority);
  135. /// Get interrupt priority.
  136. /// \param[in] irqn interrupt ID number
  137. /// \return current interrupt priority value with optional IRQ_PRIORITY_ERROR bit set.
  138. uint32_t IRQ_GetPriority (IRQn_ID_t irqn);
  139. /// Set priority masking threshold.
  140. /// \param[in] priority priority masking threshold value
  141. /// \return 0 on success, -1 on error.
  142. int32_t IRQ_SetPriorityMask (uint32_t priority);
  143. /// Get priority masking threshold
  144. /// \return current priority masking threshold value with optional IRQ_PRIORITY_ERROR bit set.
  145. uint32_t IRQ_GetPriorityMask (void);
  146. /// Set priority grouping field split point
  147. /// \param[in] bits number of MSB bits included in the group priority field comparison
  148. /// \return 0 on success, -1 on error.
  149. int32_t IRQ_SetPriorityGroupBits (uint32_t bits);
  150. /// Get priority grouping field split point
  151. /// \return current number of MSB bits included in the group priority field comparison with
  152. /// optional IRQ_PRIORITY_ERROR bit set.
  153. uint32_t IRQ_GetPriorityGroupBits (void);
  154. #endif // IRQ_CTRL_H_