aboutsummaryrefslogtreecommitdiff
path: root/lib/chibios-contrib/ext/mcux-sdk/devices/LPC824/drivers/fsl_power.h
diff options
context:
space:
mode:
Diffstat (limited to 'lib/chibios-contrib/ext/mcux-sdk/devices/LPC824/drivers/fsl_power.h')
-rw-r--r--lib/chibios-contrib/ext/mcux-sdk/devices/LPC824/drivers/fsl_power.h386
1 files changed, 386 insertions, 0 deletions
diff --git a/lib/chibios-contrib/ext/mcux-sdk/devices/LPC824/drivers/fsl_power.h b/lib/chibios-contrib/ext/mcux-sdk/devices/LPC824/drivers/fsl_power.h
new file mode 100644
index 000000000..1807d5830
--- /dev/null
+++ b/lib/chibios-contrib/ext/mcux-sdk/devices/LPC824/drivers/fsl_power.h
@@ -0,0 +1,386 @@
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
28/*! @brief PMU PCON reserved mask, used to clear reserved field which should not write 1*/
29#define PMUC_PCON_RESERVED_MASK ((0xf << 4) | (0x6 << 8) | 0xfffff000u)
30
31#define POWER_EnbaleLPO POWER_EnableLPO
32#define POWER_EnbaleLPOInDeepPowerDownMode POWER_EnableLPOInDeepPowerDownMode
33
34typedef enum pd_bits
35{
36 kPDRUNCFG_PD_IRC_OUT = SYSCON_PDRUNCFG_IRCOUT_PD_MASK,
37 kPDRUNCFG_PD_IRC = SYSCON_PDRUNCFG_IRC_PD_MASK,
38 kPDRUNCFG_PD_FLASH = SYSCON_PDRUNCFG_FLASH_PD_MASK,
39 kPDRUNCFG_PD_BOD = SYSCON_PDRUNCFG_BOD_PD_MASK,
40 kPDRUNCFG_PD_ADC0 = SYSCON_PDRUNCFG_ADC_PD_MASK,
41 kPDRUNCFG_PD_SYSOSC = SYSCON_PDRUNCFG_SYSOSC_PD_MASK,
42 kPDRUNCFG_PD_WDT_OSC = SYSCON_PDRUNCFG_WDTOSC_PD_MASK,
43 kPDRUNCFG_PD_SYSPLL = SYSCON_PDRUNCFG_SYSPLL_PD_MASK,
44 kPDRUNCFG_PD_ACMP = SYSCON_PDRUNCFG_ACMP_MASK,
45
46 /*
47 This enum member has no practical meaning,it is used to avoid MISRA issue,
48 user should not trying to use it.
49 */
50 kPDRUNCFG_ForceUnsigned = (int)0x80000000U,
51} pd_bit_t;
52
53/*! @brief Deep sleep and power down mode wake up configurations */
54enum _power_wakeup
55{
56 kPDAWAKECFG_Wakeup_IRC_OUT = SYSCON_PDAWAKECFG_IRCOUT_PD_MASK,
57 kPDAWAKECFG_Wakeup_IRC = SYSCON_PDAWAKECFG_IRC_PD_MASK,
58 kPDAWAKECFG_Wakeup_FLASH = SYSCON_PDAWAKECFG_FLASH_PD_MASK,
59 kPDAWAKECFG_Wakeup_BOD = SYSCON_PDAWAKECFG_BOD_PD_MASK,
60 kPDAWAKECFG_Wakeup_ADC = SYSCON_PDAWAKECFG_ADC_PD_MASK,
61 kPDAWAKECFG_Wakeup_SYSOSC = SYSCON_PDAWAKECFG_SYSOSC_PD_MASK,
62 kPDAWAKECFG_Wakeup_WDT_OSC = SYSCON_PDAWAKECFG_WDTOSC_PD_MASK,
63 kPDAWAKECFG_Wakeup_SYSPLL = SYSCON_PDAWAKECFG_SYSPLL_PD_MASK,
64 kPDAWAKECFG_Wakeup_ACMP = SYSCON_PDAWAKECFG_ACMP_MASK,
65};
66
67/*! @brief Deep sleep/power down mode active part */
68enum _power_deep_sleep_active
69{
70 kPDSLEEPCFG_DeepSleepBODActive = SYSCON_PDSLEEPCFG_BOD_PD_MASK,
71 kPDSLEEPCFG_DeepSleepWDTOscActive = SYSCON_PDSLEEPCFG_WDTOSC_PD_MASK,
72};
73
74/*! @brief pmu general purpose register index */
75typedef enum _power_gen_reg
76{
77 kPmu_GenReg0 = 0U, /*!< general purpose register0 */
78 kPmu_GenReg1 = 1U, /*!< general purpose register1 */
79 kPmu_GenReg2 = 2U, /*!< general purpose register2 */
80 kPmu_GenReg3 = 3U, /*!< general purpose register3 */
81 kPmu_GenReg4 = 4U, /*!< DPDCTRL bit 31-4 */
82} power_gen_reg_t;
83
84/* Power mode configuration API parameter */
85typedef enum _power_mode_config
86{
87 kPmu_Sleep = 0U,
88 kPmu_Deep_Sleep = 1U,
89 kPmu_PowerDown = 2U,
90 kPmu_Deep_PowerDown = 3U,
91} power_mode_cfg_t;
92
93/*******************************************************************************
94 * API
95 ******************************************************************************/
96
97#ifdef __cplusplus
98extern "C" {
99#endif
100
101/*!
102 * @name SYSCON Power Configuration
103 * @{
104 */
105
106/*!
107 * @brief API to enable PDRUNCFG bit in the Syscon. Note that enabling the bit powers down the peripheral
108 *
109 * @param en peripheral for which to enable the PDRUNCFG bit
110 * @return none
111 */
112static inline void POWER_EnablePD(pd_bit_t en)
113{
114 SYSCON->PDRUNCFG |= (uint32_t)en;
115}
116
117/*!
118 * @brief API to disable PDRUNCFG bit in the Syscon. Note that disabling the bit powers up the peripheral
119 *
120 * @param en peripheral for which to disable the PDRUNCFG bit
121 * @return none
122 */
123static inline void POWER_DisablePD(pd_bit_t en)
124{
125 SYSCON->PDRUNCFG &= ~(uint32_t)en;
126}
127
128/*!
129 * @brief API to config wakeup configurations for deep sleep mode and power down mode.
130 *
131 * @param mask: wake up configurations for deep sleep mode and power down mode, reference _power_wakeup.
132 * @param powerDown: true is power down the mask part, false is powered part.
133 */
134static inline void POWER_WakeUpConfig(uint32_t mask, bool powerDown)
135{
136 if (powerDown)
137 {
138 SYSCON->PDAWAKECFG |= mask;
139 }
140 else
141 {
142 SYSCON->PDAWAKECFG &= ~mask;
143 }
144}
145
146/*!
147 * @brief API to config active part for deep sleep mode and power down mode.
148 *
149 * @param mask: active part configurations for deep sleep mode and power down mode, reference _power_deep_sleep_active.
150 * @param powerDown: true is power down the mask part, false is powered part.
151 */
152static inline void POWER_DeepSleepConfig(uint32_t mask, bool powerDown)
153{
154 if (powerDown)
155 {
156 SYSCON->PDSLEEPCFG |= mask;
157 }
158 else
159 {
160 SYSCON->PDSLEEPCFG &= ~mask;
161 }
162}
163
164/* @} */
165
166/*!
167 * @name ARM core Power Configuration
168 * @{
169 */
170
171/*!
172 * @brief API to enable deep sleep bit in the ARM Core.
173 *
174 * @return none
175 */
176static inline void POWER_EnableDeepSleep(void)
177{
178 SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;
179}
180
181/*!
182 * @brief API to disable deep sleep bit in the ARM Core.
183 *
184 * @return none
185 */
186static inline void POWER_DisableDeepSleep(void)
187{
188 SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;
189}
190
191/* @} */
192
193/*!
194 * @name PMU functionality
195 * @{
196 */
197
198/*!
199 * @brief API to enter sleep power mode.
200 *
201 * @return none
202 */
203void POWER_EnterSleep(void);
204
205/*!
206 * @brief API to enter deep sleep power mode.
207 *
208 * @param activePart: should be a single or combine value of _power_deep_sleep_active .
209 * @return none
210 */
211void POWER_EnterDeepSleep(uint32_t activePart);
212
213/*!
214 * @brief API to enter power down mode.
215 *
216 * @param activePart: should be a single or combine value of _power_deep_sleep_active .
217 * @return none
218 */
219void POWER_EnterPowerDown(uint32_t activePart);
220
221/*!
222 * @brief API to enter deep power down mode.
223 *
224 * @return none
225 */
226void POWER_EnterDeepPowerDownMode(void);
227
228/*!
229 * @brief API to get sleep mode flag.
230 *
231 * @return sleep mode flag: 0 is active mode, 1 is sleep mode entered.
232 */
233static inline uint32_t POWER_GetSleepModeFlag(void)
234{
235 return (PMU->PCON & PMU_PCON_SLEEPFLAG_MASK) >> PMU_PCON_SLEEPFLAG_SHIFT;
236}
237
238/*!
239 * @brief API to clear sleep mode flag.
240 *
241 */
242static inline void POWER_ClrSleepModeFlag(void)
243{
244 PMU->PCON |= PMU_PCON_SLEEPFLAG_MASK;
245}
246
247/*!
248 * @brief API to get deep power down mode flag.
249 *
250 * @return sleep mode flag: 0 not deep power down, 1 is deep power down mode entered.
251 */
252static inline uint32_t POWER_GetDeepPowerDownModeFlag(void)
253{
254 return (PMU->PCON & PMU_PCON_DPDFLAG_MASK) >> PMU_PCON_DPDFLAG_SHIFT;
255}
256
257/*!
258 * @brief API to clear deep power down mode flag.
259 *
260 */
261static inline void POWER_ClrDeepPowerDownModeFlag(void)
262{
263 PMU->PCON |= PMU_PCON_DPDFLAG_MASK;
264}
265
266/*!
267 * @brief API to enable non deep power down mode.
268 *
269 * @param enable: true is enable non deep power down, otherwise disable.
270 */
271static inline void POWER_EnableNonDpd(bool enable)
272{
273 if (enable)
274 {
275 PMU->PCON |= PMU_PCON_NODPD_MASK;
276 }
277 else
278 {
279 PMU->PCON &= ~PMU_PCON_NODPD_MASK;
280 }
281}
282
283/*!
284 * @brief API to enable LPO.
285 *
286 * @param enable: true to enable LPO, false to disable LPO.
287 */
288static inline void POWER_EnableLPO(bool enable)
289{
290 if (enable)
291 {
292 PMU->DPDCTRL |= PMU_DPDCTRL_LPOSCEN_MASK;
293 }
294 else
295 {
296 PMU->DPDCTRL &= ~PMU_DPDCTRL_LPOSCEN_MASK;
297 }
298}
299
300/*!
301 * @brief API to enable LPO in deep power down mode.
302 *
303 * @param enable: true to enable LPO, false to disable LPO.
304 */
305static inline void POWER_EnableLPOInDeepPowerDownMode(bool enable)
306{
307 if (enable)
308 {
309 PMU->DPDCTRL |= PMU_DPDCTRL_LPOSCDPDEN_MASK;
310 }
311 else
312 {
313 PMU->DPDCTRL &= ~PMU_DPDCTRL_LPOSCDPDEN_MASK;
314 }
315}
316
317/*!
318 * @brief API to retore data to general purpose register which can be retain during deep power down mode.
319 * Note the kPMU_GenReg4 can retore 3 byte data only, so the general purpose register can store 19bytes data.
320 * @param index: general purpose data register index.
321 * @param data: data to restore.
322 */
323static inline void POWER_SetRetainData(power_gen_reg_t index, uint32_t data)
324{
325 if (index <= kPmu_GenReg3)
326 {
327 PMU->GPREG[index] = data;
328 }
329 else
330 {
331 /* only 26 bits can store in GPDATA field */
332 PMU->DPDCTRL = (PMU->DPDCTRL & (~PMU_DPDCTRL_GPDATA_MASK)) | PMU_DPDCTRL_GPDATA(data);
333 }
334}
335
336/*!
337 * @brief API to get data from general purpose register which retain during deep power down mode.
338 * Note the kPMU_GenReg4 can retore 3 byte data only, so the general purpose register can store 19bytes data.
339 * @param index: general purpose data register index.
340 * @return data stored in the general purpose register.
341 */
342static inline uint32_t POWER_GetRetainData(power_gen_reg_t index)
343{
344 if (index == kPmu_GenReg4)
345 {
346 return (PMU->DPDCTRL & PMU_DPDCTRL_GPDATA_MASK) >> PMU_DPDCTRL_GPDATA_SHIFT;
347 }
348
349 return PMU->GPREG[index];
350}
351
352/*!
353 * @brief API to enable external clock input for self wake up timer.
354 *
355 * @param enable: true is enable external clock input for self-wake-up timer, otherwise disable.
356 * @param enHysteresis: true is enable Hysteresis for the pin, otherwise disable.
357 */
358static inline void POWER_EnableWktClkIn(bool enable, bool enHysteresis)
359{
360 PMU->DPDCTRL = (PMU->DPDCTRL & (~(PMU_DPDCTRL_WAKEUPCLKHYS_MASK | PMU_DPDCTRL_WAKECLKPAD_DISABLE_MASK))) |
361 PMU_DPDCTRL_WAKECLKPAD_DISABLE(enable) | PMU_DPDCTRL_WAKEUPCLKHYS(enHysteresis);
362}
363
364/*!
365 * @brief API to enable wake up pin for deep power down mode.
366 *
367 * @param enable: true is enable, otherwise disable.
368 * @param enHysteresis: true is enable Hysteresis for the pin, otherwise disable.
369 */
370static inline void POWER_EnableWakeupPinForDeepPowerDown(bool enable, bool enHysteresis)
371{
372 PMU->DPDCTRL = (PMU->DPDCTRL & (~(PMU_DPDCTRL_WAKEUPHYS_MASK | PMU_DPDCTRL_WAKEPAD_DISABLE_MASK))) |
373 PMU_DPDCTRL_WAKEPAD_DISABLE(!enable) | PMU_DPDCTRL_WAKEUPHYS(enHysteresis);
374}
375
376/* @} */
377
378#ifdef __cplusplus
379}
380#endif
381
382/*!
383 * @}
384 */
385
386#endif /* _FSL_POWER_H_ */