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_MAX32662_LP_H_ 28 #define LIBRARIES_PERIPHDRIVERS_INCLUDE_MAX32662_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 #include "tmr.h" 37 38 #ifdef __cplusplus 39 extern "C" { 40 #endif 41 42 /** 43 * @defgroup pwrseq Low Power (LP) 44 * @ingroup periphlibs 45 * @{ 46 */ 47 48 /** 49 * @brief Enumeration type for voltage selection 50 * 51 */ 52 typedef enum { MXC_LP_V0_9 = 0, MXC_LP_V1_0, MXC_LP_V1_1 } mxc_lp_ovr_t; 53 54 /** 55 * @brief Places the device into SLEEP mode. This function returns once any interrupt occurs. 56 * @note MXC_LP_ClearWakeStatus should be called before this function, to avoid immediately waking up again 57 */ 58 void MXC_LP_EnterSleepMode(void); 59 60 /** 61 * @brief Places the device into DEEPSLEEP mode. This function returns once an RTC or external interrupt occur. 62 * @note MXC_LP_ClearWakeStatus should be called before this function, to avoid immediately waking up again 63 */ 64 void MXC_LP_EnterDeepSleepMode(void); 65 66 /** 67 * @brief Places the device into BACKUP mode. CPU state is not maintained in this mode, so this function never returns. 68 * Instead, the device will restart once an RTC or external interrupt occur. 69 * @note MXC_LP_ClearWakeStatus should be called before this function, to avoid immediately waking up again 70 */ 71 void MXC_LP_EnterBackupMode(void); 72 73 /** 74 * @brief Places the device into Shutdown mode. CPU state is not maintained in this mode, so this function never returns. 75 * Instead, the device will restart once an RTC, USB wakeup, or external interrupt occur. 76 */ 77 void MXC_LP_EnterShutDownMode(void); 78 79 /** 80 * @brief Enables power to System RAM block 3. 81 */ 82 void MXC_LP_EnableSRAM3(void); 83 84 /** 85 * @brief Disables power to System RAM block 3. The contents of the RAM are destroyed. 86 */ 87 void MXC_LP_DisableSRAM3(void); 88 89 /** 90 * @brief Enables power to System RAM block 2. 91 */ 92 void MXC_LP_EnableSRAM2(void); 93 94 /** 95 * @brief Disables power to System RAM block 2. The contents of the RAM are destroyed. 96 */ 97 void MXC_LP_DisableSRAM2(void); 98 99 /** 100 * @brief Enables power to System RAM block 1. 101 */ 102 void MXC_LP_EnableSRAM1(void); 103 104 /** 105 * @brief Disables power to System RAM block 1. The contents of the RAM are destroyed. 106 */ 107 void MXC_LP_DisableSRAM1(void); 108 109 /** 110 * @brief Enables power to System RAM block 0. 111 */ 112 void MXC_LP_EnableSRAM0(void); 113 114 /** 115 * @brief Disables power to System RAM block 0. The contents of the RAM are destroyed. 116 */ 117 void MXC_LP_DisableSRAM0(void); 118 119 /** 120 * @brief Enables power to the specified System RAM block. 121 * 122 * @param[in] block The System RAM block to enable (0, 1, 2, or 3) 123 * 124 * @return E_BAD_PARAM if the block specified is invalid, otherwise E_SUCCESS 125 */ 126 int MXC_LP_EnableSRAM(int block); 127 128 /** 129 * @brief Disables power to the specified System RAM block. The contents of the RAM are destroyed. 130 * 131 * @param[in] block The System RAM block to enable (0, 1, 2, or 3) 132 * 133 * @return E_BAD_PARAM if the block specified is invalid, otherwise E_SUCCESS 134 */ 135 int MXC_LP_DisableSRAM(int block); 136 137 /** 138 * @brief NOT SUPPORTED. Set OVR bits to set the voltage the micro will run. 139 * 140 * @param[in] ovr The ovr options are only 0.9V, 1.0V, and 1.1V use enum mxc_lp_ovr_t 141 * 142 * @return E_NOT_SUPPORTED. 143 */ 144 int MXC_LP_SetOVR(mxc_lp_ovr_t ovr); 145 146 /** 147 * @brief Turn bandgap on 148 */ 149 void MXC_LP_BandgapOn(void); 150 151 /** 152 * @brief Turn bandgap off 153 */ 154 void MXC_LP_BandgapOff(void); 155 156 /** 157 * @brief Is the bandgap on or off 158 * 159 * @return 1 = bandgap on , 0 = bandgap off 160 */ 161 int MXC_LP_BandgapIsOn(void); 162 163 /** 164 * @brief clear all wake up status 165 */ 166 void MXC_LP_ClearWakeStatus(void); 167 168 /** 169 * @brief Enables the selected GPIO port and its selected pins to wake up the device from any low power mode. 170 * Call this function multiple times to enable pins on multiple ports. This function does not configure 171 * the GPIO pins nor does it setup their interrupt functionality. 172 * @param wu_pins The port and pins to configure as wakeup sources. Only the gpio and mask fields of the 173 * structure are used. The func and pad fields are ignored. 174 */ 175 176 void MXC_LP_EnableGPIOWakeup(const mxc_gpio_cfg_t *wu_pins); 177 178 /** 179 * @brief Disables the selected GPIO port and its selected pins as a wake up source. 180 * Call this function multiple times to disable pins on multiple ports. 181 * @param wu_pins The port and pins to disable as wakeup sources. Only the gpio and mask fields of the 182 * structure are used. The func and pad fields are ignored. 183 */ 184 void MXC_LP_DisableGPIOWakeup(const mxc_gpio_cfg_t *wu_pins); 185 186 /** 187 * @brief Enables the RTC alarm to wake up the device from any low power mode. 188 */ 189 void MXC_LP_EnableRTCAlarmWakeup(void); 190 191 /** 192 * @brief Disables the RTC alarm from waking up the device. 193 */ 194 void MXC_LP_DisableRTCAlarmWakeup(void); 195 196 /** 197 * @brief Enables Timer to wakeup from any low power mode. Only TMR3 is supported. 198 * 199 * @param tmr Pointer to timer module. 200 */ 201 void MXC_LP_EnableTimerWakeup(mxc_tmr_regs_t *tmr); 202 203 /** 204 * @brief Disables Timer from waking up device. Only TMR3 is supported. 205 * 206 * @param tmr Pointer to timer module. 207 */ 208 void MXC_LP_DisableTimerWakeup(mxc_tmr_regs_t *tmr); 209 210 /** 211 * @brief Enables the WUT alarm to wake up the device from any low power mode. 212 */ 213 void MXC_LP_EnableWUTAlarmWakeup(void); 214 215 /** 216 * @brief Disables the WUT alarm from waking up the device. 217 */ 218 void MXC_LP_DisableWUTAlarmWakeup(void); 219 220 /** 221 * @brief Configure which clocks are powered down at deep sleep and which are not affected. 222 * 223 * @note Need to configure all clocks at once any clock not passed in the mask will be unaffected by Deepsleep. This will 224 * always overwrite the previous settings of ALL clocks. 225 * 226 * @param[in] mask The mask of the clocks to power down when part goes into deepsleep 227 * 228 * @return #E_NO_ERROR or error based on /ref MXC_Error_Codes 229 */ 230 int MXC_LP_ConfigDeepSleepClocks(uint32_t mask); 231 232 /**@} end of group pwrseq */ 233 234 /** 235 * @brief Enable Internal Cache Controller RAM Light Sleep mode. 236 */ 237 238 void MXC_LP_EnableICacheLightSleep(void); 239 240 /** 241 * @brief Disable Internal Cache Controller RAM Light Sleep mode. 242 */ 243 void MXC_LP_DisableICacheLightSleep(void); 244 245 /** 246 * @brief Enable ROM Light Sleep mode. 247 */ 248 void MXC_LP_ROMLightSleepEnable(void); 249 250 /** 251 * @brief Disable ROM Light Sleep mode. 252 */ 253 void MXC_LP_RomLightSleepDisable(void); 254 255 /** 256 * @brief Enable Light Sleep mode for the specified System RAM instance 257 * 258 * @param[in] instance The System RAM instance to enable Light Sleep mode for (0, 1, 2, or 3) 259 * 260 * @return E_BAD_PARAM if the system RAM instance specified is invalid, otherwise E_SUCCESS 261 */ 262 int MXC_LP_EnableSysRAMLightSleep(int instance); 263 264 /** 265 * @brief Disable Light Sleep mode for the specified System RAM instance 266 * 267 * @param[in] instance The System RAM instance to disable Light Sleep mode for (0, 1, 2, or 3) 268 * 269 * @return E_BAD_PARAM if the system RAM instance specified is invalid, otherwise E_SUCCESS 270 */ 271 int MXC_LP_DisableSysRAMLightSleep(int instance); 272 273 #ifdef __cplusplus 274 } 275 #endif 276 277 #endif // LIBRARIES_PERIPHDRIVERS_INCLUDE_MAX32662_LP_H_ 278