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_MAX32570_LP_H_
28 #define LIBRARIES_PERIPHDRIVERS_INCLUDE_MAX32570_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 "gpio.h"
36 
37 #ifdef __cplusplus
38 extern "C" {
39 #endif
40 
41 /**
42  * @defgroup pwrseq Low Power (LP)
43  * @ingroup periphlibs
44  * @{
45  */
46 
47 /**
48  * @brief   Enumeration type for voltage selection
49  *
50  */
51 typedef enum { MXC_LP_V0_9 = 0, MXC_LP_V1_0, MXC_LP_V1_1 } mxc_lp_ovr_t;
52 
53 /**
54  * @brief   Enumeration type for PM Mode
55  *
56  */
57 typedef enum {
58     MXC_LP_ISO = MXC_F_GCR_PM_ISO_PD,
59     MXC_LP_IPO = MXC_F_GCR_PM_IPO_PD,
60     MXC_LP_IBRO = MXC_F_GCR_PM_IBRO_PD,
61     MXC_LP_XRFO = MXC_F_GCR_PM_ERFO_PD,
62     MXC_LP_NFC = MXC_F_GCR_PM_NFC_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 Shutdown mode.  CPU state is not maintained in this mode, so this function never returns.
83  *             Instead, the device will restart once an RTC, USB wakeup, or external interrupt occur.
84  */
85 void MXC_LP_EnterShutDownMode(void);
86 
87 /**
88  * @brief      Set ovr bits to set the voltage the micro will run at.
89  *
90  * @param[in]  ovr   The ovr options are only 0.9V, 1.0V, and 1.1V use enum mxc_lp_ovr_t
91  */
92 void MXC_LP_SetOVR(mxc_lp_ovr_t ovr);
93 
94 /**
95  * @brief      Enable retention regulator
96  */
97 void MXC_LP_RetentionRegEnable(void);
98 
99 /**
100  * @brief      Disable retention regulator
101  */
102 void MXC_LP_RetentionRegDisable(void);
103 
104 /**
105  * @brief      Is the retention regulator enabled
106  *
107  * @return     1 = enabled 0 =  disabled
108  */
109 int MXC_LP_RetentionRegIsEnabled(void);
110 
111 /**
112  * @brief      Turn bandgap on
113  */
114 void MXC_LP_BandgapOn(void);
115 
116 /**
117  * @brief      Turn bandgap off
118  */
119 void MXC_LP_BandgapOff(void);
120 
121 /**
122  * @brief      Is the bandgap on or off
123  *
124  * @return     1 = bandgap on , 0 = bandgap off
125  */
126 int MXC_LP_BandgapIsOn(void);
127 
128 /**
129  * @brief      Enable Power on Reset VDD Core Monitor
130  */
131 void MXC_LP_PORVCOREoreMonitorEnable(void);
132 
133 /**
134  * @brief      Disable Power on Reset VDD Core Monitor
135  */
136 void MXC_LP_PORVCOREoreMonitorDisable(void);
137 
138 /**
139  * @brief      Is Power on Reset VDD Core Monitor enabled
140  *
141  * @return     1 = enabled , 0 = disabled
142  */
143 int MXC_LP_PORVCOREoreMonitorIsEnabled(void);
144 
145 /**
146  * @brief      Enable LDO
147  */
148 void MXC_LP_LDOEnable(void);
149 
150 /**
151  * @brief      Disable LDO
152  */
153 void MXC_LP_LDODisable(void);
154 
155 /**
156  * @brief      Is LDO enabled
157  *
158  * @return     1 = enabled , 0 = disabled
159  */
160 int MXC_LP_LDOIsEnabled(void);
161 
162 /**
163  * @brief      Enable Fast wakeup
164  */
165 void MXC_LP_FastWakeupEnable(void);
166 
167 /**
168  * @brief      Disable Fast wakeup
169  */
170 void MXC_LP_FastWakeupDisable(void);
171 
172 /**
173  * @brief      Is Fast wake up is Enabled
174  *
175  * @return     1 = enabled , 0 = disabled
176  */
177 int MXC_LP_FastWakeupIsEnabled(void);
178 
179 /**
180  * @brief      clear all wake up status
181  */
182 void MXC_LP_ClearWakeStatus(void);
183 
184 /**
185  * @brief      Enables the selected GPIO port and its selected pins to wake up the device from any low power mode.
186  *             Call this function multiple times to enable pins on multiple ports.  This function does not configure
187  *             the GPIO pins nor does it setup their interrupt functionality.
188  * @param      wu_pins      The port and pins to configure as wakeup sources.  Only the gpio and mask fields of the
189  *                          structure are used.  The func and pad fields are ignored. \ref mxc_gpio_cfg_t
190  */
191 void MXC_LP_EnableGPIOWakeup(mxc_gpio_cfg_t *wu_pins);
192 
193 /**
194  * @brief      Disables the selected GPIO port and its selected pins as a wake up source.
195  *             Call this function multiple times to disable pins on multiple ports.
196  * @param      wu_pins      The port and pins to disable as wakeup sources.  Only the gpio and mask fields of the
197  *                          structure are used.  The func and pad fields are ignored. \ref mxc_gpio_cfg_t
198  */
199 void MXC_LP_DisableGPIOWakeup(mxc_gpio_cfg_t *wu_pins);
200 
201 /**
202  * @brief      Enables the RTC alarm to wake up the device from any low power mode.
203  */
204 void MXC_LP_EnableRTCAlarmWakeup(void);
205 
206 /**
207  * @brief      Disables the RTC alarm from waking up the device.
208  */
209 void MXC_LP_DisableRTCAlarmWakeup(void);
210 /**
211  * @brief      Enables the USB to wake up the device from any low power mode.
212  */
213 void MXC_LP_EnableUSBWakeup(void);
214 
215 /**
216  * @brief      Disables the USB from waking up the device.
217  */
218 void MXC_LP_DisableUSBWakeup(void);
219 
220 /**
221  * @brief      Enables the HA0 to wake up the device from any low power mode.
222  */
223 void MXC_LP_EnableHA0Wakeup(void);
224 
225 /**
226  * @brief      Disables the HA)0 from waking up the device.
227  */
228 void MXC_LP_DisableHA0Wakeup(void);
229 
230 /**
231  * @brief      Enables the HA1 to wake up the device from any low power mode.
232  */
233 void MXC_LP_EnableHA1Wakeup(void);
234 
235 /**
236  * @brief      Disables the HA1 from waking up the device.
237  */
238 void MXC_LP_DisableHA1Wakeup(void);
239 
240 /**
241  * @brief      Configure which clocks are powered down at deep sleep and which are not affected.
242  *
243  * @note       Need to configure all clocks at once any clock not passed in the mask will be unaffected by Deepsleep.  This will
244  *             always overwrite the previous settings of ALL clocks.
245  *
246  * @param[in]  mask  The mask of the clocks to power down when part goes into deepsleep
247  *
248  * @return     #E_NO_ERROR or error based on \ref MXC_Error_Codes
249  */
250 int MXC_LP_ConfigDeepSleepClocks(uint32_t mask);
251 
252 /**
253  * @brief      Enable NFC Oscilator Bypass
254  */
255 void MXC_LP_NFCOscBypassEnable(void);
256 
257 /**
258  * @brief      Disable NFC Oscilator Bypass
259  */
260 void MXC_LP_NFCOscBypassDisable(void);
261 
262 /**
263  * @brief      Is NFC Oscilator Bypass Enabled
264  *
265  * @return     1 = enabled, 0 = disabled
266  */
267 int MXC_LP_NFCOscBypassIsEnabled(void);
268 
269 /**
270  * @brief Enable System Ram 0 in light sleep
271  */
272 void MXC_LP_SysRam0LightSleepEnable(void);
273 
274 /**
275  * @brief Enable System Ram 1 in light sleep
276  */
277 void MXC_LP_SysRam1LightSleepEnable(void);
278 
279 /**
280  * @brief Enable System Ram 2 in light sleep
281  */
282 void MXC_LP_SysRam2LightSleepEnable(void);
283 
284 /**
285  * @brief Enable System Ram 3 in light sleep
286  */
287 void MXC_LP_SysRam3LightSleepEnable(void);
288 
289 /**
290  * @brief Enable System Ram 4 in light sleep
291  */
292 void MXC_LP_SysRam4LightSleepEnable(void);
293 
294 /**
295  * @brief Enable System Ram 5 in light sleep
296  */
297 void MXC_LP_SysRam5LightSleepEnable(void);
298 
299 /**
300  * @brief Enable Icache 0 in light sleep
301  */
302 void MXC_LP_ICache0LightSleepEnable(void);
303 
304 /**
305  * @brief Enable Icache XIP in light sleep
306  */
307 void MXC_LP_ICacheXIPLightSleepEnable(void);
308 
309 /**
310  * @brief Enable System Cache in light sleep
311  */
312 void MXC_LP_SRCCLightSleepEnable(void);
313 
314 /**
315  * @brief Enable Crypto in light sleep
316  */
317 void MXC_LP_CryptoLightSleepEnable(void);
318 
319 /**
320  * @brief Enable USB in light sleep
321  */
322 void MXC_LP_USBFIFOLightSleepEnable(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 System Ram 4 in light sleep
351  */
352 void MXC_LP_SysRam4LightSleepDisable(void);
353 
354 /**
355  * @brief Disable System Ram 5 in light sleep
356  */
357 void MXC_LP_SysRam5LightSleepDisable(void);
358 
359 /**
360  * @brief Disable Icache 0 in light sleep
361  */
362 void MXC_LP_ICache0LightSleepDisable(void);
363 
364 /**
365  * @brief Disable Icache XIP in light sleep
366  */
367 void MXC_LP_ICacheXIPLightSleepDisable(void);
368 
369 /**
370  * @brief Disable System Cache in light sleep
371  */
372 void MXC_LP_SRCCLightSleepDisable(void);
373 
374 /**
375  * @brief Disable Crypto in light sleep
376  */
377 void MXC_LP_CryptoLightSleepDisable(void);
378 
379 /**
380  * @brief Disable USB in light sleep
381  */
382 void MXC_LP_USBFIFOLightSleepDisable(void);
383 
384 /**
385  * @brief Disable ROM 0 in light sleep
386  */
387 void MXC_LP_ROMLightSleepDisable(void);
388 
389 /**
390  * @brief Shutdown System Ram 0
391  */
392 void MXC_LP_SysRam0Shutdown(void);
393 
394 /**
395  * @brief Wakeup System Ram 0
396  */
397 void MXC_LP_SysRam0PowerUp(void);
398 
399 /**
400  * @brief Shutdown System Ram 1
401  */
402 void MXC_LP_SysRam1Shutdown(void);
403 
404 /**
405  * @brief PowerUp System Ram 1
406  */
407 void MXC_LP_SysRam1PowerUp(void);
408 
409 /**
410  * @brief Shutdown System Ram 2
411  */
412 void MXC_LP_SysRam2Shutdown(void);
413 
414 /**
415  * @brief PowerUp System Ram 2
416  */
417 void MXC_LP_SysRam2PowerUp(void);
418 
419 /**
420  * @brief Shutdown System Ram 3
421  */
422 void MXC_LP_SysRam3Shutdown(void);
423 
424 /**
425  * @brief PowerUp System Ram 3
426  */
427 void MXC_LP_SysRam3PowerUp(void);
428 
429 /**
430  * @brief Shutdown System Ram 4
431  */
432 void MXC_LP_SysRam4Shutdown(void);
433 
434 /**
435  * @brief PowerUp System Ram 4
436  */
437 void MXC_LP_SysRam4PowerUp(void);
438 
439 /**
440  * @brief Shutdown System Ram 5
441  */
442 void MXC_LP_SysRam5Shutdown(void);
443 
444 /**
445  * @brief PowerUp System Ram 5
446  */
447 void MXC_LP_SysRam5PowerUp(void);
448 
449 /**
450  * @brief Shutdown Internal Cache
451  */
452 void MXC_LP_ICache0Shutdown(void);
453 
454 /**
455  * @brief PowerUp Internal Cache
456  */
457 void MXC_LP_ICache0PowerUp(void);
458 
459 /**
460  * @brief Shutdown Internal Cache XIP
461  */
462 void MXC_LP_ICacheXIPShutdown(void);
463 
464 /**
465  * @brief PowerUp Internal Cache XIP
466  */
467 void MXC_LP_ICacheXIPPowerUp(void);
468 
469 /**
470  * @brief Shutdown SRCC
471  */
472 void MXC_LP_SRCCShutdown(void);
473 
474 /**
475  * @brief PowerUp SRCC
476  */
477 void MXC_LP_SRCCPowerUp(void);
478 
479 /**
480  * @brief Shutdown USB FIFO
481  */
482 void MXC_LP_USBFIFOShutdown(void);
483 
484 /**
485  * @brief PowerUp USB FIFO
486  */
487 void MXC_LP_USBFIFOPowerUp(void);
488 
489 /**
490  * @brief Shutdown ROM
491  */
492 void MXC_LP_ROMShutdown(void);
493 
494 /**
495  * @brief PowerUp ROM
496  */
497 void MXC_LP_ROMPowerUp(void);
498 
499 /**@} end of group pwrseq */
500 
501 #ifdef __cplusplus
502 }
503 #endif
504 
505 #endif // LIBRARIES_PERIPHDRIVERS_INCLUDE_MAX32570_LP_H_
506