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_MAX78000_LP_H_
28 #define LIBRARIES_PERIPHDRIVERS_INCLUDE_MAX78000_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 "lpcmp.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_cfg_ds_pd_t;
63 
64 /**
65  * @brief      Places the device into SLEEP mode.  This function returns once an RTC or external interrupt occur.
66  */
67 void MXC_LP_EnterSleepMode(void);
68 
69 /**
70  * @brief      Places the device into Low Power mode.  This function returns once an RTC or external interrupt occur.
71  */
72 void MXC_LP_EnterLowPowerMode(void);
73 
74 /**
75  * @brief      Places the device into Micro Power mode.  This function returns once an RTC or external interrupt occur.
76  */
77 void MXC_LP_EnterMicroPowerMode(void);
78 
79 /**
80  * @brief      Places the device into Standby mode.  This function returns once an RTC or external interrupt occur.
81  */
82 void MXC_LP_EnterStandbyMode(void);
83 
84 /**
85  * @brief      Places the device into BACKUP mode.  CPU state is not maintained in this mode, so this function never returns.
86  *             Instead, the device will restart once an RTC or external interrupt occur.
87  */
88 void MXC_LP_EnterBackupMode(void);
89 
90 /**
91  * @brief      Places the device into Shutdown mode.  CPU state is not maintained in this mode, so this function never returns.
92  *             Instead, the device will restart once an RTC, USB wakeup, or external interrupt occur.
93  */
94 void MXC_LP_EnterPowerDownMode(void);
95 
96 /**
97  * @brief      Set ovr bits to set the voltage the micro will run at.
98  *
99  * @param[in]  ovr   The ovr options are only 0.9V, 1.0V, and 1.1V use enum mxc_lp_ovr_t
100  */
101 void MXC_LP_SetOVR(mxc_lp_ovr_t ovr);
102 
103 /**
104  * @brief      Turn bandgap on
105  */
106 void MXC_LP_BandgapOn(void);
107 
108 /**
109  * @brief      Turn bandgap off
110  */
111 void MXC_LP_BandgapOff(void);
112 
113 /**
114  * @brief      Is the bandgap on or off
115  *
116  * @return     1 = bandgap on , 0 = bandgap off
117  */
118 int MXC_LP_BandgapIsOn(void);
119 
120 /**
121  * @brief      clear all wake up status
122  */
123 void MXC_LP_ClearWakeStatus(void);
124 
125 /**
126  * @brief      Enables the selected GPIO port and its selected pins to wake up the device from any low power mode.
127  *             Call this function multiple times to enable pins on multiple ports.  This function does not configure
128  *             the GPIO pins nor does it setup their interrupt functionality.
129  * @param      wu_pins      The port and pins to configure as wakeup sources.  Only the gpio and mask fields of the
130  *                          structure are used.  The func and pad fields are ignored.
131  */
132 
133 void MXC_LP_EnableGPIOWakeup(mxc_gpio_cfg_t *wu_pins);
134 
135 /**
136  * @brief      Disables the selected GPIO port and its selected pins as a wake up source.
137  *             Call this function multiple times to disable pins on multiple ports.
138  * @param      wu_pins      The port and pins to disable as wakeup sources.  Only the gpio and mask fields of the
139  *                          structure are used.  The func and pad fields are ignored.
140  */
141 void MXC_LP_DisableGPIOWakeup(mxc_gpio_cfg_t *wu_pins);
142 
143 /**
144  * @brief      Enables the RTC alarm to wake up the device from any low power mode.
145  */
146 void MXC_LP_EnableRTCAlarmWakeup(void);
147 
148 /**
149  * @brief      Disables the RTC alarm from waking up the device.
150  */
151 void MXC_LP_DisableRTCAlarmWakeup(void);
152 
153 /**
154  * @brief      Enables Timer to wakeup from any low power mode.
155  *
156  * @param      tmr  Pointer to timer module.
157  */
158 void MXC_LP_EnableTimerWakeup(mxc_tmr_regs_t *tmr);
159 
160 /**
161  * @brief      Disables Timer from waking up device.
162  *
163  * @param      tmr  Pointer to timer module.
164  */
165 void MXC_LP_DisableTimerWakeup(mxc_tmr_regs_t *tmr);
166 
167 /**
168  * @brief      Enables the WUT alarm to wake up the device from any low power mode.
169  */
170 void MXC_LP_EnableWUTAlarmWakeup(void);
171 
172 /**
173  * @brief      Disables the WUT alarm from waking up the device.
174  */
175 void MXC_LP_DisableWUTAlarmWakeup(void);
176 
177 /**
178  * @brief      Enables the LPCMP to wake up the device from any low power mode.
179  */
180 void MXC_LP_EnableLPCMPWakeup(mxc_lpcmp_cmpsel_t cmp);
181 
182 /**
183  * @brief      Disables the LPCMP from waking up the device.
184  */
185 void MXC_LP_DisableLPCMPWakeup(mxc_lpcmp_cmpsel_t cmp);
186 
187 /**
188  * @brief      Configure which clocks are powered down at deep sleep and which are not affected.
189  *
190  * @note       Need to configure all clocks at once any clock not passed in the mask will be unaffected by Deepsleep.  This will
191  *             always overwrite the previous settings of ALL clocks.
192  *
193  * @param[in]  mask  The mask of the clocks to power down when part goes into deepsleep
194  *
195  * @return     #E_NO_ERROR or error based on /ref MXC_Error_Codes
196  */
197 int MXC_LP_ConfigDeepSleepClocks(uint32_t mask);
198 
199 /**
200  * @brief Shutdown System Ram 0
201  */
202 void MXC_LP_SysRam0Shutdown(void);
203 
204 /**
205  * @brief Wakeup System Ram 0
206  */
207 void MXC_LP_SysRam0PowerUp(void);
208 
209 /**
210  * @brief Shutdown System Ram 1
211  */
212 void MXC_LP_SysRam1Shutdown(void);
213 
214 /**
215  * @brief PowerUp System Ram 1
216  */
217 void MXC_LP_SysRam1PowerUp(void);
218 
219 /**
220  * @brief Shutdown System Ram 2
221  */
222 void MXC_LP_SysRam2Shutdown(void);
223 
224 /**
225  * @brief PowerUp System Ram 2
226  */
227 void MXC_LP_SysRam2PowerUp(void);
228 
229 /**
230  * @brief Shutdown System Ram 3
231  */
232 void MXC_LP_SysRam3Shutdown(void);
233 
234 /**
235  * @brief PowerUp System Ram 3
236  */
237 void MXC_LP_SysRam3PowerUp(void);
238 
239 /**@} end of group pwrseq */
240 
241 #ifdef __cplusplus
242 }
243 #endif
244 
245 #endif // LIBRARIES_PERIPHDRIVERS_INCLUDE_MAX78000_LP_H_
246