diff options
Diffstat (limited to 'lib/chibios-contrib/ext/mcux-sdk/devices/LPC804/drivers/fsl_power.h')
-rw-r--r-- | lib/chibios-contrib/ext/mcux-sdk/devices/LPC804/drivers/fsl_power.h | 360 |
1 files changed, 360 insertions, 0 deletions
diff --git a/lib/chibios-contrib/ext/mcux-sdk/devices/LPC804/drivers/fsl_power.h b/lib/chibios-contrib/ext/mcux-sdk/devices/LPC804/drivers/fsl_power.h new file mode 100644 index 000000000..b8b4532ef --- /dev/null +++ b/lib/chibios-contrib/ext/mcux-sdk/devices/LPC804/drivers/fsl_power.h | |||
@@ -0,0 +1,360 @@ | |||
1 | /* | ||
2 | * Copyright (c) 2016, Freescale Semiconductor, Inc. | ||
3 | * Copyright 2016-2018, 2020 NXP | ||
4 | * All rights reserved. | ||
5 | * | ||
6 | * SPDX-License-Identifier: BSD-3-Clause | ||
7 | */ | ||
8 | #ifndef _FSL_POWER_H_ | ||
9 | #define _FSL_POWER_H_ | ||
10 | |||
11 | #include "fsl_common.h" | ||
12 | |||
13 | /******************************************************************************* | ||
14 | * Definitions | ||
15 | ******************************************************************************/ | ||
16 | |||
17 | /*! | ||
18 | * @addtogroup power | ||
19 | * @{ | ||
20 | */ | ||
21 | |||
22 | /*! @name Driver version */ | ||
23 | /*@{*/ | ||
24 | /*! @brief power driver version 2.0.4. */ | ||
25 | #define FSL_POWER_DRIVER_VERSION (MAKE_VERSION(2, 0, 4)) | ||
26 | /*@}*/ | ||
27 | /*! @brief PMU PCON reserved mask, used to clear reserved field which should not write 1*/ | ||
28 | #define PMUC_PCON_RESERVED_MASK ((0xf << 4) | (0x6 << 8) | 0xfffff000u) | ||
29 | |||
30 | #define POWER_EnbaleLPO POWER_EnableLPO | ||
31 | |||
32 | typedef enum pd_bits | ||
33 | { | ||
34 | kPDRUNCFG_PD_FRO_OUT = SYSCON_PDRUNCFG_FROOUT_PD_MASK, | ||
35 | kPDRUNCFG_PD_FRO = SYSCON_PDRUNCFG_FRO_PD_MASK, | ||
36 | kPDRUNCFG_PD_FLASH = SYSCON_PDRUNCFG_FLASH_PD_MASK, | ||
37 | kPDRUNCFG_PD_BOD = SYSCON_PDRUNCFG_BOD_PD_MASK, | ||
38 | kPDRUNCFG_PD_ADC0 = SYSCON_PDRUNCFG_ADC_PD_MASK, | ||
39 | kPDRUNCFG_PD_LPOSC = SYSCON_PDRUNCFG_LPOSC_PD_MASK, | ||
40 | kPDRUNCFG_PD_DAC0 = SYSCON_PDRUNCFG_DAC0_MASK, | ||
41 | kPDRUNCFG_PD_ACMP = SYSCON_PDRUNCFG_ACMP_MASK, | ||
42 | /* | ||
43 | This enum member has no practical meaning,it is used to avoid MISRA issue, | ||
44 | user should not trying to use it. | ||
45 | */ | ||
46 | kPDRUNCFG_ForceUnsigned = (int)0x80000000U, | ||
47 | } pd_bit_t; | ||
48 | |||
49 | /*! @brief Deep sleep and power down mode wake up configurations */ | ||
50 | enum _power_wakeup | ||
51 | { | ||
52 | kPDAWAKECFG_Wakeup_FRO_OUT = SYSCON_PDAWAKECFG_FROOUT_PD_MASK, | ||
53 | kPDAWAKECFG_Wakeup_FRO = SYSCON_PDAWAKECFG_FRO_PD_MASK, | ||
54 | kPDAWAKECFG_Wakeup_FLASH = SYSCON_PDAWAKECFG_FLASH_PD_MASK, | ||
55 | kPDAWAKECFG_Wakeup_BOD = SYSCON_PDAWAKECFG_BOD_PD_MASK, | ||
56 | kPDAWAKECFG_Wakeup_ADC = SYSCON_PDAWAKECFG_ADC_PD_MASK, | ||
57 | kPDAWAKECFG_Wakeup_LPOSC = SYSCON_PDAWAKECFG_LPOSC_PD_MASK, | ||
58 | kPDAWAKECFG_Wakeup_DAC0 = SYSCON_PDAWAKECFG_DAC_MASK, | ||
59 | kPDAWAKECFG_Wakeup_ACMP = SYSCON_PDAWAKECFG_ACMP_MASK, | ||
60 | }; | ||
61 | |||
62 | /*! @brief Deep power down mode wake up pins */ | ||
63 | enum _power_dpd_wakeup_pin | ||
64 | { | ||
65 | KPmu_Dpd_En_Pio0_15 = (uint32_t)(1 << 0), | ||
66 | KPmu_Dpd_En_Pio0_9 = (uint32_t)(1 << 1), | ||
67 | KPmu_Dpd_En_Pio0_8 = (uint32_t)(1 << 2), | ||
68 | KPmu_Dpd_En_Pio0_17 = (uint32_t)(1 << 3), | ||
69 | KPmu_Dpd_En_Pio0_13 = (uint32_t)(1 << 4), | ||
70 | KPmu_Dpd_En_Pio0_4 = (uint32_t)(1 << 5), | ||
71 | KPmu_Dpd_En_Pio0_11 = (uint32_t)(1 << 6), | ||
72 | KPmu_Dpd_En_Pio0_10 = (uint32_t)(1 << 7), | ||
73 | }; | ||
74 | |||
75 | /*! @brief Deep sleep/power down mode active part */ | ||
76 | enum _power_deep_sleep_active | ||
77 | { | ||
78 | kPDSLEEPCFG_DeepSleepBODActive = SYSCON_PDSLEEPCFG_BOD_PD_MASK, | ||
79 | kPDSLEEPCFG_DeepSleepLPOscActive = SYSCON_PDSLEEPCFG_LPOSC_PD_MASK, | ||
80 | }; | ||
81 | |||
82 | /*! @brief pmu general purpose register index */ | ||
83 | typedef enum _power_gen_reg | ||
84 | { | ||
85 | kPmu_GenReg0 = 0U, /*!< general purpose register0 */ | ||
86 | kPmu_GenReg1 = 1U, /*!< general purpose register1 */ | ||
87 | kPmu_GenReg2 = 2U, /*!< general purpose register2 */ | ||
88 | kPmu_GenReg3 = 3U, /*!< general purpose register3 */ | ||
89 | kPmu_GenReg4 = 4U, /*!< general purpose reguster4 */ | ||
90 | } power_gen_reg_t; | ||
91 | |||
92 | /* Power mode configuration API parameter */ | ||
93 | typedef enum _power_mode_config | ||
94 | { | ||
95 | kPmu_Sleep = 0U, | ||
96 | kPmu_Deep_Sleep = 1U, | ||
97 | kPmu_PowerDown = 2U, | ||
98 | kPmu_Deep_PowerDown = 3U, | ||
99 | } power_mode_cfg_t; | ||
100 | |||
101 | /******************************************************************************* | ||
102 | * API | ||
103 | ******************************************************************************/ | ||
104 | |||
105 | #ifdef __cplusplus | ||
106 | extern "C" { | ||
107 | #endif | ||
108 | |||
109 | /*! | ||
110 | * @name SYSCON Power Configuration | ||
111 | * @{ | ||
112 | */ | ||
113 | |||
114 | /*! | ||
115 | * @brief API to enable PDRUNCFG bit in the Syscon. Note that enabling the bit powers down the peripheral | ||
116 | * | ||
117 | * @param en peripheral for which to enable the PDRUNCFG bit | ||
118 | * @return none | ||
119 | */ | ||
120 | static inline void POWER_EnablePD(pd_bit_t en) | ||
121 | { | ||
122 | SYSCON->PDRUNCFG |= (uint32_t)en; | ||
123 | } | ||
124 | |||
125 | /*! | ||
126 | * @brief API to disable PDRUNCFG bit in the Syscon. Note that disabling the bit powers up the peripheral | ||
127 | * | ||
128 | * @param en peripheral for which to disable the PDRUNCFG bit | ||
129 | * @return none | ||
130 | */ | ||
131 | static inline void POWER_DisablePD(pd_bit_t en) | ||
132 | { | ||
133 | SYSCON->PDRUNCFG &= ~(uint32_t)en; | ||
134 | } | ||
135 | |||
136 | /* @} */ | ||
137 | |||
138 | /*! | ||
139 | * @name ARM core Power Configuration | ||
140 | * @{ | ||
141 | */ | ||
142 | |||
143 | /*! | ||
144 | * @brief API to enable deep sleep bit in the ARM Core. | ||
145 | * | ||
146 | * @return none | ||
147 | */ | ||
148 | static inline void POWER_EnableDeepSleep(void) | ||
149 | { | ||
150 | SCB->SCR &= ~SCB_SCR_SLEEPDEEP_Msk; | ||
151 | } | ||
152 | |||
153 | /*! | ||
154 | * @brief API to disable deep sleep bit in the ARM Core. | ||
155 | * | ||
156 | * @return none | ||
157 | */ | ||
158 | static inline void POWER_DisableDeepSleep(void) | ||
159 | { | ||
160 | SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk; | ||
161 | } | ||
162 | |||
163 | /* @} */ | ||
164 | |||
165 | /*! | ||
166 | * @name PMU functionality | ||
167 | * @{ | ||
168 | */ | ||
169 | |||
170 | /*! | ||
171 | * @brief API to enter sleep power mode. | ||
172 | * | ||
173 | * @return none | ||
174 | */ | ||
175 | void POWER_EnterSleep(void); | ||
176 | |||
177 | /*! | ||
178 | * @brief API to enter deep sleep power mode. | ||
179 | * | ||
180 | * @param activePart: should be a single or combine value of _power_deep_sleep_active . | ||
181 | * @return none | ||
182 | */ | ||
183 | void POWER_EnterDeepSleep(uint32_t activePart); | ||
184 | |||
185 | /*! | ||
186 | * @brief API to enter power down mode. | ||
187 | * | ||
188 | * @param activePart: should be a single or combine value of _power_deep_sleep_active . | ||
189 | * @return none | ||
190 | */ | ||
191 | void POWER_EnterPowerDown(uint32_t activePart); | ||
192 | |||
193 | /*! | ||
194 | * @brief API to enter deep power down mode. | ||
195 | * | ||
196 | * @return none | ||
197 | */ | ||
198 | void POWER_EnterDeepPowerDownMode(void); | ||
199 | |||
200 | /*! | ||
201 | * @brief API to get sleep mode flag. | ||
202 | * | ||
203 | * @return sleep mode flag: 0 is active mode, 1 is sleep mode entered. | ||
204 | */ | ||
205 | static inline uint32_t POWER_GetSleepModeFlag(void) | ||
206 | { | ||
207 | return (PMU->PCON & PMU_PCON_SLEEPFLAG_MASK) >> PMU_PCON_SLEEPFLAG_SHIFT; | ||
208 | } | ||
209 | |||
210 | /*! | ||
211 | * @brief API to clear sleep mode flag. | ||
212 | * | ||
213 | */ | ||
214 | static inline void POWER_ClrSleepModeFlag(void) | ||
215 | { | ||
216 | PMU->PCON |= PMU_PCON_SLEEPFLAG_MASK; | ||
217 | } | ||
218 | |||
219 | /*! | ||
220 | * @brief API to get deep power down mode flag. | ||
221 | * | ||
222 | * @return sleep mode flag: 0 not deep power down, 1 is deep power down mode entered. | ||
223 | */ | ||
224 | static inline uint32_t POWER_GetDeepPowerDownModeFlag(void) | ||
225 | { | ||
226 | return (PMU->PCON & PMU_PCON_DPDFLAG_MASK) >> PMU_PCON_DPDFLAG_SHIFT; | ||
227 | } | ||
228 | |||
229 | /*! | ||
230 | * @brief API to clear deep power down mode flag. | ||
231 | * | ||
232 | */ | ||
233 | static inline void POWER_ClrDeepPowerDownModeFlag(void) | ||
234 | { | ||
235 | PMU->PCON |= PMU_PCON_DPDFLAG_MASK; | ||
236 | } | ||
237 | |||
238 | /*! | ||
239 | * @brief API to clear wake up pin status flag. | ||
240 | * | ||
241 | */ | ||
242 | static inline void POWER_ClrWakeupPinFlag(void) | ||
243 | { | ||
244 | PMU->WUSRCREG |= PMU_WUSRCREG_WUSRCREG_MASK; | ||
245 | } | ||
246 | |||
247 | /*! | ||
248 | * @brief API to enable non deep power down mode. | ||
249 | * | ||
250 | * @param enable: true is enable non deep power down, otherwise disable. | ||
251 | */ | ||
252 | static inline void POWER_EnableNonDpd(bool enable) | ||
253 | { | ||
254 | if (enable) | ||
255 | { | ||
256 | PMU->PCON |= PMU_PCON_NODPD_MASK; | ||
257 | } | ||
258 | else | ||
259 | { | ||
260 | PMU->PCON &= ~PMU_PCON_NODPD_MASK; | ||
261 | } | ||
262 | } | ||
263 | |||
264 | /*! | ||
265 | * @brief API to enable LPO. | ||
266 | * | ||
267 | * @param enable: true to enable LPO, false to disable LPO. | ||
268 | */ | ||
269 | static inline void POWER_EnableLPO(bool enable) | ||
270 | { | ||
271 | if (enable) | ||
272 | { | ||
273 | SYSCON->LPOSCCLKEN |= SYSCON_LPOSCCLKEN_WKT_MASK; | ||
274 | } | ||
275 | else | ||
276 | { | ||
277 | SYSCON->LPOSCCLKEN &= ~SYSCON_LPOSCCLKEN_WKT_MASK; | ||
278 | } | ||
279 | } | ||
280 | |||
281 | /*! | ||
282 | * @brief API to config wakeup configurations for deep sleep mode and power down mode. | ||
283 | * | ||
284 | * @param mask: wake up configurations for deep sleep mode and power down mode, reference _power_wakeup. | ||
285 | * @param powerDown: true is power down the mask part, false is powered part. | ||
286 | */ | ||
287 | static inline void POWER_WakeUpConfig(uint32_t mask, bool powerDown) | ||
288 | { | ||
289 | if (powerDown) | ||
290 | { | ||
291 | SYSCON->PDAWAKECFG |= mask; | ||
292 | } | ||
293 | else | ||
294 | { | ||
295 | SYSCON->PDAWAKECFG &= ~mask; | ||
296 | } | ||
297 | } | ||
298 | |||
299 | /*! | ||
300 | * @brief API to config active part for deep sleep mode and power down mode. | ||
301 | * | ||
302 | * @param mask: active part configurations for deep sleep mode and power down mode, reference _power_deep_sleep_active. | ||
303 | * @param powerDown: true is power down the mask part, false is powered part. | ||
304 | */ | ||
305 | static inline void POWER_DeepSleepConfig(uint32_t mask, bool powerDown) | ||
306 | { | ||
307 | if (powerDown) | ||
308 | { | ||
309 | SYSCON->PDSLEEPCFG |= mask; | ||
310 | } | ||
311 | else | ||
312 | { | ||
313 | SYSCON->PDSLEEPCFG &= ~mask; | ||
314 | } | ||
315 | } | ||
316 | |||
317 | /*! | ||
318 | * @name API to enable wake up pin for deep power down mode | ||
319 | * | ||
320 | * @param wakeup_pin wake up pin for which to enable.reference _power_dpd_wakeup_pin. | ||
321 | * @return none | ||
322 | */ | ||
323 | static inline void POWER_DeepPowerDownWakeupSourceSelect(uint32_t wakeup_pin) | ||
324 | { | ||
325 | PMU->WUENAREG |= wakeup_pin; | ||
326 | } | ||
327 | |||
328 | /*! | ||
329 | * @brief API to retore data to general purpose register which can be retain during deep power down mode. | ||
330 | * | ||
331 | * @param index: general purpose data register index. | ||
332 | * @param data: data to restore. | ||
333 | */ | ||
334 | static inline void POWER_SetRetainData(power_gen_reg_t index, uint32_t data) | ||
335 | { | ||
336 | PMU->GPREG[index] = data; | ||
337 | } | ||
338 | |||
339 | /*! | ||
340 | * @brief API to get data from general purpose register which retain during deep power down mode. | ||
341 | * | ||
342 | * @param index: general purpose data register index. | ||
343 | * @return data stored in the general purpose register. | ||
344 | */ | ||
345 | static inline uint32_t POWER_GetRetainData(power_gen_reg_t index) | ||
346 | { | ||
347 | return PMU->GPREG[index]; | ||
348 | } | ||
349 | |||
350 | /* @} */ | ||
351 | |||
352 | #ifdef __cplusplus | ||
353 | } | ||
354 | #endif | ||
355 | |||
356 | /*! | ||
357 | * @} | ||
358 | */ | ||
359 | |||
360 | #endif /* _FSL_POWER_H_ */ | ||