2 * Copyright (c) 2016, Freescale Semiconductor, Inc.
\r
3 * Copyright 2016-2017 NXP
\r
4 * All rights reserved.
\r
6 * SPDX-License-Identifier: BSD-3-Clause
\r
10 #define _FSL_PINT_H_
\r
12 #include "fsl_common.h"
\r
15 * @addtogroup pint_driver
\r
21 /*******************************************************************************
\r
23 ******************************************************************************/
\r
25 /*! @name Driver version */
\r
27 #define FSL_PINT_DRIVER_VERSION (MAKE_VERSION(2, 1, 3)) /*!< Version 2.1.3 */
\r
30 /* Number of interrupt line supported by PINT */
\r
31 #define PINT_PIN_INT_COUNT 8U
\r
33 /* Number of interrupt line supported by SECURE PINT */
\r
34 #define SEC_PINT_PIN_INT_COUNT 2U
\r
36 /* Number of input sources supported by PINT */
\r
37 #define PINT_INPUT_COUNT 8U
\r
39 /* PININT Bit slice source register bits */
\r
40 #define PININT_BITSLICE_SRC_START 8U
\r
41 #define PININT_BITSLICE_SRC_MASK 7U
\r
43 /* PININT Bit slice configuration register bits */
\r
44 #define PININT_BITSLICE_CFG_START 8U
\r
45 #define PININT_BITSLICE_CFG_MASK 7U
\r
46 #define PININT_BITSLICE_ENDP_MASK 7U
\r
48 #define PINT_PIN_INT_LEVEL 0x10U
\r
49 #define PINT_PIN_INT_EDGE 0x00U
\r
50 #define PINT_PIN_INT_FALL_OR_HIGH_LEVEL 0x02U
\r
51 #define PINT_PIN_INT_RISE 0x01U
\r
52 #define PINT_PIN_RISE_EDGE (PINT_PIN_INT_EDGE | PINT_PIN_INT_RISE)
\r
53 #define PINT_PIN_FALL_EDGE (PINT_PIN_INT_EDGE | PINT_PIN_INT_FALL_OR_HIGH_LEVEL)
\r
54 #define PINT_PIN_BOTH_EDGE (PINT_PIN_INT_EDGE | PINT_PIN_INT_RISE | PINT_PIN_INT_FALL_OR_HIGH_LEVEL)
\r
55 #define PINT_PIN_LOW_LEVEL (PINT_PIN_INT_LEVEL)
\r
56 #define PINT_PIN_HIGH_LEVEL (PINT_PIN_INT_LEVEL | PINT_PIN_INT_FALL_OR_HIGH_LEVEL)
\r
58 /*! @brief PINT Pin Interrupt enable type */
\r
59 typedef enum _pint_pin_enable
\r
61 kPINT_PinIntEnableNone = 0U, /*!< Do not generate Pin Interrupt */
\r
62 kPINT_PinIntEnableRiseEdge = PINT_PIN_RISE_EDGE, /*!< Generate Pin Interrupt on rising edge */
\r
63 kPINT_PinIntEnableFallEdge = PINT_PIN_FALL_EDGE, /*!< Generate Pin Interrupt on falling edge */
\r
64 kPINT_PinIntEnableBothEdges = PINT_PIN_BOTH_EDGE, /*!< Generate Pin Interrupt on both edges */
\r
65 kPINT_PinIntEnableLowLevel = PINT_PIN_LOW_LEVEL, /*!< Generate Pin Interrupt on low level */
\r
66 kPINT_PinIntEnableHighLevel = PINT_PIN_HIGH_LEVEL /*!< Generate Pin Interrupt on high level */
\r
67 } pint_pin_enable_t;
\r
69 /*! @brief PINT Pin Interrupt type */
\r
70 typedef enum _pint_int
\r
72 kPINT_PinInt0 = 0U, /*!< Pin Interrupt 0 */
\r
73 #if (FSL_FEATURE_PINT_NUMBER_OF_CONNECTED_OUTPUTS > 1U)
\r
74 kPINT_PinInt1 = 1U, /*!< Pin Interrupt 1 */
\r
76 #if (FSL_FEATURE_PINT_NUMBER_OF_CONNECTED_OUTPUTS > 2U)
\r
77 kPINT_PinInt2 = 2U, /*!< Pin Interrupt 2 */
\r
79 #if (FSL_FEATURE_PINT_NUMBER_OF_CONNECTED_OUTPUTS > 3U)
\r
80 kPINT_PinInt3 = 3U, /*!< Pin Interrupt 3 */
\r
82 #if (FSL_FEATURE_PINT_NUMBER_OF_CONNECTED_OUTPUTS > 4U)
\r
83 kPINT_PinInt4 = 4U, /*!< Pin Interrupt 4 */
\r
85 #if (FSL_FEATURE_PINT_NUMBER_OF_CONNECTED_OUTPUTS > 5U)
\r
86 kPINT_PinInt5 = 5U, /*!< Pin Interrupt 5 */
\r
88 #if (FSL_FEATURE_PINT_NUMBER_OF_CONNECTED_OUTPUTS > 6U)
\r
89 kPINT_PinInt6 = 6U, /*!< Pin Interrupt 6 */
\r
91 #if (FSL_FEATURE_PINT_NUMBER_OF_CONNECTED_OUTPUTS > 7U)
\r
92 kPINT_PinInt7 = 7U, /*!< Pin Interrupt 7 */
\r
94 #if (FSL_FEATURE_SECPINT_NUMBER_OF_CONNECTED_OUTPUTS > 0U)
\r
95 kPINT_SecPinInt0 = 8U, /*!< Secure Pin Interrupt 0 */
\r
97 #if (FSL_FEATURE_SECPINT_NUMBER_OF_CONNECTED_OUTPUTS > 1U)
\r
98 kPINT_SecPinInt1 = 9U, /*!< Secure Pin Interrupt 1 */
\r
102 /*! @brief PINT Pattern Match bit slice input source type */
\r
103 typedef enum _pint_pmatch_input_src
\r
105 kPINT_PatternMatchInp0Src = 0U, /*!< Input source 0 */
\r
106 kPINT_PatternMatchInp1Src = 1U, /*!< Input source 1 */
\r
107 kPINT_PatternMatchInp2Src = 2U, /*!< Input source 2 */
\r
108 kPINT_PatternMatchInp3Src = 3U, /*!< Input source 3 */
\r
109 kPINT_PatternMatchInp4Src = 4U, /*!< Input source 4 */
\r
110 kPINT_PatternMatchInp5Src = 5U, /*!< Input source 5 */
\r
111 kPINT_PatternMatchInp6Src = 6U, /*!< Input source 6 */
\r
112 kPINT_PatternMatchInp7Src = 7U, /*!< Input source 7 */
\r
113 } pint_pmatch_input_src_t;
\r
115 /*! @brief PINT Pattern Match bit slice type */
\r
116 typedef enum _pint_pmatch_bslice
\r
118 kPINT_PatternMatchBSlice0 = 0U, /*!< Bit slice 0 */
\r
119 #if (FSL_FEATURE_PINT_NUMBER_OF_CONNECTED_OUTPUTS > 1U)
\r
120 kPINT_PatternMatchBSlice1 = 1U, /*!< Bit slice 1 */
\r
122 #if (FSL_FEATURE_PINT_NUMBER_OF_CONNECTED_OUTPUTS > 2U)
\r
123 kPINT_PatternMatchBSlice2 = 2U, /*!< Bit slice 2 */
\r
125 #if (FSL_FEATURE_PINT_NUMBER_OF_CONNECTED_OUTPUTS > 3U)
\r
126 kPINT_PatternMatchBSlice3 = 3U, /*!< Bit slice 3 */
\r
128 #if (FSL_FEATURE_PINT_NUMBER_OF_CONNECTED_OUTPUTS > 4U)
\r
129 kPINT_PatternMatchBSlice4 = 4U, /*!< Bit slice 4 */
\r
131 #if (FSL_FEATURE_PINT_NUMBER_OF_CONNECTED_OUTPUTS > 5U)
\r
132 kPINT_PatternMatchBSlice5 = 5U, /*!< Bit slice 5 */
\r
134 #if (FSL_FEATURE_PINT_NUMBER_OF_CONNECTED_OUTPUTS > 6U)
\r
135 kPINT_PatternMatchBSlice6 = 6U, /*!< Bit slice 6 */
\r
137 #if (FSL_FEATURE_PINT_NUMBER_OF_CONNECTED_OUTPUTS > 7U)
\r
138 kPINT_PatternMatchBSlice7 = 7U, /*!< Bit slice 7 */
\r
140 #if (FSL_FEATURE_SECPINT_NUMBER_OF_CONNECTED_OUTPUTS > 0U)
\r
141 kSECPINT_PatternMatchBSlice0 = 8U, /*!< Bit slice 0 */
\r
143 #if (FSL_FEATURE_SECPINT_NUMBER_OF_CONNECTED_OUTPUTS > 1U)
\r
144 kSECPINT_PatternMatchBSlice1 = 9U, /*!< Bit slice 1 */
\r
146 } pint_pmatch_bslice_t;
\r
148 /*! @brief PINT Pattern Match configuration type */
\r
149 typedef enum _pint_pmatch_bslice_cfg
\r
151 kPINT_PatternMatchAlways = 0U, /*!< Always Contributes to product term match */
\r
152 kPINT_PatternMatchStickyRise = 1U, /*!< Sticky Rising edge */
\r
153 kPINT_PatternMatchStickyFall = 2U, /*!< Sticky Falling edge */
\r
154 kPINT_PatternMatchStickyBothEdges = 3U, /*!< Sticky Rising or Falling edge */
\r
155 kPINT_PatternMatchHigh = 4U, /*!< High level */
\r
156 kPINT_PatternMatchLow = 5U, /*!< Low level */
\r
157 kPINT_PatternMatchNever = 6U, /*!< Never contributes to product term match */
\r
158 kPINT_PatternMatchBothEdges = 7U, /*!< Either rising or falling edge */
\r
159 } pint_pmatch_bslice_cfg_t;
\r
161 /*! @brief PINT Callback function. */
\r
162 typedef void (*pint_cb_t)(pint_pin_int_t pintr, uint32_t pmatch_status);
\r
164 typedef struct _pint_pmatch_cfg
\r
166 pint_pmatch_input_src_t bs_src;
\r
167 pint_pmatch_bslice_cfg_t bs_cfg;
\r
169 pint_cb_t callback;
\r
170 } pint_pmatch_cfg_t;
\r
172 /*******************************************************************************
\r
174 ******************************************************************************/
\r
176 #if defined(__cplusplus)
\r
181 * @brief Initialize PINT peripheral.
\r
183 * This function initializes the PINT peripheral and enables the clock.
\r
185 * @param base Base address of the PINT peripheral.
\r
189 void PINT_Init(PINT_Type *base);
\r
192 * @brief Configure PINT peripheral pin interrupt.
\r
194 * This function configures a given pin interrupt.
\r
196 * @param base Base address of the PINT peripheral.
\r
197 * @param intr Pin interrupt.
\r
198 * @param enable Selects detection logic.
\r
199 * @param callback Callback.
\r
203 void PINT_PinInterruptConfig(PINT_Type *base, pint_pin_int_t intr, pint_pin_enable_t enable, pint_cb_t callback);
\r
206 * @brief Get PINT peripheral pin interrupt configuration.
\r
208 * This function returns the configuration of a given pin interrupt.
\r
210 * @param base Base address of the PINT peripheral.
\r
211 * @param pintr Pin interrupt.
\r
212 * @param enable Pointer to store the detection logic.
\r
213 * @param callback Callback.
\r
217 void PINT_PinInterruptGetConfig(PINT_Type *base, pint_pin_int_t pintr, pint_pin_enable_t *enable, pint_cb_t *callback);
\r
220 * @brief Clear Selected pin interrupt status only when the pin was triggered by edge-sensitive.
\r
222 * This function clears the selected pin interrupt status.
\r
224 * @param base Base address of the PINT peripheral.
\r
225 * @param pintr Pin interrupt.
\r
229 void PINT_PinInterruptClrStatus(PINT_Type *base, pint_pin_int_t pintr);
\r
232 * @brief Get Selected pin interrupt status.
\r
234 * This function returns the selected pin interrupt status.
\r
236 * @param base Base address of the PINT peripheral.
\r
237 * @param pintr Pin interrupt.
\r
239 * @retval status = 0 No pin interrupt request. = 1 Selected Pin interrupt request active.
\r
241 static inline uint32_t PINT_PinInterruptGetStatus(PINT_Type *base, pint_pin_int_t pintr)
\r
243 return ((base->IST & (1UL << (uint32_t)pintr)) != 0U ? 1U : 0U);
\r
247 * @brief Clear all pin interrupts status only when pins were triggered by edge-sensitive.
\r
249 * This function clears the status of all pin interrupts.
\r
251 * @param base Base address of the PINT peripheral.
\r
255 void PINT_PinInterruptClrStatusAll(PINT_Type *base);
\r
258 * @brief Get all pin interrupts status.
\r
260 * This function returns the status of all pin interrupts.
\r
262 * @param base Base address of the PINT peripheral.
\r
264 * @retval status Each bit position indicates the status of corresponding pin interrupt.
\r
265 * = 0 No pin interrupt request. = 1 Pin interrupt request active.
\r
267 static inline uint32_t PINT_PinInterruptGetStatusAll(PINT_Type *base)
\r
269 return (base->IST);
\r
273 * @brief Clear Selected pin interrupt fall flag.
\r
275 * This function clears the selected pin interrupt fall flag.
\r
277 * @param base Base address of the PINT peripheral.
\r
278 * @param pintr Pin interrupt.
\r
282 static inline void PINT_PinInterruptClrFallFlag(PINT_Type *base, pint_pin_int_t pintr)
\r
284 base->FALL = (1UL << (uint32_t)pintr);
\r
288 * @brief Get selected pin interrupt fall flag.
\r
290 * This function returns the selected pin interrupt fall flag.
\r
292 * @param base Base address of the PINT peripheral.
\r
293 * @param pintr Pin interrupt.
\r
295 * @retval flag = 0 Falling edge has not been detected. = 1 Falling edge has been detected.
\r
297 static inline uint32_t PINT_PinInterruptGetFallFlag(PINT_Type *base, pint_pin_int_t pintr)
\r
299 return ((base->FALL & (1UL << (uint32_t)pintr)) != 0U ? 1U : 0U);
\r
303 * @brief Clear all pin interrupt fall flags.
\r
305 * This function clears the fall flag for all pin interrupts.
\r
307 * @param base Base address of the PINT peripheral.
\r
311 static inline void PINT_PinInterruptClrFallFlagAll(PINT_Type *base)
\r
313 base->FALL = PINT_FALL_FDET_MASK;
\r
317 * @brief Get all pin interrupt fall flags.
\r
319 * This function returns the fall flag of all pin interrupts.
\r
321 * @param base Base address of the PINT peripheral.
\r
323 * @retval flags Each bit position indicates the falling edge detection of the corresponding pin interrupt.
\r
324 * 0 Falling edge has not been detected. = 1 Falling edge has been detected.
\r
326 static inline uint32_t PINT_PinInterruptGetFallFlagAll(PINT_Type *base)
\r
328 return (base->FALL);
\r
332 * @brief Clear Selected pin interrupt rise flag.
\r
334 * This function clears the selected pin interrupt rise flag.
\r
336 * @param base Base address of the PINT peripheral.
\r
337 * @param pintr Pin interrupt.
\r
341 static inline void PINT_PinInterruptClrRiseFlag(PINT_Type *base, pint_pin_int_t pintr)
\r
343 base->RISE = (1UL << (uint32_t)pintr);
\r
347 * @brief Get selected pin interrupt rise flag.
\r
349 * This function returns the selected pin interrupt rise flag.
\r
351 * @param base Base address of the PINT peripheral.
\r
352 * @param pintr Pin interrupt.
\r
354 * @retval flag = 0 Rising edge has not been detected. = 1 Rising edge has been detected.
\r
356 static inline uint32_t PINT_PinInterruptGetRiseFlag(PINT_Type *base, pint_pin_int_t pintr)
\r
358 return ((base->RISE & (1UL << (uint32_t)pintr)) != 0U ? 1U : 0U);
\r
362 * @brief Clear all pin interrupt rise flags.
\r
364 * This function clears the rise flag for all pin interrupts.
\r
366 * @param base Base address of the PINT peripheral.
\r
370 static inline void PINT_PinInterruptClrRiseFlagAll(PINT_Type *base)
\r
372 base->RISE = PINT_RISE_RDET_MASK;
\r
376 * @brief Get all pin interrupt rise flags.
\r
378 * This function returns the rise flag of all pin interrupts.
\r
380 * @param base Base address of the PINT peripheral.
\r
382 * @retval flags Each bit position indicates the rising edge detection of the corresponding pin interrupt.
\r
383 * 0 Rising edge has not been detected. = 1 Rising edge has been detected.
\r
385 static inline uint32_t PINT_PinInterruptGetRiseFlagAll(PINT_Type *base)
\r
387 return (base->RISE);
\r
391 * @brief Configure PINT pattern match.
\r
393 * This function configures a given pattern match bit slice.
\r
395 * @param base Base address of the PINT peripheral.
\r
396 * @param bslice Pattern match bit slice number.
\r
397 * @param cfg Pointer to bit slice configuration.
\r
401 void PINT_PatternMatchConfig(PINT_Type *base, pint_pmatch_bslice_t bslice, pint_pmatch_cfg_t *cfg);
\r
404 * @brief Get PINT pattern match configuration.
\r
406 * This function returns the configuration of a given pattern match bit slice.
\r
408 * @param base Base address of the PINT peripheral.
\r
409 * @param bslice Pattern match bit slice number.
\r
410 * @param cfg Pointer to bit slice configuration.
\r
414 void PINT_PatternMatchGetConfig(PINT_Type *base, pint_pmatch_bslice_t bslice, pint_pmatch_cfg_t *cfg);
\r
417 * @brief Get pattern match bit slice status.
\r
419 * This function returns the status of selected bit slice.
\r
421 * @param base Base address of the PINT peripheral.
\r
422 * @param bslice Pattern match bit slice number.
\r
424 * @retval status = 0 Match has not been detected. = 1 Match has been detected.
\r
426 static inline uint32_t PINT_PatternMatchGetStatus(PINT_Type *base, pint_pmatch_bslice_t bslice)
\r
428 return ((base->PMCTRL >> PINT_PMCTRL_PMAT_SHIFT) & (1UL << (uint32_t)bslice)) >> (uint32_t)bslice;
\r
432 * @brief Get status of all pattern match bit slices.
\r
434 * This function returns the status of all bit slices.
\r
436 * @param base Base address of the PINT peripheral.
\r
438 * @retval status Each bit position indicates the match status of corresponding bit slice.
\r
439 * = 0 Match has not been detected. = 1 Match has been detected.
\r
441 static inline uint32_t PINT_PatternMatchGetStatusAll(PINT_Type *base)
\r
443 return base->PMCTRL >> PINT_PMCTRL_PMAT_SHIFT;
\r
447 * @brief Reset pattern match detection logic.
\r
449 * This function resets the pattern match detection logic if any of the product term is matching.
\r
451 * @param base Base address of the PINT peripheral.
\r
453 * @retval pmstatus Each bit position indicates the match status of corresponding bit slice.
\r
454 * = 0 Match was detected. = 1 Match was not detected.
\r
456 uint32_t PINT_PatternMatchResetDetectLogic(PINT_Type *base);
\r
459 * @brief Enable pattern match function.
\r
461 * This function enables the pattern match function.
\r
463 * @param base Base address of the PINT peripheral.
\r
467 static inline void PINT_PatternMatchEnable(PINT_Type *base)
\r
469 base->PMCTRL = (base->PMCTRL & PINT_PMCTRL_ENA_RXEV_MASK) | PINT_PMCTRL_SEL_PMATCH_MASK;
\r
473 * @brief Disable pattern match function.
\r
475 * This function disables the pattern match function.
\r
477 * @param base Base address of the PINT peripheral.
\r
481 static inline void PINT_PatternMatchDisable(PINT_Type *base)
\r
483 base->PMCTRL = (base->PMCTRL & PINT_PMCTRL_ENA_RXEV_MASK) & ~PINT_PMCTRL_SEL_PMATCH_MASK;
\r
487 * @brief Enable RXEV output.
\r
489 * This function enables the pattern match RXEV output.
\r
491 * @param base Base address of the PINT peripheral.
\r
495 static inline void PINT_PatternMatchEnableRXEV(PINT_Type *base)
\r
497 base->PMCTRL = (base->PMCTRL & PINT_PMCTRL_SEL_PMATCH_MASK) | PINT_PMCTRL_ENA_RXEV_MASK;
\r
501 * @brief Disable RXEV output.
\r
503 * This function disables the pattern match RXEV output.
\r
505 * @param base Base address of the PINT peripheral.
\r
509 static inline void PINT_PatternMatchDisableRXEV(PINT_Type *base)
\r
511 base->PMCTRL = (base->PMCTRL & PINT_PMCTRL_SEL_PMATCH_MASK) & ~PINT_PMCTRL_ENA_RXEV_MASK;
\r
515 * @brief Enable callback.
\r
517 * This function enables the interrupt for the selected PINT peripheral. Although the pin(s) are monitored
\r
518 * as soon as they are enabled, the callback function is not enabled until this function is called.
\r
520 * @param base Base address of the PINT peripheral.
\r
524 void PINT_EnableCallback(PINT_Type *base);
\r
527 * @brief Disable callback.
\r
529 * This function disables the interrupt for the selected PINT peripheral. Although the pins are still
\r
530 * being monitored but the callback function is not called.
\r
532 * @param base Base address of the peripheral.
\r
536 void PINT_DisableCallback(PINT_Type *base);
\r
539 * @brief Deinitialize PINT peripheral.
\r
541 * This function disables the PINT clock.
\r
543 * @param base Base address of the PINT peripheral.
\r
547 void PINT_Deinit(PINT_Type *base);
\r
550 * @brief enable callback by pin index.
\r
552 * This function enables callback by pin index instead of enabling all pins.
\r
554 * @param base Base address of the peripheral.
\r
555 * @param pinIdx pin index.
\r
559 void PINT_EnableCallbackByIndex(PINT_Type *base, pint_pin_int_t pintIdx);
\r
562 * @brief disable callback by pin index.
\r
564 * This function disables callback by pin index instead of disabling all pins.
\r
566 * @param base Base address of the peripheral.
\r
567 * @param pinIdx pin index.
\r
571 void PINT_DisableCallbackByIndex(PINT_Type *base, pint_pin_int_t pintIdx);
\r
579 #endif /* _FSL_PINT_H_ */
\r