1 /*
2 * Copyright 2019-2024 NXP.
3 * All rights reserved.
4 *
5 * SPDX-License-Identifier: BSD-3-Clause
6 */
7 #ifndef FSL_WUU_H_
8 #define FSL_WUU_H_
9
10 #include "fsl_common.h"
11
12 /*! @addtogroup wuu */
13 /*! @{ */
14
15 /*******************************************************************************
16 * Definitions
17 *******************************************************************************/
18
19 /*! @name Driver version */
20 /*! @{ */
21 /*! @brief Defines WUU driver version 2.4.0. */
22 #define FSL_WUU_DRIVER_VERSION (MAKE_VERSION(2, 4, 0))
23 /*! @} */
24
25 /*!
26 * @brief External WakeUp pin edge detection enumeration.
27 */
28 typedef enum _wuu_external_pin_edge_detection
29 {
30 kWUU_ExternalPinDisable = 0x0U, /*!< External input Pin disabled as wake up input. */
31 kWUU_ExternalPinRisingEdge = 0x1U, /*!< External input Pin enabled with the rising edge detection. */
32 kWUU_ExternalPinFallingEdge = 0x2U, /*!< External input Pin enabled with the falling edge detection. */
33 kWUU_ExternalPinAnyEdge = 0x3U, /*!< External input Pin enabled with any change detection. */
34 } wuu_external_pin_edge_detection_t;
35
36 /*!
37 * @brief External input wake up pin event enumeration.
38 */
39 typedef enum _wuu_external_wakeup_pin_event
40 {
41 kWUU_ExternalPinInterrupt = 0x0U, /*!< External input Pin configured as interrupt. */
42 kWUU_ExternalPinDMARequest = 0x1U, /*!< External input Pin configured as DMA request. */
43 kWUU_ExternalPinTriggerEvent = 0x2U, /*!< External input Pin configured as Trigger event. */
44 } wuu_external_wakeup_pin_event_t;
45
46 /*!
47 * @brief External input wake up pin mode enumeration.
48 */
49 typedef enum _wuu_external_wakeup_pin_mode
50 {
51 kWUU_ExternalPinActiveDSPD = 0x0U, /*!< External input Pin is active only during Deep Sleep/Power Down Mode. */
52 kWUU_ExternalPinActiveAlways = 0x1U, /*!< External input Pin is active during all power modes. */
53 } wuu_external_wakeup_pin_mode_t;
54
55 /*!
56 * @brief Internal module wake up event enumeration.
57 */
58 typedef enum _wuu_internal_wakeup_module_event
59 {
60 kWUU_InternalModuleInterrupt = 0x0U, /*!< Internal modules' interrupt as a wakeup source. */
61 kWUU_InternalModuleDMATrigger = 0x1U, /*!< Internal modules' DMA/Trigger as a wakeup source. */
62 } wuu_internal_wakeup_module_event_t;
63
64 /*!
65 * @brief Pin filter edge enumeration.
66 */
67 typedef enum _wuu_filter_edge
68 {
69 kWUU_FilterDisabled = 0x0U, /*!< Filter disabled. */
70 kWUU_FilterPosedgeEnable = 0x1U, /*!< Filter posedge detect enabled. */
71 kWUU_FilterNegedgeEnable = 0x2U, /*!< Filter negedge detect enabled. */
72 kWUU_FilterAnyEdge = 0x3U, /*!< Filter any edge detect enabled. */
73 } wuu_filter_edge_t;
74
75 /*!
76 * @brief Pin Filter event enumeration.
77 */
78 typedef enum _wuu_filter_event
79 {
80 kWUU_FilterInterrupt = 0x0U, /*!< Filter output configured as interrupt. */
81 kWUU_FilterDMARequest = 0x1U, /*!< Filter output configured as DMA request. */
82 kWUU_FilterTriggerEvent = 0x2U, /*!< Filter output configured as Trigger event. */
83 } wuu_filter_event_t;
84
85 /*!
86 * @brief Pin filter mode enumeration.
87 */
88 typedef enum _wuu_filter_mode
89 {
90 kWUU_FilterActiveDSPD = 0x0U, /*!< External input pin filter is active only during Deep Sleep/Power Down Mode. */
91 kWUU_FilterActiveAlways = 0x1U, /*!< External input Pin filter is active during all power modes. */
92 } wuu_filter_mode_t;
93
94 /*!
95 * @brief External WakeUp pin configuration
96 */
97 typedef struct _wuu_external_wakeup_pin_config
98 {
99 wuu_external_pin_edge_detection_t edge; /*!< External Input pin edge detection. */
100 wuu_external_wakeup_pin_event_t event; /*!< External Input wakeup Pin event */
101 wuu_external_wakeup_pin_mode_t mode; /*!< External Input wakeup Pin operate mode. */
102 } wuu_external_wakeup_pin_config_t;
103
104 /*!
105 * @brief Pin Filter configuration.
106 */
107 typedef struct _wuu_pin_filter_config
108 {
109 uint32_t pinIndex; /*!< The index of wakeup pin to be muxxed into filter. */
110 wuu_filter_edge_t edge; /*!< The edge of the pin digital filter. */
111 wuu_filter_event_t event; /*!< The event of the filter output. */
112 wuu_filter_mode_t mode; /*!< The mode of the filter operate. */
113 } wuu_pin_filter_config_t;
114
115 /*******************************************************************************
116 * API
117 ******************************************************************************/
118 #if defined(__cplusplus)
119 extern "C" {
120 #endif
121
122 /*!
123 * @name External Wake up Pins Control APIs.
124 * @{
125 */
126 /*!
127 * @brief Enables and Configs External WakeUp Pins.
128 *
129 * This function enables/disables the external pin as wakeup input. What's more this
130 * function configs pins options, including edge detection wakeup event and operate mode.
131 *
132 * @param base MUU peripheral base address.
133 * @param pinIndex The index of the external input pin. See Reference Manual for the details.
134 * @param config Pointer to wuu_external_wakeup_pin_config_t structure.
135 */
136 void WUU_SetExternalWakeUpPinsConfig(WUU_Type *base, uint8_t pinIndex, const wuu_external_wakeup_pin_config_t *config);
137
138 /*!
139 * @brief Disable and clear external wakeup pin settings.
140 *
141 * @param base MUU peripheral base address.
142 * @param pinIndex The index of the external input pin.
143 */
144 void WUU_ClearExternalWakeupPinsConfig(WUU_Type *base, uint8_t pinIndex);
145
146 /*!
147 * @brief Gets External Wakeup pin flags.
148 *
149 * This function return the external wakeup pin flags.
150 *
151 * @param base WUU peripheral base address.
152 * @return Wakeup flags for all external wakeup pins.
153 */
WUU_GetExternalWakeUpPinsFlag(WUU_Type * base)154 static inline uint32_t WUU_GetExternalWakeUpPinsFlag(WUU_Type *base)
155 {
156 return base->PF;
157 }
158
159 /*!
160 * @brief Clears External WakeUp Pin flags.
161 *
162 * This function clears external wakeup pins flags based on the mask.
163 *
164 * @param base WUU peripheral base address.
165 * @param mask The mask of Wakeup pin index to be cleared.
166 */
WUU_ClearExternalWakeUpPinsFlag(WUU_Type * base,uint32_t mask)167 static inline void WUU_ClearExternalWakeUpPinsFlag(WUU_Type *base, uint32_t mask)
168 {
169 base->PF = mask;
170 }
171 /*! @} */
172
173 /*!
174 * @name Internal Wakeup Module control APIs.
175 * @{
176 */
177
178 /*!
179 * @brief Config Internal modules' event as the wake up soures.
180 *
181 * This function configs the internal modules event as the wake up sources.
182 *
183 * @param base WUU peripheral base address.
184 * @param moduleIndex The selected internal module. See the Reference Manual for the details.
185 * @param event Select interrupt or DMA/Trigger of the internal module as the wake up source.
186 */
187 void WUU_SetInternalWakeUpModulesConfig(WUU_Type *base, uint8_t moduleIndex, wuu_internal_wakeup_module_event_t event);
188
189 /*!
190 * @brief Disable an on-chip internal modules' event as the wakeup sources.
191 *
192 * @param base WUU peripheral base address.
193 * @param moduleIndex The selected internal module. See the Reference Manual for the details.
194 * @param event The event(interrupt or DMA/trigger) of the internal module to disable.
195 */
196 void WUU_ClearInternalWakeUpModulesConfig(WUU_Type *base, uint8_t moduleIndex, wuu_internal_wakeup_module_event_t event);
197
198 #if (defined(FSL_FEATURE_WUU_HAS_MF) && FSL_FEATURE_WUU_HAS_MF)
199 /*!
200 * @brief Get wakeup flags for internal wakeup modules.
201 *
202 * @param base WUU peripheral base address.
203 * @return Wakeup flags for all internal wakeup modules.
204 */
WUU_GetModuleInterruptFlag(WUU_Type * base)205 static inline uint32_t WUU_GetModuleInterruptFlag(WUU_Type *base)
206 {
207 return base->MF;
208 }
209
210 /*!
211 * @brief Gets the internal module wakeup source flag.
212 *
213 * This function checks the flag to detect whether the system is
214 * woken up by specific on-chip module interrupt.
215 *
216 * @param base WWU peripheral base address.
217 * @param moduleIndex A module index, which starts from 0.
218 * @return True if the specific pin is a wake up source.
219 */
WUU_GetInternalWakeupModuleFlag(WUU_Type * base,uint32_t moduleIndex)220 static inline bool WUU_GetInternalWakeupModuleFlag(WUU_Type *base, uint32_t moduleIndex)
221 {
222 return ((1UL << moduleIndex) == (WUU_GetModuleInterruptFlag(base) & (1UL << moduleIndex)));
223 }
224 #endif /* FSL_FEATURE_WUU_HAS_MF */
225
226 /*! @} */
227
228 /*!
229 * @name Pin Filter Control APIs
230 * @{
231 */
232 /*!
233 * @brief Configs and Enables Pin filters.
234 *
235 * This function configs Pin filter, including pin select, filer operate mode
236 * filer wakeup event and filter edge detection.
237 *
238 * @param base WUU peripheral base address.
239 * @param filterIndex The index of the pin filer.
240 * @param config Pointer to wuu_pin_filter_config_t structure.
241 */
242 void WUU_SetPinFilterConfig(WUU_Type *base, uint8_t filterIndex, const wuu_pin_filter_config_t *config);
243
244 /*!
245 * @brief Gets the pin filter configuration.
246 *
247 * This function gets the pin filter flag.
248 *
249 * @param base WUU peripheral base address.
250 * @param filterIndex A pin filter index, which starts from 1.
251 * @return True if the flag is a source of the existing low-leakage power mode.
252 */
253 bool WUU_GetPinFilterFlag(WUU_Type *base, uint8_t filterIndex);
254
255 /*!
256 * @brief Clears the pin filter configuration.
257 *
258 * This function clears the pin filter flag.
259 *
260 * @param base WUU peripheral base address.
261 * @param filterIndex A pin filter index to clear the flag, starting from 1.
262 */
263 void WUU_ClearPinFilterFlag(WUU_Type *base, uint8_t filterIndex);
264
265 /*!
266 * brief Gets the external wakeup source flag.
267 *
268 * This function checks the external pin flag to detect whether the MCU is
269 * woken up by the specific pin.
270 *
271 * param base WUU peripheral base address.
272 * param pinIndex A pin index, which starts from 0.
273 * return True if the specific pin is a wakeup source.
274 */
275 bool WUU_GetExternalWakeupPinFlag(WUU_Type *base, uint32_t pinIndex);
276
277 /*!
278 * brief Clears the external wakeup source flag.
279 *
280 * This function clears the external wakeup source flag for a specific pin.
281 *
282 * param base WUU peripheral base address.
283 * param pinIndex A pin index, which starts from 0.
284 */
285 void WUU_ClearExternalWakeupPinFlag(WUU_Type *base, uint32_t pinIndex);
286 /*! @} */
287
288 #if defined(__cplusplus)
289 }
290 #endif
291
292 /*! @} */
293
294 #endif /*FSL_WUU_H_*/
295