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