1 /**
2  * @file    lp.h
3  * @brief   Low Power(LP) function prototypes and data types.
4  */
5 
6 /******************************************************************************
7  *
8  * Copyright (C) 2022-2023 Maxim Integrated Products, Inc. (now owned by
9  * Analog Devices, Inc.),
10  * Copyright (C) 2023-2024 Analog Devices, Inc.
11  *
12  * Licensed under the Apache License, Version 2.0 (the "License");
13  * you may not use this file except in compliance with the License.
14  * You may obtain a copy of the License at
15  *
16  *     http://www.apache.org/licenses/LICENSE-2.0
17  *
18  * Unless required by applicable law or agreed to in writing, software
19  * distributed under the License is distributed on an "AS IS" BASIS,
20  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21  * See the License for the specific language governing permissions and
22  * limitations under the License.
23  *
24  ******************************************************************************/
25 
26 /* Define to prevent redundant inclusion */
27 #ifndef LIBRARIES_PERIPHDRIVERS_INCLUDE_MAX32672_LP_H_
28 #define LIBRARIES_PERIPHDRIVERS_INCLUDE_MAX32672_LP_H_
29 
30 /* **** Includes **** */
31 #include <stdint.h>
32 #include "pwrseq_regs.h"
33 #include "mcr_regs.h"
34 #include "gcr_regs.h"
35 #include "adc.h"
36 #include "gpio.h"
37 #include "tmr.h"
38 
39 #ifdef __cplusplus
40 extern "C" {
41 #endif
42 
43 /**
44  * @defgroup pwrseq Low Power (LP)
45  * @ingroup periphlibs
46  * @{
47  */
48 
49 /**
50  * @brief   Enumeration type for voltage selection
51  *
52  */
53 typedef enum { MXC_LP_V0_9 = 0, MXC_LP_V1_0, MXC_LP_V1_1 } mxc_lp_ovr_t;
54 
55 /**
56  * @brief   Enumeration type for PM Mode
57  *
58  */
59 typedef enum {
60     MXC_LP_IPO = MXC_F_GCR_PM_IPO_PD,
61     MXC_LP_IBRO = MXC_F_GCR_PM_IBRO_PD,
62     MXC_LP_XRFO = MXC_F_GCR_PM_ERFO_PD
63 } mxc_lp_cfg_ds_pd_t;
64 
65 /**
66  * @brief      Places the device into SLEEP mode.  This function returns once an RTC or external interrupt occur.
67  */
68 void MXC_LP_EnterSleepMode(void);
69 
70 /**
71  * @brief      Places the device into DEEPSLEEP mode.  This function returns once an RTC or external interrupt occur.
72  */
73 void MXC_LP_EnterDeepSleepMode(void);
74 
75 /**
76  * @brief      Places the device into BACKUP mode.  CPU state is not maintained in this mode, so this function never returns.
77  *             Instead, the device will restart once an RTC or external interrupt occur.
78  */
79 void MXC_LP_EnterBackupMode(void);
80 
81 /**
82  * @brief      Places the device into Storage mode.  CPU state is not maintained in this mode, so this function never returns.
83  *             Instead, the device will restart once an RTC or external interrupt occur.
84  */
85 void MXC_LP_EnterStorageMode(void);
86 
87 /**
88  * @brief      Places the device into Shutdown mode.  CPU state is not maintained in this mode, so this function never returns.
89  *             Instead, the device will restart once an RTC, USB wakeup, or external interrupt occur.
90  */
91 void MXC_LP_EnterShutDownMode(void);
92 
93 /**
94  * @brief      Set ovr bits to set the voltage the micro will run at.
95  *
96  * @param[in]  ovr   The ovr options are only 0.9V, 1.0V, and 1.1V use enum mxc_lp_ovr_t
97  */
98 void MXC_LP_SetOVR(mxc_lp_ovr_t ovr);
99 
100 /**
101  * @brief      Enable retention regulator
102  */
103 void MXC_LP_RetentionRegEnable(void);
104 
105 /**
106  * @brief      Disable retention regulator
107  */
108 void MXC_LP_RetentionRegDisable(void);
109 
110 /**
111  * @brief      Is the retention regulator enabled
112  *
113  * @return     1 = enabled 0 =  disabled
114  */
115 int MXC_LP_RetentionRegIsEnabled(void);
116 
117 /**
118  * @brief      Turn bandgap on
119  */
120 void MXC_LP_BandgapOn(void);
121 
122 /**
123  * @brief      Turn bandgap off
124  */
125 void MXC_LP_BandgapOff(void);
126 
127 /**
128  * @brief      Is the bandgap on or off
129  *
130  * @return     1 = bandgap on , 0 = bandgap off
131  */
132 int MXC_LP_BandgapIsOn(void);
133 
134 /**
135  * @brief      Enable Power on Reset VDD Core Monitor
136  */
137 void MXC_LP_PORVCOREoreMonitorEnable(void);
138 
139 /**
140  * @brief      Disable Power on Reset VDD Core Monitor
141  */
142 void MXC_LP_PORVCOREoreMonitorDisable(void);
143 
144 /**
145  * @brief      Is Power on Reset VDD Core Monitor enabled
146  *
147  * @return     1 = enabled , 0 = disabled
148  */
149 int MXC_LP_PORVCOREoreMonitorIsEnabled(void);
150 
151 /**
152  * @brief      Enable LDO
153  */
154 void MXC_LP_LDOEnable(void);
155 
156 /**
157  * @brief      Disable LDO
158  */
159 void MXC_LP_LDODisable(void);
160 
161 /**
162  * @brief      Is LDO enabled
163  *
164  * @return     1 = enabled , 0 = disabled
165  */
166 int MXC_LP_LDOIsEnabled(void);
167 
168 /**
169  * @brief      Enable Fast wakeup
170  */
171 void MXC_LP_FastWakeupEnable(void);
172 
173 /**
174  * @brief      Disable Fast wakeup
175  */
176 void MXC_LP_FastWakeupDisable(void);
177 
178 /**
179  * @brief      Is Fast wake up is Enabled
180  *
181  * @return     1 = enabled , 0 = disabled
182  */
183 int MXC_LP_FastWakeupIsEnabled(void);
184 
185 /**
186  * @brief      clear all wake up status
187  */
188 void MXC_LP_ClearWakeStatus(void);
189 
190 /**
191  * @brief      Enables the selected GPIO port and its selected pins to wake up the device from any low power mode.
192  *             Call this function multiple times to enable pins on multiple ports.  This function does not configure
193  *             the GPIO pins nor does it setup their interrupt functionality.
194  * @param      wu_pins      The port and pins to configure as wakeup sources.  Only the gpio and mask fields of the
195  *                          structure are used.  The func and pad fields are ignored. \ref mxc_gpio_cfg_t
196  */
197 void MXC_LP_EnableGPIOWakeup(mxc_gpio_cfg_t *wu_pins);
198 
199 /**
200  * @brief      Disables the selected GPIO port and its selected pins as a wake up source.
201  *             Call this function multiple times to disable pins on multiple ports.
202  * @param      wu_pins      The port and pins to disable as wakeup sources.  Only the gpio and mask fields of the
203  *                          structure are used.  The func and pad fields are ignored. \ref mxc_gpio_cfg_t
204  */
205 void MXC_LP_DisableGPIOWakeup(mxc_gpio_cfg_t *wu_pins);
206 
207 /**
208  * @brief      Enables the RTC alarm to wake up the device from any low power mode.
209  */
210 void MXC_LP_EnableRTCAlarmWakeup(void);
211 
212 /**
213  * @brief      Disables the RTC alarm from waking up the device.
214  */
215 void MXC_LP_DisableRTCAlarmWakeup(void);
216 
217 /**
218  * @brief      Enables Timer to wakeup from any low power mode.
219  *
220  * @param      tmr  Pointer to timer module.
221  */
222 void MXC_LP_EnableTimerWakeup(mxc_tmr_regs_t *tmr);
223 
224 /**
225  * @brief      Disables Timer from waking up device.
226  *
227  * @param      tmr  Pointer to timer module.
228  */
229 void MXC_LP_DisableTimerWakeup(mxc_tmr_regs_t *tmr);
230 
231 /**
232  * @brief      Enables the USB to wake up the device from any low power mode.
233  */
234 void MXC_LP_EnableUSBWakeup(void);
235 
236 /**
237  * @brief      Disables the USB from waking up the device.
238  */
239 void MXC_LP_DisableUSBWakeup(void);
240 
241 /**
242  * @brief      Enables the HA0 to wake up the device from any low power mode.
243  */
244 void MXC_LP_EnableHA0Wakeup(void);
245 
246 /**
247  * @brief      Disables the HA)0 from waking up the device.
248  */
249 void MXC_LP_DisableHA0Wakeup(void);
250 /**
251  * @brief      Enables the HA1 to wake up the device from any low power mode.
252  */
253 void MXC_LP_EnableHA1Wakeup(void);
254 
255 /**
256  * @brief      Disables the HA1 from waking up the device.
257  */
258 void MXC_LP_DisableHA1Wakeup(void);
259 
260 /**
261  * @brief Enable the analog comparators as wakeup sources from low-power modes.
262  */
263 void MXC_LP_EnableComparatorWakeup(mxc_adc_comp_t comp);
264 
265 /**
266  * @brief Disable the analog comparators as wakeup sources from low-power modes.
267  */
268 void MXC_LP_DisableComparatorWakeup(mxc_adc_comp_t comp);
269 
270 /**
271  * @brief      Configure which clocks are powered down at deep sleep and which are not affected.
272  *
273  * @note       Need to configure all clocks at once any clock not passed in the mask will be unaffected by Deepsleep.  This will
274  *             always overwrite the previous settings of ALL clocks.
275  *
276  * @param[in]  mask  The mask of the clocks to power down when part goes into deepsleep
277  *
278  * @return     #E_NO_ERROR or error based on \ref MXC_Error_Codes
279  */
280 int MXC_LP_ConfigDeepSleepClocks(uint32_t mask);
281 
282 /**
283  * @brief      Enable NFC Oscilator Bypass
284  */
285 void MXC_LP_NFCOscBypassEnable(void);
286 
287 /**
288  * @brief      Disable NFC Oscilator Bypass
289  */
290 void MXC_LP_NFCOscBypassDisable(void);
291 
292 /**
293  * @brief      Is NFC Oscilator Bypass Enabled
294  *
295  * @return     1 = enabled, 0 = disabled
296  */
297 int MXC_LP_NFCOscBypassIsEnabled(void);
298 
299 /**
300  * @brief Enable System Ram 0 in light sleep
301  */
302 void MXC_LP_SysRam0LightSleepEnable(void);
303 
304 /**
305  * @brief Enable System Ram 1 in light sleep
306  */
307 void MXC_LP_SysRam1LightSleepEnable(void);
308 
309 /**
310  * @brief Enable System Ram 2 in light sleep
311  */
312 void MXC_LP_SysRam2LightSleepEnable(void);
313 
314 /**
315  * @brief Enable System Ram 3 in light sleep
316  */
317 void MXC_LP_SysRam3LightSleepEnable(void);
318 
319 /**
320  * @brief Enable Icache 0 in light sleep
321  */
322 void MXC_LP_ICache0LightSleepEnable(void);
323 
324 /**
325  * @brief Enable ROM 0 in light sleep
326  */
327 void MXC_LP_ROMLightSleepEnable(void);
328 
329 /**
330  * @brief Disable System Ram 0 in light sleep
331  */
332 void MXC_LP_SysRam0LightSleepDisable(void);
333 
334 /**
335  * @brief Disable System Ram 1 in light sleep
336  */
337 void MXC_LP_SysRam1LightSleepDisable(void);
338 
339 /**
340  * @brief Disable System Ram 2 in light sleep
341  */
342 void MXC_LP_SysRam2LightSleepDisable(void);
343 
344 /**
345  * @brief Disable System Ram 3 in light sleep
346  */
347 void MXC_LP_SysRam3LightSleepDisable(void);
348 
349 /**
350  * @brief Disable Icache 0 in light sleep
351  */
352 void MXC_LP_ICache0LightSleepDisable(void);
353 
354 /**
355  * @brief Disable ROM 0 in light sleep
356  */
357 void MXC_LP_ROMLightSleepDisable(void);
358 
359 /**
360  * @brief Shutdown System Ram 0
361  */
362 void MXC_LP_SysRam0Shutdown(void);
363 
364 /**
365  * @brief Wakeup System Ram 0
366  */
367 void MXC_LP_SysRam0PowerUp(void);
368 
369 /**
370  * @brief Shutdown System Ram 1
371  */
372 void MXC_LP_SysRam1Shutdown(void);
373 
374 /**
375  * @brief PowerUp System Ram 1
376  */
377 void MXC_LP_SysRam1PowerUp(void);
378 
379 /**
380  * @brief Shutdown System Ram 2
381  */
382 void MXC_LP_SysRam2Shutdown(void);
383 
384 /**
385  * @brief PowerUp System Ram 2
386  */
387 void MXC_LP_SysRam2PowerUp(void);
388 
389 /**
390  * @brief Shutdown System Ram 3
391  */
392 void MXC_LP_SysRam3Shutdown(void);
393 
394 /**
395  * @brief PowerUp System Ram 3
396  */
397 void MXC_LP_SysRam3PowerUp(void);
398 
399 /**
400  * @brief Shutdown System Ram 4
401  */
402 void MXC_LP_SysRam4Shutdown(void);
403 
404 /**
405  * @brief PowerUp System Ram 4
406  */
407 void MXC_LP_SysRam4PowerUp(void);
408 
409 /**
410  * @brief Shutdown System Ram 5
411  */
412 void MXC_LP_SysRam5Shutdown(void);
413 
414 /**
415  * @brief PowerUp System Ram 5
416  */
417 void MXC_LP_SysRam5PowerUp(void);
418 
419 /**
420  * @brief Shutdown Internal Cache
421  */
422 void MXC_LP_ICache0Shutdown(void);
423 
424 /**
425  * @brief PowerUp Internal Cache
426  */
427 void MXC_LP_ICache0PowerUp(void);
428 
429 /**
430  * @brief Shutdown Internal Cache XIP
431  */
432 void MXC_LP_ICacheXIPShutdown(void);
433 
434 /**
435  * @brief PowerUp Internal Cache XIP
436  */
437 void MXC_LP_ICacheXIPPowerUp(void);
438 
439 /**
440  * @brief Shutdown SRCC
441  */
442 void MXC_LP_SRCCShutdown(void);
443 
444 /**
445  * @brief PowerUp SRCC
446  */
447 void MXC_LP_SRCCPowerUp(void);
448 
449 /**
450  * @brief Shutdown USB FIFO
451  */
452 void MXC_LP_USBFIFOShutdown(void);
453 
454 /**
455  * @brief PowerUp USB FIFO
456  */
457 void MXC_LP_USBFIFOPowerUp(void);
458 
459 /**
460  * @brief Shutdown ROM
461  */
462 void MXC_LP_ROMShutdown(void);
463 
464 /**
465  * @brief PowerUp ROM
466  */
467 void MXC_LP_ROMPowerUp(void);
468 
469 /**@} end of group pwrseq */
470 
471 #ifdef __cplusplus
472 }
473 #endif
474 
475 #endif // LIBRARIES_PERIPHDRIVERS_INCLUDE_MAX32672_LP_H_
476