1 /*
2 * Copyright (c) 2015, Freescale Semiconductor, Inc.
3 * Copyright 2016-2020 NXP
4 * All rights reserved.
5 *
6 * SPDX-License-Identifier: BSD-3-Clause
7 */
8
9 #ifndef _FSL_INTMUX_H_
10 #define _FSL_INTMUX_H_
11
12 #include "fsl_common.h"
13
14 /*!
15 * @addtogroup intmux
16 * @{
17 */
18
19 /*******************************************************************************
20 * Definitions
21 ******************************************************************************/
22
23 /*! @name Driver version */
24 /*@{*/
25 #define FSL_INTMUX_DRIVER_VERSION (MAKE_VERSION(2, 0, 4))
26 /*@}*/
27
28 /*! @brief INTMUX channel logic mode. */
29 typedef enum _intmux_channel_logic_mode
30 {
31 kINTMUX_ChannelLogicOR = 0x0U, /*!< Logic OR all enabled interrupt inputs */
32 kINTMUX_ChannelLogicAND, /*!< Logic AND all enabled interrupt inputs */
33 } intmux_channel_logic_mode_t;
34
35 /*******************************************************************************
36 * API
37 ******************************************************************************/
38
39 #if defined(__cplusplus)
40 extern "C" {
41 #endif
42
43 /*! @name Initialization and deinitialization */
44 /*@{*/
45
46 /*!
47 * @brief Initializes the INTMUX module.
48 *
49 * This function enables the clock gate for the specified INTMUX. It then resets all channels, so that no
50 * interrupt sources are routed and the logic mode is set to default of #kINTMUX_ChannelLogicOR.
51 * Finally, the NVIC vectors for all the INTMUX output channels are enabled.
52 *
53 * @param base INTMUX peripheral base address.
54 */
55 void INTMUX_Init(INTMUX_Type *base);
56
57 /*!
58 * @brief Deinitializes an INTMUX instance for operation.
59 *
60 * The clock gate for the specified INTMUX is disabled and the NVIC vectors for all channels are disabled.
61 *
62 * @param base INTMUX peripheral base address.
63 */
64 void INTMUX_Deinit(INTMUX_Type *base);
65
66 /*!
67 * @brief Resets an INTMUX channel.
68 *
69 * Sets all register values in the specified channel to their reset value. This function disables all interrupt
70 * sources for the channel.
71 *
72 * @param base INTMUX peripheral base address.
73 * @param channel The INTMUX channel number.
74 */
INTMUX_ResetChannel(INTMUX_Type * base,uint32_t channel)75 static inline void INTMUX_ResetChannel(INTMUX_Type *base, uint32_t channel)
76 {
77 assert(channel < (uint32_t)FSL_FEATURE_INTMUX_CHANNEL_COUNT);
78
79 base->CHANNEL[channel].CHn_CSR |= INTMUX_CHn_CSR_RST_MASK;
80 }
81
82 /*!
83 * @brief Sets the logic mode for an INTMUX channel.
84 *
85 * INTMUX channels can be configured to use one of the two logic modes that control how pending interrupt sources
86 * on the channel trigger the output interrupt.
87 * - #kINTMUX_ChannelLogicOR means any source pending triggers the output interrupt.
88 * - #kINTMUX_ChannelLogicAND means all selected sources on the channel must be pending before the channel
89 * output interrupt triggers.
90 *
91 * @param base INTMUX peripheral base address.
92 * @param channel The INTMUX channel number.
93 * @param logic The INTMUX channel logic mode.
94 */
INTMUX_SetChannelMode(INTMUX_Type * base,uint32_t channel,intmux_channel_logic_mode_t logic)95 static inline void INTMUX_SetChannelMode(INTMUX_Type *base, uint32_t channel, intmux_channel_logic_mode_t logic)
96 {
97 assert(channel < (uint32_t)FSL_FEATURE_INTMUX_CHANNEL_COUNT);
98
99 base->CHANNEL[channel].CHn_CSR = INTMUX_CHn_CSR_AND(logic);
100 }
101
102 /*@}*/
103 /*! @name Sources */
104 /*@{*/
105
106 /*!
107 * @brief Enables an interrupt source on an INTMUX channel.
108 *
109 * @param base INTMUX peripheral base address.
110 * @param channel Index of the INTMUX channel on which the specified interrupt is enabled.
111 * @param irq Interrupt to route to the specified INTMUX channel. The interrupt must be an INTMUX source.
112 */
INTMUX_EnableInterrupt(INTMUX_Type * base,uint32_t channel,IRQn_Type irq)113 static inline void INTMUX_EnableInterrupt(INTMUX_Type *base, uint32_t channel, IRQn_Type irq)
114 {
115 assert(channel < (uint32_t)FSL_FEATURE_INTMUX_CHANNEL_COUNT);
116 assert((uint32_t)irq >= (uint32_t)FSL_FEATURE_INTMUX_IRQ_START_INDEX);
117
118 base->CHANNEL[channel].CHn_IER_31_0 |= (1UL << ((uint32_t)irq - (uint32_t)FSL_FEATURE_INTMUX_IRQ_START_INDEX));
119 }
120
121 /*!
122 * @brief Disables an interrupt source on an INTMUX channel.
123 *
124 * @param base INTMUX peripheral base address.
125 * @param channel Index of the INTMUX channel on which the specified interrupt is disabled.
126 * @param irq Interrupt number. The interrupt must be an INTMUX source.
127 */
INTMUX_DisableInterrupt(INTMUX_Type * base,uint32_t channel,IRQn_Type irq)128 static inline void INTMUX_DisableInterrupt(INTMUX_Type *base, uint32_t channel, IRQn_Type irq)
129 {
130 assert(channel < (uint32_t)FSL_FEATURE_INTMUX_CHANNEL_COUNT);
131 assert((uint32_t)irq >= (uint32_t)FSL_FEATURE_INTMUX_IRQ_START_INDEX);
132
133 base->CHANNEL[channel].CHn_IER_31_0 &= ~(1UL << ((uint32_t)irq - (uint32_t)FSL_FEATURE_INTMUX_IRQ_START_INDEX));
134 }
135
136 /*@}*/
137 /*! @name Status */
138 /*@{*/
139
140 /*!
141 * @brief Gets INTMUX pending interrupt sources for a specific channel.
142 *
143 * @param base INTMUX peripheral base address.
144 * @param channel The INTMUX channel number.
145 * @return The mask of pending interrupt bits. Bit[n] set means INTMUX source n is pending.
146 */
INTMUX_GetChannelPendingSources(INTMUX_Type * base,uint32_t channel)147 static inline uint32_t INTMUX_GetChannelPendingSources(INTMUX_Type *base, uint32_t channel)
148 {
149 assert(channel < (uint32_t)FSL_FEATURE_INTMUX_CHANNEL_COUNT);
150
151 return base->CHANNEL[channel].CHn_IPR_31_0;
152 }
153
154 /*@}*/
155
156 #if defined(__cplusplus)
157 }
158 #endif
159
160 /*! @} */
161
162 #endif /* _FSL_INTMUX_H_ */
163