1 /*
2 * Copyright (c) 2016, Freescale Semiconductor, Inc.
3 * Copyright 2016-2017, 2020, 2022 NXP
4 * All rights reserved.
5 *
6 * SPDX-License-Identifier: BSD-3-Clause
7 */
8
9 #ifndef _FSL_GINT_H_
10 #define _FSL_GINT_H_
11
12 #include "fsl_common.h"
13
14 /*!
15 * @addtogroup gint_driver
16 * @{
17 */
18
19 /*! @file */
20
21 /*******************************************************************************
22 * Definitions
23 ******************************************************************************/
24
25 /*! @name Driver version */
26 /*@{*/
27 #define FSL_GINT_DRIVER_VERSION (MAKE_VERSION(2, 1, 0)) /*!< Driver version. */
28 /*@}*/
29
30 /*! @brief GINT combine inputs type */
31 typedef enum _gint_comb
32 {
33 kGINT_CombineOr = 0U, /*!< A grouped interrupt is generated when any one of the enabled inputs is active */
34 kGINT_CombineAnd = 1U /*!< A grouped interrupt is generated when all enabled inputs are active */
35 } gint_comb_t;
36
37 /*! @brief GINT trigger type */
38 typedef enum _gint_trig
39 {
40 kGINT_TrigEdge = 0U, /*!< Edge triggered based on polarity */
41 kGINT_TrigLevel = 1U /*!< Level triggered based on polarity */
42 } gint_trig_t;
43
44 /* @brief GINT port type */
45 typedef enum _gint_port
46 {
47 kGINT_Port0 = 0U,
48 #if !(defined(FSL_FEATURE_GINT_PORT_COUNT) && (FSL_FEATURE_GINT_PORT_COUNT <= 1U))
49 kGINT_Port1 = 1U,
50 #endif
51 #if defined(FSL_FEATURE_GINT_PORT_COUNT) && (FSL_FEATURE_GINT_PORT_COUNT > 2U)
52 kGINT_Port2 = 2U,
53 #endif
54 #if defined(FSL_FEATURE_GINT_PORT_COUNT) && (FSL_FEATURE_GINT_PORT_COUNT > 3U)
55 kGINT_Port3 = 3U,
56 #endif
57 #if defined(FSL_FEATURE_GINT_PORT_COUNT) && (FSL_FEATURE_GINT_PORT_COUNT > 4U)
58 kGINT_Port4 = 4U,
59 #endif
60 #if defined(FSL_FEATURE_GINT_PORT_COUNT) && (FSL_FEATURE_GINT_PORT_COUNT > 5U)
61 kGINT_Port5 = 5U,
62 #endif
63 #if defined(FSL_FEATURE_GINT_PORT_COUNT) && (FSL_FEATURE_GINT_PORT_COUNT > 6U)
64 kGINT_Port6 = 6U,
65 #endif
66 #if defined(FSL_FEATURE_GINT_PORT_COUNT) && (FSL_FEATURE_GINT_PORT_COUNT > 7U)
67 kGINT_Port7 = 7U,
68 #endif
69 } gint_port_t;
70
71 /*! @brief GINT Callback function. */
72 typedef void (*gint_cb_t)(void);
73
74 /*******************************************************************************
75 * API
76 ******************************************************************************/
77
78 #if defined(__cplusplus)
79 extern "C" {
80 #endif
81
82 /*!
83 * @brief Initialize GINT peripheral.
84
85 * This function initializes the GINT peripheral and enables the clock.
86 *
87 * @param base Base address of the GINT peripheral.
88 *
89 * @retval None.
90 */
91 void GINT_Init(GINT_Type *base);
92
93 /*!
94 * @brief Setup GINT peripheral control parameters.
95
96 * This function sets the control parameters of GINT peripheral.
97 *
98 * @param base Base address of the GINT peripheral.
99 * @param comb Controls if the enabled inputs are logically ORed or ANDed for interrupt generation.
100 * @param trig Controls if the enabled inputs are level or edge sensitive based on polarity.
101 * @param callback This function is called when configured group interrupt is generated.
102 *
103 * @retval None.
104 */
105 void GINT_SetCtrl(GINT_Type *base, gint_comb_t comb, gint_trig_t trig, gint_cb_t callback);
106
107 /*!
108 * @brief Get GINT peripheral control parameters.
109
110 * This function returns the control parameters of GINT peripheral.
111 *
112 * @param base Base address of the GINT peripheral.
113 * @param comb Pointer to store combine input value.
114 * @param trig Pointer to store trigger value.
115 * @param callback Pointer to store callback function.
116 *
117 * @retval None.
118 */
119 void GINT_GetCtrl(GINT_Type *base, gint_comb_t *comb, gint_trig_t *trig, gint_cb_t *callback);
120
121 /*!
122 * @brief Configure GINT peripheral pins.
123
124 * This function enables and controls the polarity of enabled pin(s) of a given port.
125 *
126 * @param base Base address of the GINT peripheral.
127 * @param port Port number.
128 * @param polarityMask Each bit position selects the polarity of the corresponding enabled pin.
129 * 0 = The pin is active LOW. 1 = The pin is active HIGH.
130 * @param enableMask Each bit position selects if the corresponding pin is enabled or not.
131 * 0 = The pin is disabled. 1 = The pin is enabled.
132 *
133 * @retval None.
134 */
135 void GINT_ConfigPins(GINT_Type *base, gint_port_t port, uint32_t polarityMask, uint32_t enableMask);
136
137 /*!
138 * @brief Get GINT peripheral pin configuration.
139
140 * This function returns the pin configuration of a given port.
141 *
142 * @param base Base address of the GINT peripheral.
143 * @param port Port number.
144 * @param polarityMask Pointer to store the polarity mask Each bit position indicates the polarity of the corresponding
145 enabled pin.
146 * 0 = The pin is active LOW. 1 = The pin is active HIGH.
147 * @param enableMask Pointer to store the enable mask. Each bit position indicates if the corresponding pin is enabled
148 or not.
149 * 0 = The pin is disabled. 1 = The pin is enabled.
150 *
151 * @retval None.
152 */
153 void GINT_GetConfigPins(GINT_Type *base, gint_port_t port, uint32_t *polarityMask, uint32_t *enableMask);
154
155 /*!
156 * @brief Enable callback.
157
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 /*!
168 * @brief Disable callback.
169
170 * This function disables the interrupt for the selected GINT peripheral. Although the pins are still
171 * being monitored but the callback function is not called.
172 *
173 * @param base Base address of the peripheral.
174 *
175 * @retval None.
176 */
177 void GINT_DisableCallback(GINT_Type *base);
178
179 /*!
180 * @brief Clear GINT status.
181
182 * This function clears the GINT status bit.
183 *
184 * @param base Base address of the GINT peripheral.
185 *
186 * @retval None.
187 */
GINT_ClrStatus(GINT_Type * base)188 static inline void GINT_ClrStatus(GINT_Type *base)
189 {
190 base->CTRL |= GINT_CTRL_INT_MASK;
191 }
192
193 /*!
194 * @brief Get GINT status.
195
196 * This function returns the GINT status.
197 *
198 * @param base Base address of the GINT peripheral.
199 *
200 * @retval status = 0 No group interrupt request. = 1 Group interrupt request active.
201 */
GINT_GetStatus(GINT_Type * base)202 static inline uint32_t GINT_GetStatus(GINT_Type *base)
203 {
204 return (base->CTRL & GINT_CTRL_INT_MASK);
205 }
206
207 /*!
208 * @brief Deinitialize GINT peripheral.
209
210 * This function disables the GINT clock.
211 *
212 * @param base Base address of the GINT peripheral.
213 *
214 * @retval None.
215 */
216 void GINT_Deinit(GINT_Type *base);
217
218 #ifdef __cplusplus
219 }
220 #endif
221
222 /*@}*/
223
224 #endif /* _FSL_GINT_H_ */
225