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