aboutsummaryrefslogtreecommitdiff
path: root/lib/chibios-contrib/ext/mcux-sdk/devices/LPC802/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/LPC802/drivers/fsl_power.h
Diffstat (limited to 'lib/chibios-contrib/ext/mcux-sdk/devices/LPC802/drivers/fsl_power.h')
-rw-r--r--lib/chibios-contrib/ext/mcux-sdk/devices/LPC802/drivers/fsl_power.h358
1 files changed, 358 insertions, 0 deletions
diff --git a/lib/chibios-contrib/ext/mcux-sdk/devices/LPC802/drivers/fsl_power.h b/lib/chibios-contrib/ext/mcux-sdk/devices/LPC802/drivers/fsl_power.h
new file mode 100644
index 000000000..560b7d4c4
--- /dev/null
+++ b/lib/chibios-contrib/ext/mcux-sdk/devices/LPC802/drivers/fsl_power.h
@@ -0,0 +1,358 @@
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
32typedef 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_ACMP = SYSCON_PDRUNCFG_ACMP_MASK,
41 /*
42 This enum member has no practical meaning,it is used to avoid MISRA issue,
43 user should not trying to use it.
44 */
45 kPDRUNCFG_ForceUnsigned = (int)0x80000000U,
46} pd_bit_t;
47
48/*! @brief Deep sleep and power down mode wake up configurations */
49enum _power_wakeup
50{
51 kPDAWAKECFG_Wakeup_FRO_OUT = SYSCON_PDAWAKECFG_FROOUT_PD_MASK,
52 kPDAWAKECFG_Wakeup_FRO = SYSCON_PDAWAKECFG_FRO_PD_MASK,
53 kPDAWAKECFG_Wakeup_FLASH = SYSCON_PDAWAKECFG_FLASH_PD_MASK,
54 kPDAWAKECFG_Wakeup_BOD = SYSCON_PDAWAKECFG_BOD_PD_MASK,
55 kPDAWAKECFG_Wakeup_ADC = SYSCON_PDAWAKECFG_ADC_PD_MASK,
56 kPDAWAKECFG_Wakeup_LPOSC = SYSCON_PDAWAKECFG_LPOSC_PD_MASK,
57 kPDAWAKECFG_Wakeup_ACMP = SYSCON_PDAWAKECFG_ACMP_MASK,
58};
59
60/*! @brief Deep power down mode wake up pins */
61enum _power_dpd_wakeup_pin
62{
63 kPmu_Dpd_En_Pio0_15 = (uint32_t)(1 << 0),
64 kPmu_Dpd_En_Pio0_9 = (uint32_t)(1 << 1),
65 kPmu_Dpd_En_Pio0_8 = (uint32_t)(1 << 2),
66 kPmu_Dpd_En_Pio0_17 = (uint32_t)(1 << 3),
67 kPmu_Dpd_En_Pio0_13 = (uint32_t)(1 << 4),
68 kPmu_Dpd_En_Pio0_4 = (uint32_t)(1 << 5),
69 kPmu_Dpd_En_Pio0_11 = (uint32_t)(1 << 6),
70 kPmu_Dpd_En_Pio0_10 = (uint32_t)(1 << 7),
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_DeepSleepLPOscActive = SYSCON_PDSLEEPCFG_LPOSC_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, /*!< general purpose reguster4 */
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 enable LPO.
136 *
137 * @param enable: true to enable LPO, false to disable LPO.
138 */
139static inline void POWER_EnableLPO(bool enable)
140{
141 if (enable)
142 {
143 SYSCON->LPOSCCLKEN |= SYSCON_LPOSCCLKEN_WKT_MASK;
144 }
145 else
146 {
147 SYSCON->LPOSCCLKEN &= ~SYSCON_LPOSCCLKEN_WKT_MASK;
148 }
149}
150
151/*!
152 * @brief API to config wakeup configurations for deep sleep mode and power down mode.
153 *
154 * @param mask: wake up configurations for deep sleep mode and power down mode, reference _power_wakeup.
155 * @param powerDown: true is power down the mask part, false is powered part.
156 */
157static inline void POWER_WakeUpConfig(uint32_t mask, bool powerDown)
158{
159 if (powerDown)
160 {
161 SYSCON->PDAWAKECFG |= mask;
162 }
163 else
164 {
165 SYSCON->PDAWAKECFG &= ~mask;
166 }
167}
168
169/*!
170 * @brief API to config active part for deep sleep mode and power down mode.
171 *
172 * @param mask: active part configurations for deep sleep mode and power down mode, reference _power_deep_sleep_active.
173 * @param powerDown: true is power down the mask part, false is powered part.
174 */
175static inline void POWER_DeepSleepConfig(uint32_t mask, bool powerDown)
176{
177 if (powerDown)
178 {
179 SYSCON->PDSLEEPCFG |= mask;
180 }
181 else
182 {
183 SYSCON->PDSLEEPCFG &= ~mask;
184 }
185}
186
187/* @} */
188
189/*!
190 * @name ARM core Power Configuration
191 * @{
192 */
193
194/*!
195 * @brief API to enable deep sleep bit in the ARM Core.
196 *
197 * @return none
198 */
199static inline void POWER_EnableDeepSleep(void)
200{
201 SCB->SCR &= ~SCB_SCR_SLEEPDEEP_Msk;
202}
203
204/*!
205 * @brief API to disable deep sleep bit in the ARM Core.
206 *
207 * @return none
208 */
209static inline void POWER_DisableDeepSleep(void)
210{
211 SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;
212}
213
214/* @} */
215
216/*!
217 * @name PMU functionality
218 * @{
219 */
220
221/*!
222 * @brief API to enter sleep power mode.
223 *
224 * @return none
225 */
226void POWER_EnterSleep(void);
227
228/*!
229 * @brief API to enter deep sleep power mode.
230 *
231 * @param activePart: should be a single or combine value of _power_deep_sleep_active .
232 * @return none
233 */
234void POWER_EnterDeepSleep(uint32_t activePart);
235
236/*!
237 * @brief API to enter power down mode.
238 *
239 * @param activePart: should be a single or combine value of _power_deep_sleep_active .
240 * @return none
241 */
242void POWER_EnterPowerDown(uint32_t activePart);
243
244/*!
245 * @brief API to enter deep power down mode.
246 *
247 * @return none
248 */
249void POWER_EnterDeepPowerDownMode(void);
250
251/*!
252 * @brief API to get sleep mode flag.
253 *
254 * @return sleep mode flag: 0 is active mode, 1 is sleep mode entered.
255 */
256static inline uint32_t POWER_GetSleepModeFlag(void)
257{
258 return (PMU->PCON & PMU_PCON_SLEEPFLAG_MASK) >> PMU_PCON_SLEEPFLAG_SHIFT;
259}
260
261/*!
262 * @brief API to clear sleep mode flag.
263 *
264 */
265static inline void POWER_ClrSleepModeFlag(void)
266{
267 PMU->PCON |= PMU_PCON_SLEEPFLAG_MASK;
268}
269
270/*!
271 * @brief API to get deep power down mode flag.
272 *
273 * @return sleep mode flag: 0 not deep power down, 1 is deep power down mode entered.
274 */
275static inline uint32_t POWER_GetDeepPowerDownModeFlag(void)
276{
277 return (PMU->PCON & PMU_PCON_DPDFLAG_MASK) >> PMU_PCON_DPDFLAG_SHIFT;
278}
279
280/*!
281 * @brief API to clear deep power down mode flag.
282 *
283 */
284static inline void POWER_ClrDeepPowerDownModeFlag(void)
285{
286 PMU->PCON |= PMU_PCON_DPDFLAG_MASK;
287}
288
289/*!
290 * @brief API to clear wake up pin status flag.
291 *
292 */
293static inline void POWER_ClrWakeupPinFlag(void)
294{
295 PMU->WUSRCREG |= PMU_WUSRCREG_WUSRCREG_MASK;
296}
297
298/*!
299 * @name API to enable wake up pin for deep power down mode
300 *
301 * @param wakeup_pin wake up pin for which to enable.reference _power_dpd_wakeup_pin.
302 * @return none
303 */
304static inline void POWER_DeepPowerDownWakeupSourceSelect(uint32_t wakeup_pin)
305{
306 PMU->WUENAREG |= wakeup_pin;
307}
308
309/*!
310 * @brief API to enable non deep power down mode.
311 *
312 * @param enable: true is enable non deep power down, otherwise disable.
313 */
314static inline void POWER_EnableNonDpd(bool enable)
315{
316 if (enable)
317 {
318 PMU->PCON |= PMU_PCON_NODPD_MASK;
319 }
320 else
321 {
322 PMU->PCON &= ~PMU_PCON_NODPD_MASK;
323 }
324}
325
326/*!
327 * @brief API to retore data to general purpose register which can be retain during deep power down mode.
328 *
329 * @param index: general purpose data register index.
330 * @param data: data to restore.
331 */
332static inline void POWER_SetRetainData(power_gen_reg_t index, uint32_t data)
333{
334 PMU->GPREG[index] = data;
335}
336
337/*!
338 * @brief API to get data from general purpose register which retain during deep power down mode.
339 *
340 * @param index: general purpose data register index.
341 * @return data stored in the general purpose register.
342 */
343static inline uint32_t POWER_GetRetainData(power_gen_reg_t index)
344{
345 return PMU->GPREG[index];
346}
347
348/* @} */
349
350#ifdef __cplusplus
351}
352#endif
353
354/*!
355 * @}
356 */
357
358#endif /* _FSL_POWER_H_ */