HwiP.h 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. /*
  2. * Copyright (c) 2015-2017, Texas Instruments Incorporated
  3. * All rights reserved.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions
  7. * are met:
  8. *
  9. * * Redistributions of source code must retain the above copyright
  10. * notice, this list of conditions and the following disclaimer.
  11. *
  12. * * Redistributions in binary form must reproduce the above copyright
  13. * notice, this list of conditions and the following disclaimer in the
  14. * documentation and/or other materials provided with the distribution.
  15. *
  16. * * Neither the name of Texas Instruments Incorporated nor the names of
  17. * its contributors may be used to endorse or promote products derived
  18. * from this software without specific prior written permission.
  19. *
  20. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  21. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  22. * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  23. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  24. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  25. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  26. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
  27. * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  28. * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
  29. * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  30. * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  31. */
  32. /** ============================================================================
  33. * @file HwiP.h
  34. *
  35. * @brief Hardware Interrupt module for the RTOS Porting Interface
  36. *
  37. * The ::HwiP_disable/::HwiP_restore APIs can be called recursively. The order
  38. * of the HwiP_restore calls, must be in reversed order. For example:
  39. * @code
  40. * uintptr_t key1, key2;
  41. * key1 = HwiP_disable();
  42. * key2 = HwiP_disable();
  43. * HwiP_restore(key2);
  44. * HwiP_restore(key1);
  45. * @endcode
  46. *
  47. * ============================================================================
  48. */
  49. #ifndef ti_osal_HwiP__include
  50. #define ti_osal_HwiP__include
  51. #ifdef __cplusplus
  52. extern "C" {
  53. #endif
  54. #include <stdint.h>
  55. #include <stdbool.h>
  56. #include <stddef.h>
  57. /*!
  58. * @brief Opaque client reference to an instance of a HwiP
  59. *
  60. * A HwiP_Handle returned from the ::HwiP_create represents that instance.
  61. */
  62. typedef void *HwiP_Handle;
  63. /*!
  64. * @brief Status codes for HwiP APIs
  65. */
  66. typedef enum HwiP_Status_e {
  67. HwiP_OK = 0,
  68. HwiP_FAILURE = (-(int32_t)1)
  69. } HwiP_Status;
  70. /**
  71. * @brief Enumerates the types different trigger types.
  72. * Please refer to Section 4.3.13 Interrupt Configuration Registers, GICD_ICFGRn
  73. * of ARM® Generic Interrupt Controller Architecture version 2.0
  74. * Architecture Specification document for details.
  75. */
  76. typedef enum
  77. {
  78. /**< Corresponding interrupt is level-sensitive */
  79. OSAL_ARM_GIC_TRIG_TYPE_LEVEL = 1,
  80. /**< Corresponding interrupt is edge */
  81. OSAL_ARM_GIC_TRIG_TYPE_EDGE = 2,
  82. /**< Coressponding interrupt is high level sensitive */
  83. OSAL_ARM_GIC_TRIG_TYPE_HIGH_LEVEL = 3,
  84. /**< Coressponding interrupt is low level sensitive */
  85. OSAL_ARM_GIC_TRIG_TYPE_LOW_LEVEL = 4,
  86. /**< Coressponding interrupt is rising edge sensitive */
  87. OSAL_ARM_GIC_TRIG_TYPE_RISING_EDGE = 5,
  88. /**< Coressponding interrupt is falling edge sensitive */
  89. OSAL_ARM_GIC_TRIG_TYPE_FALLING_EDGE = 6
  90. } OSAL_armGicTrigType_t;
  91. /*!
  92. * @brief Prototype for the entry function for a hardware interrupt
  93. */
  94. typedef void (*HwiP_Fxn)(uintptr_t arg);
  95. /*!
  96. * @brief Basic HwiP Parameters
  97. *
  98. * Structure that contains the parameters passed into ::HwiP_create
  99. * when creating a HwiP instance. The ::HwiP_Params_init function should
  100. * be used to initialize the fields to default values before the application sets
  101. * the fields manually. The HwiP default parameters are noted in
  102. * HwiP_Params_init.
  103. */
  104. typedef struct HwiP_Params_s {
  105. char *name; /*!< Name of the clock instance. Memory must
  106. persist for the life of the clock instance.
  107. This can be used for debugging purposes, or
  108. set to NULL if not needed. */
  109. uintptr_t arg; /*!< Argument passed into the Hwi function. */
  110. uint32_t priority; /*!< Device specific priority. */
  111. uint32_t evtId; /*!< Event Id associated */
  112. #if defined (__ARM_ARCH_7A__)
  113. uint32_t triggerSensitivity; /*!< Set an interrupt's trigger sensitivity for
  114. ARM cortex-A Generic Interrupt Controller(GIC)
  115. v2.0 specific implementations as @ref OSAL_armGicTrigType_t
  116. */
  117. #endif
  118. } HwiP_Params;
  119. /*!
  120. * @brief Function to clear a single interrupt
  121. *
  122. * @param interruptNum interrupt number to clear
  123. */
  124. extern void HwiP_clearInterrupt(int32_t interruptNum);
  125. /*!
  126. * @brief Function to create an interrupt on CortexM devices
  127. *
  128. * @param interruptNum Interrupt Vector Id
  129. *
  130. * @param hwiFxn entry function of the hardware interrupt
  131. *
  132. * @param params Pointer to the instance configuration parameters. NULL
  133. * denotes to use the default parameters. The HwiP default
  134. * parameters are noted in ::HwiP_Params_init.
  135. *
  136. * @return
  137. */
  138. extern HwiP_Handle HwiP_create(int32_t interruptNum, HwiP_Fxn hwiFxn,
  139. HwiP_Params *params);
  140. /*!
  141. * @brief Function to delete an interrupt on CortexM devices
  142. *
  143. * @param handle returned from the HwiP_create call
  144. *
  145. * @return A HwiP_Handle on success or a NULL
  146. */
  147. extern HwiP_Status HwiP_delete(HwiP_Handle handle);
  148. /*!
  149. * @brief Function to disable interrupts to enter a critical region
  150. *
  151. * This function can be called multiple times, but must unwound in the reverse
  152. * order. For example
  153. * @code
  154. * uintptr_t key1, key2;
  155. * key1 = HwiP_disable();
  156. * key2 = HwiP_disable();
  157. * HwiP_restore(key2);
  158. * HwiP_restore(key1);
  159. * @endcode
  160. *
  161. * @return A key that must be passed to HwiP_restore to re-enable interrupts.
  162. */
  163. extern uintptr_t HwiP_disable(void);
  164. /*!
  165. * @brief Function to disable a single interrupt
  166. *
  167. * @param interruptNum interrupt number to disable
  168. */
  169. extern void HwiP_disableInterrupt(int32_t interruptNum);
  170. /*!
  171. * @brief Function to enable a single interrupt
  172. *
  173. * @param interruptNum interrupt number to enable
  174. */
  175. extern void HwiP_enableInterrupt(int32_t interruptNum);
  176. /*!
  177. * @brief Initialize params structure to default values.
  178. *
  179. * The default parameters are:
  180. * - name: NULL
  181. * - arg: 0
  182. * - priority: ~0
  183. *
  184. * @param params Pointer to the instance configuration parameters.
  185. */
  186. extern void HwiP_Params_init(HwiP_Params *params);
  187. /*!
  188. * @brief Function to restore interrupts to exit a critical region
  189. *
  190. * @param key return from HwiP_disable
  191. */
  192. extern void HwiP_restore(uintptr_t key);
  193. /*!
  194. * @brief Function to get HwiP Handle from an interrupt number
  195. *
  196. * @param interruptNum the interrupt number
  197. */
  198. HwiP_Handle HwiP_getHandle(int32_t interruptNum);
  199. /*!
  200. * @brief Function to get the eventId associated with an interrupt number
  201. *
  202. * @param interruptNum the interrupt number
  203. */
  204. int32_t HwiP_getEventId(int32_t interruptNum);
  205. #ifdef __cplusplus
  206. }
  207. #endif
  208. #endif /* ti_osal_HwiP__include */