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