fsl_gint.h 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. /*
  2. * The Clear BSD License
  3. * Copyright (c) 2016, Freescale Semiconductor, Inc.
  4. * Copyright 2016-2017 NXP
  5. * All rights reserved.
  6. *
  7. * Redistribution and use in source and binary forms, with or without modification,
  8. * are permitted (subject to the limitations in the disclaimer below) provided
  9. * that the following conditions are met:
  10. *
  11. * o Redistributions of source code must retain the above copyright notice, this list
  12. * of conditions and the following disclaimer.
  13. *
  14. * o Redistributions in binary form must reproduce the above copyright notice, this
  15. * list of conditions and the following disclaimer in the documentation and/or
  16. * other materials provided with the distribution.
  17. *
  18. * o Neither the name of the copyright holder nor the names of its
  19. * contributors may be used to endorse or promote products derived from this
  20. * software without specific prior written permission.
  21. *
  22. * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY THIS LICENSE.
  23. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  24. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  25. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  26. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
  27. * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  28. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  29. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  30. * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  31. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  32. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  33. */
  34. #ifndef _FSL_GINT_H_
  35. #define _FSL_GINT_H_
  36. #include "fsl_common.h"
  37. /*!
  38. * @addtogroup gint_driver
  39. * @{
  40. */
  41. /*! @file */
  42. /*******************************************************************************
  43. * Definitions
  44. ******************************************************************************/
  45. /*! @name Driver version */
  46. /*@{*/
  47. #define FSL_GINT_DRIVER_VERSION (MAKE_VERSION(2, 0, 0)) /*!< Version 2.0.0. */
  48. /*@}*/
  49. /*! @brief GINT combine inputs type */
  50. typedef enum _gint_comb
  51. {
  52. kGINT_CombineOr = 0U, /*!< A grouped interrupt is generated when any one of the enabled inputs is active */
  53. kGINT_CombineAnd = 1U /*!< A grouped interrupt is generated when all enabled inputs are active */
  54. } gint_comb_t;
  55. /*! @brief GINT trigger type */
  56. typedef enum _gint_trig
  57. {
  58. kGINT_TrigEdge = 0U, /*!< Edge triggered based on polarity */
  59. kGINT_TrigLevel = 1U /*!< Level triggered based on polarity */
  60. } gint_trig_t;
  61. /* @brief GINT port type */
  62. typedef enum _gint_port
  63. {
  64. kGINT_Port0 = 0U,
  65. kGINT_Port1 = 1U,
  66. #if defined(FSL_FEATURE_GINT_PORT_COUNT) && (FSL_FEATURE_GINT_PORT_COUNT > 2U)
  67. kGINT_Port2 = 2U,
  68. #endif
  69. #if defined(FSL_FEATURE_GINT_PORT_COUNT) && (FSL_FEATURE_GINT_PORT_COUNT > 3U)
  70. kGINT_Port3 = 3U,
  71. #endif
  72. #if defined(FSL_FEATURE_GINT_PORT_COUNT) && (FSL_FEATURE_GINT_PORT_COUNT > 4U)
  73. kGINT_Port4 = 4U,
  74. #endif
  75. #if defined(FSL_FEATURE_GINT_PORT_COUNT) && (FSL_FEATURE_GINT_PORT_COUNT > 5U)
  76. kGINT_Port5 = 5U,
  77. #endif
  78. #if defined(FSL_FEATURE_GINT_PORT_COUNT) && (FSL_FEATURE_GINT_PORT_COUNT > 6U)
  79. kGINT_Port6 = 6U,
  80. #endif
  81. #if defined(FSL_FEATURE_GINT_PORT_COUNT) && (FSL_FEATURE_GINT_PORT_COUNT > 7U)
  82. kGINT_Port7 = 7U,
  83. #endif
  84. } gint_port_t;
  85. /*! @brief GINT Callback function. */
  86. typedef void (*gint_cb_t)(void);
  87. /*******************************************************************************
  88. * API
  89. ******************************************************************************/
  90. #if defined(__cplusplus)
  91. extern "C" {
  92. #endif
  93. /*!
  94. * @brief Initialize GINT peripheral.
  95. * This function initializes the GINT peripheral and enables the clock.
  96. *
  97. * @param base Base address of the GINT peripheral.
  98. *
  99. * @retval None.
  100. */
  101. void GINT_Init(GINT_Type *base);
  102. /*!
  103. * @brief Setup GINT peripheral control parameters.
  104. * This function sets the control parameters of GINT peripheral.
  105. *
  106. * @param base Base address of the GINT peripheral.
  107. * @param comb Controls if the enabled inputs are logically ORed or ANDed for interrupt generation.
  108. * @param trig Controls if the enabled inputs are level or edge sensitive based on polarity.
  109. * @param callback This function is called when configured group interrupt is generated.
  110. *
  111. * @retval None.
  112. */
  113. void GINT_SetCtrl(GINT_Type *base, gint_comb_t comb, gint_trig_t trig, gint_cb_t callback);
  114. /*!
  115. * @brief Get GINT peripheral control parameters.
  116. * This function returns the control parameters of GINT peripheral.
  117. *
  118. * @param base Base address of the GINT peripheral.
  119. * @param comb Pointer to store combine input value.
  120. * @param trig Pointer to store trigger value.
  121. * @param callback Pointer to store callback function.
  122. *
  123. * @retval None.
  124. */
  125. void GINT_GetCtrl(GINT_Type *base, gint_comb_t *comb, gint_trig_t *trig, gint_cb_t *callback);
  126. /*!
  127. * @brief Configure GINT peripheral pins.
  128. * This function enables and controls the polarity of enabled pin(s) of a given port.
  129. *
  130. * @param base Base address of the GINT peripheral.
  131. * @param port Port number.
  132. * @param polarityMask Each bit position selects the polarity of the corresponding enabled pin.
  133. * 0 = The pin is active LOW. 1 = The pin is active HIGH.
  134. * @param enableMask Each bit position selects if the corresponding pin is enabled or not.
  135. * 0 = The pin is disabled. 1 = The pin is enabled.
  136. *
  137. * @retval None.
  138. */
  139. void GINT_ConfigPins(GINT_Type *base, gint_port_t port, uint32_t polarityMask, uint32_t enableMask);
  140. /*!
  141. * @brief Get GINT peripheral pin configuration.
  142. * This function returns the pin configuration of a given port.
  143. *
  144. * @param base Base address of the GINT peripheral.
  145. * @param port Port number.
  146. * @param polarityMask Pointer to store the polarity mask Each bit position indicates the polarity of the corresponding
  147. enabled pin.
  148. * 0 = The pin is active LOW. 1 = The pin is active HIGH.
  149. * @param enableMask Pointer to store the enable mask. Each bit position indicates if the corresponding pin is enabled
  150. or not.
  151. * 0 = The pin is disabled. 1 = The pin is enabled.
  152. *
  153. * @retval None.
  154. */
  155. void GINT_GetConfigPins(GINT_Type *base, gint_port_t port, uint32_t *polarityMask, uint32_t *enableMask);
  156. /*!
  157. * @brief Enable callback.
  158. * This function enables the interrupt for the selected GINT peripheral. Although the pin(s) are monitored
  159. * as soon as they are enabled, the callback function is not enabled until this function is called.
  160. *
  161. * @param base Base address of the GINT peripheral.
  162. *
  163. * @retval None.
  164. */
  165. void GINT_EnableCallback(GINT_Type *base);
  166. /*!
  167. * @brief Disable callback.
  168. * This function disables the interrupt for the selected GINT peripheral. Although the pins are still
  169. * being monitored but the callback function is not called.
  170. *
  171. * @param base Base address of the peripheral.
  172. *
  173. * @retval None.
  174. */
  175. void GINT_DisableCallback(GINT_Type *base);
  176. /*!
  177. * @brief Clear GINT status.
  178. * This function clears the GINT status bit.
  179. *
  180. * @param base Base address of the GINT peripheral.
  181. *
  182. * @retval None.
  183. */
  184. static inline void GINT_ClrStatus(GINT_Type *base)
  185. {
  186. base->CTRL |= GINT_CTRL_INT_MASK;
  187. }
  188. /*!
  189. * @brief Get GINT status.
  190. * This function returns the GINT status.
  191. *
  192. * @param base Base address of the GINT peripheral.
  193. *
  194. * @retval status = 0 No group interrupt request. = 1 Group interrupt request active.
  195. */
  196. static inline uint32_t GINT_GetStatus(GINT_Type *base)
  197. {
  198. return (base->CTRL & GINT_CTRL_INT_MASK);
  199. }
  200. /*!
  201. * @brief Deinitialize GINT peripheral.
  202. * This function disables the GINT clock.
  203. *
  204. * @param base Base address of the GINT peripheral.
  205. *
  206. * @retval None.
  207. */
  208. void GINT_Deinit(GINT_Type *base);
  209. #ifdef __cplusplus
  210. }
  211. #endif
  212. /*@}*/
  213. #endif /* _FSL_GINT_H_ */