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 #ifndef _FSL_LLWU_H_
9 #define _FSL_LLWU_H_
10
11 #include "fsl_common.h"
12
13 /*! @addtogroup llwu */
14 /*! @{ */
15
16 /*******************************************************************************
17 * Definitions
18 ******************************************************************************/
19
20 /*! @name Driver version */
21 /*@{*/
22 /*! @brief LLWU driver version. */
23 #define FSL_LLWU_DRIVER_VERSION (MAKE_VERSION(2, 0, 5))
24 /*@}*/
25
26 #if (defined(FSL_FEATURE_LLWU_REG_BITWIDTH) && (FSL_FEATURE_LLWU_REG_BITWIDTH == 32))
27 #define LLWU_REG_VAL(x) ((uint32_t)(x))
28 #else
29 #define LLWU_REG_VAL(x) ((uint8_t)(x))
30 #endif
31
32 /*!
33 * @brief External input pin control modes
34 */
35 typedef enum _llwu_external_pin_mode
36 {
37 kLLWU_ExternalPinDisable = 0U, /*!< Pin disabled as a wakeup input. */
38 kLLWU_ExternalPinRisingEdge = 1U, /*!< Pin enabled with the rising edge detection. */
39 kLLWU_ExternalPinFallingEdge = 2U, /*!< Pin enabled with the falling edge detection.*/
40 kLLWU_ExternalPinAnyEdge = 3U /*!< Pin enabled with any change detection. */
41 } llwu_external_pin_mode_t;
42
43 /*!
44 * @brief Digital filter control modes
45 */
46 typedef enum _llwu_pin_filter_mode
47 {
48 kLLWU_PinFilterDisable = 0U, /*!< Filter disabled. */
49 kLLWU_PinFilterRisingEdge = 1U, /*!< Filter positive edge detection.*/
50 kLLWU_PinFilterFallingEdge = 2U, /*!< Filter negative edge detection.*/
51 kLLWU_PinFilterAnyEdge = 3U /*!< Filter any edge detection. */
52 } llwu_pin_filter_mode_t;
53
54 #if (defined(FSL_FEATURE_LLWU_HAS_VERID) && FSL_FEATURE_LLWU_HAS_VERID)
55 /*!
56 * @brief IP version ID definition.
57 */
58 typedef struct _llwu_version_id
59 {
60 uint16_t feature; /*!< A feature specification number. */
61 uint8_t minor; /*!< The minor version number. */
62 uint8_t major; /*!< The major version number. */
63 } llwu_version_id_t;
64 #endif /* FSL_FEATURE_LLWU_HAS_VERID */
65
66 #if (defined(FSL_FEATURE_LLWU_HAS_PARAM) && FSL_FEATURE_LLWU_HAS_PARAM)
67 /*!
68 * @brief IP parameter definition.
69 */
70 typedef struct _llwu_param
71 {
72 uint8_t filters; /*!< A number of the pin filter. */
73 uint8_t dmas; /*!< A number of the wakeup DMA. */
74 uint8_t modules; /*!< A number of the wakeup module. */
75 uint8_t pins; /*!< A number of the wake up pin. */
76 } llwu_param_t;
77 #endif /* FSL_FEATURE_LLWU_HAS_PARAM */
78
79 #if (defined(FSL_FEATURE_LLWU_HAS_PIN_FILTER) && FSL_FEATURE_LLWU_HAS_PIN_FILTER)
80 /*!
81 * @brief An external input pin filter control structure
82 */
83 typedef struct _llwu_external_pin_filter_mode
84 {
85 uint32_t pinIndex; /*!< A pin number */
86 llwu_pin_filter_mode_t filterMode; /*!< Filter mode */
87 } llwu_external_pin_filter_mode_t;
88 #endif /* FSL_FEATURE_LLWU_HAS_PIN_FILTER */
89
90 /*******************************************************************************
91 * API
92 ******************************************************************************/
93
94 #if defined(__cplusplus)
95 extern "C" {
96 #endif
97
98 /*!
99 * @name Low-Leakage Wakeup Unit Control APIs
100 * @{
101 */
102
103 #if (defined(FSL_FEATURE_LLWU_HAS_VERID) && FSL_FEATURE_LLWU_HAS_VERID)
104 /*!
105 * @brief Gets the LLWU version ID.
106 *
107 * This function gets the LLWU version ID, including the major version number,
108 * the minor version number, and the feature specification number.
109 *
110 * @param base LLWU peripheral base address.
111 * @param versionId A pointer to the version ID structure.
112 */
LLWU_GetVersionId(LLWU_Type * base,llwu_version_id_t * versionId)113 static inline void LLWU_GetVersionId(LLWU_Type *base, llwu_version_id_t *versionId)
114 {
115 union
116 {
117 llwu_version_id_t vid;
118 uint32_t u32;
119 } llwuVID;
120
121 llwuVID.u32 = base->VERID;
122
123 *versionId = llwuVID.vid;
124 }
125 #endif /* FSL_FEATURE_LLWU_HAS_VERID */
126
127 #if (defined(FSL_FEATURE_LLWU_HAS_PARAM) && FSL_FEATURE_LLWU_HAS_PARAM)
128 /*!
129 * @brief Gets the LLWU parameter.
130 *
131 * This function gets the LLWU parameter, including a wakeup pin number, a module
132 * number, a DMA number, and a pin filter number.
133 *
134 * @param base LLWU peripheral base address.
135 * @param param A pointer to the LLWU parameter structure.
136 */
LLWU_GetParam(LLWU_Type * base,llwu_param_t * param)137 static inline void LLWU_GetParam(LLWU_Type *base, llwu_param_t *param)
138 {
139 union
140 {
141 llwu_param_t param;
142 uint32_t u32;
143 } llwuParam;
144
145 llwuParam.u32 = base->PARAM;
146
147 *param = llwuParam.param;
148 }
149 #endif /* FSL_FEATURE_LLWU_HAS_PARAM */
150
151 #if (defined(FSL_FEATURE_LLWU_HAS_EXTERNAL_PIN) && FSL_FEATURE_LLWU_HAS_EXTERNAL_PIN)
152 /*!
153 * @brief Sets the external input pin source mode.
154 *
155 * This function sets the external input pin source mode that is used
156 * as a wake up source.
157 *
158 * @param base LLWU peripheral base address.
159 * @param pinIndex A pin index to be enabled as an external wakeup source starting from 1.
160 * @param pinMode A pin configuration mode defined in the llwu_external_pin_modes_t.
161 */
162 void LLWU_SetExternalWakeupPinMode(LLWU_Type *base, uint32_t pinIndex, llwu_external_pin_mode_t pinMode);
163
164 /*!
165 * @brief Gets the external wakeup source flag.
166 *
167 * This function checks the external pin flag to detect whether the MCU is
168 * woken up by the specific pin.
169 *
170 * @param base LLWU peripheral base address.
171 * @param pinIndex A pin index, which starts from 1.
172 * @return True if the specific pin is a wakeup source.
173 */
174 bool LLWU_GetExternalWakeupPinFlag(LLWU_Type *base, uint32_t pinIndex);
175
176 /*!
177 * @brief Clears the external wakeup source flag.
178 *
179 * This function clears the external wakeup source flag for a specific pin.
180 *
181 * @param base LLWU peripheral base address.
182 * @param pinIndex A pin index, which starts from 1.
183 */
184 void LLWU_ClearExternalWakeupPinFlag(LLWU_Type *base, uint32_t pinIndex);
185 #endif /* FSL_FEATURE_LLWU_HAS_EXTERNAL_PIN */
186
187 #if (defined(FSL_FEATURE_LLWU_HAS_INTERNAL_MODULE) && FSL_FEATURE_LLWU_HAS_INTERNAL_MODULE)
188 /*!
189 * @brief Enables/disables the internal module source.
190 *
191 * This function enables/disables the internal module source mode that is used
192 * as a wake up source.
193 *
194 * @param base LLWU peripheral base address.
195 * @param moduleIndex A module index to be enabled as an internal wakeup source starting from 1.
196 * @param enable An enable or a disable setting
197 */
LLWU_EnableInternalModuleInterruptWakup(LLWU_Type * base,uint32_t moduleIndex,bool enable)198 static inline void LLWU_EnableInternalModuleInterruptWakup(LLWU_Type *base, uint32_t moduleIndex, bool enable)
199 {
200 if (enable)
201 {
202 base->ME |= LLWU_REG_VAL(1UL << moduleIndex);
203 }
204 else
205 {
206 base->ME &= LLWU_REG_VAL(~(1UL << moduleIndex));
207 }
208 }
209
210 #if (!(defined(FSL_FEATURE_LLWU_HAS_NO_INTERNAL_MODULE_WAKEUP_FLAG_REG) && \
211 FSL_FEATURE_LLWU_HAS_NO_INTERNAL_MODULE_WAKEUP_FLAG_REG))
212 /* Re-define the register which includes the internal wakeup module flag. */
213 #if (defined(FSL_FEATURE_LLWU_REG_BITWIDTH) && (FSL_FEATURE_LLWU_REG_BITWIDTH == 32)) /* 32-bit LLWU. */
214 #if (defined(FSL_FEATURE_LLWU_HAS_MF) && FSL_FEATURE_LLWU_HAS_MF)
215 #define INTERNAL_WAKEUP_MODULE_FLAG_REG MF
216 #else
217 #error "Unsupported internal module flag register."
218 #endif
219 #else /* 8-bit LLUW. */
220 #if (defined(FSL_FEATURE_LLWU_HAS_MF) && FSL_FEATURE_LLWU_HAS_MF)
221 #define INTERNAL_WAKEUP_MODULE_FLAG_REG MF5
222 #elif (defined(FSL_FEATURE_LLWU_HAS_PF) && FSL_FEATURE_LLWU_HAS_PF)
223 #define INTERNAL_WAKEUP_MODULE_FLAG_REG PF3
224 #elif (!(defined(FSL_FEATURE_LLWU_HAS_EXTERNAL_PIN) && (FSL_FEATURE_LLWU_HAS_EXTERNAL_PIN > 16)))
225 #define INTERNAL_WAKEUP_MODULE_FLAG_REG F3
226 #else
227 #error "Unsupported internal module flag register."
228 #endif
229 #endif /* FSL_FEATURE_LLWU_REG_BITWIDTH */
230
231 /*!
232 * @brief Gets the external wakeup source flag.
233 *
234 * This function checks the external pin flag to detect whether the system is
235 * woken up by the specific pin.
236 *
237 * @param base LLWU peripheral base address.
238 * @param moduleIndex A module index, which starts from 1.
239 * @return True if the specific pin is a wake up source.
240 */
LLWU_GetInternalWakeupModuleFlag(LLWU_Type * base,uint32_t moduleIndex)241 static inline bool LLWU_GetInternalWakeupModuleFlag(LLWU_Type *base, uint32_t moduleIndex)
242 {
243 return ((1UL << moduleIndex) == ((uint32_t)base->INTERNAL_WAKEUP_MODULE_FLAG_REG & (1UL << moduleIndex)));
244 }
245 #endif /* FSL_FEATURE_LLWU_HAS_NO_INTERNAL_MODULE_WAKEUP_FLAG_REG */
246 #endif /* FSL_FEATURE_LLWU_HAS_INTERNAL_MODULE */
247
248 #if (defined(FSL_FEATURE_LLWU_HAS_DMA_ENABLE_REG) && FSL_FEATURE_LLWU_HAS_DMA_ENABLE_REG)
249 /*!
250 * @brief Enables/disables the internal module DMA wakeup source.
251 *
252 * This function enables/disables the internal DMA that is used as a wake up source.
253 *
254 * @param base LLWU peripheral base address.
255 * @param moduleIndex An internal module index which is used as a DMA request source, starting from 1.
256 * @param enable Enable or disable the DMA request source
257 */
LLWU_EnableInternalModuleDmaRequestWakup(LLWU_Type * base,uint32_t moduleIndex,bool enable)258 static inline void LLWU_EnableInternalModuleDmaRequestWakup(LLWU_Type *base, uint32_t moduleIndex, bool enable)
259 {
260 if (enable)
261 {
262 base->DE |= LLWU_REG_VAL(1UL << moduleIndex);
263 }
264 else
265 {
266 base->DE &= LLWU_REG_VAL(~(1UL << moduleIndex));
267 }
268 }
269 #endif /* FSL_FEATURE_LLWU_HAS_DMA_ENABLE_REG */
270
271 #if (defined(FSL_FEATURE_LLWU_HAS_PIN_FILTER) && FSL_FEATURE_LLWU_HAS_PIN_FILTER)
272 /*!
273 * @brief Sets the pin filter configuration.
274 *
275 * This function sets the pin filter configuration.
276 *
277 * @param base LLWU peripheral base address.
278 * @param filterIndex A pin filter index used to enable/disable the digital filter, starting from 1.
279 * @param filterMode A filter mode configuration
280 */
281 void LLWU_SetPinFilterMode(LLWU_Type *base, uint32_t filterIndex, llwu_external_pin_filter_mode_t filterMode);
282
283 /*!
284 * @brief Gets the pin filter configuration.
285 *
286 * This function gets the pin filter flag.
287 *
288 * @param base LLWU peripheral base address.
289 * @param filterIndex A pin filter index, which starts from 1.
290 * @return True if the flag is a source of the existing low-leakage power mode.
291 */
292 bool LLWU_GetPinFilterFlag(LLWU_Type *base, uint32_t filterIndex);
293
294 /*!
295 * @brief Clears the pin filter configuration.
296 *
297 * This function clears the pin filter flag.
298 *
299 * @param base LLWU peripheral base address.
300 * @param filterIndex A pin filter index to clear the flag, starting from 1.
301 */
302 void LLWU_ClearPinFilterFlag(LLWU_Type *base, uint32_t filterIndex);
303
304 #endif /* FSL_FEATURE_LLWU_HAS_PIN_FILTER */
305
306 #if (defined(FSL_FEATURE_LLWU_HAS_RESET_ENABLE) && FSL_FEATURE_LLWU_HAS_RESET_ENABLE)
307 /*!
308 * @brief Sets the reset pin mode.
309 *
310 * This function determines how the reset pin is used as a low leakage mode exit source.
311 *
312 * @param base LLWU peripheral base address.
313 * @param pinEnable Enable reset the pin filter
314 * @param pinFilterEnable Specify whether the pin filter is enabled in Low-Leakage power mode.
315 */
316 void LLWU_SetResetPinMode(LLWU_Type *base, bool pinEnable, bool pinFilterEnable);
317 #endif /* FSL_FEATURE_LLWU_HAS_RESET_ENABLE */
318
319 /*@}*/
320
321 #if defined(__cplusplus)
322 }
323 #endif
324
325 /*! @}*/
326 #endif /* _FSL_LLWU_H_*/
327