1 /** 2 * @file lp.h 3 * @brief Low power 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_MAX32665_LP_H_ 28 #define LIBRARIES_PERIPHDRIVERS_INCLUDE_MAX32665_LP_H_ 29 30 /* **** Includes **** */ 31 #include <stdint.h> 32 #include "gpio.h" 33 #include "pwrseq_regs.h" 34 #include "mcr_regs.h" 35 #include "gcr_regs.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 typedef enum { 48 MXC_RETAIN_NONE = MXC_S_PWRSEQ_LPCN_RAMRET_DIS, 49 MXC_RETAIN_32k = MXC_S_PWRSEQ_LPCN_RAMRET_EN1, 50 MXC_RETAIN_64k = MXC_S_PWRSEQ_LPCN_RAMRET_EN2, 51 MXC_RETAIN_ALL = MXC_S_PWRSEQ_LPCN_RAMRET_EN3 52 } mxc_ram_retained_t; 53 54 /** 55 * @brief Enumeration type for voltage selection 56 * 57 */ 58 typedef enum { MXC_LP_V0_9 = 0, MXC_LP_V1_0, MXC_LP_V1_1 } mxc_lp_ovr_t; 59 60 /** 61 * @brief Enumeration type for PM Mode 62 * 63 */ 64 typedef enum { 65 MXC_LP_HIRC = MXC_F_GCR_PM_HIRCPD, 66 MXC_LP_HIRC96M = MXC_F_GCR_PM_HIRC96MPD, 67 MXC_LP_HIRC8M = MXC_F_GCR_PM_HIRC8MPD, 68 MXC_LP_XTAL = MXC_F_GCR_PM_XTALPB, 69 } mxc_lp_cfg_ds_pd_t; 70 71 /** 72 * @brief Clears the wakup status bits. 73 */ 74 void MXC_LP_ClearWakeStatus(void); 75 76 /** 77 * @brief Enables the selected GPIO port and its selected pins to wake up the device from any low power mode. 78 * Call this function multiple times to enable pins on multiple ports. This function does not configure 79 * the GPIO pins nor does it setup their interrupt functionality. 80 * @param wu_pins The port and pins to configure as wakeup sources. Only the gpio and mask fields of the 81 * structure are used. The func and pad fields are ignored. 82 */ 83 void MXC_LP_EnableGPIOWakeup(mxc_gpio_cfg_t *wu_pins); 84 85 /** 86 * @brief Disables the selected GPIO port and its selected pins as a wake up source. 87 * Call this function multiple times to disable pins on multiple ports. 88 * @param wu_pins The port and pins to disable as wakeup sources. Only the gpio and mask fields of the 89 * structure are used. The func and pad fields are ignored. 90 */ 91 void MXC_LP_DisableGPIOWakeup(mxc_gpio_cfg_t *wu_pins); 92 93 /** 94 * @brief Enables the RTC alarm to wake up the device from any low power mode. 95 */ 96 void MXC_LP_EnableRTCAlarmWakeup(void); 97 98 /** 99 * @brief Disables the RTC alarm from waking up the device. 100 */ 101 void MXC_LP_DisableRTCAlarmWakeup(void); 102 103 /** 104 * @brief Enables the WUT alarm to wake up the device from any low power mode. 105 */ 106 void MXC_LP_EnableWUTAlarmWakeup(void); 107 108 /** 109 * @brief Disables the WUT alarm from waking up the device. 110 */ 111 void MXC_LP_DisableWUTAlarmWakeup(void); 112 113 /** 114 * @brief Puts System Ram 0 in light sleep 115 */ 116 void MXC_LP_SysRam0LightSleepEnable(void); 117 118 /** 119 * @brief Puts System Ram 1 in light sleep 120 */ 121 void MXC_LP_SysRam1LightSleepEnable(void); 122 123 /** 124 * @brief Puts System Ram 2 in light sleep 125 */ 126 void MXC_LP_SysRam2LightSleepEnable(void); 127 128 /** 129 * @brief Puts System Ram 3 in light sleep 130 */ 131 void MXC_LP_SysRam3LightSleepEnable(void); 132 133 /** 134 * @brief Puts System Ram 4 in light sleep 135 */ 136 void MXC_LP_SysRam4LightSleepEnable(void); 137 138 /** 139 * @brief Puts System Ram 5 in light sleep 140 */ 141 void MXC_LP_SysRam5LightSleepEnable(void); 142 143 /** 144 * @brief Shutdown System Ram 0 145 */ 146 void MXC_LP_SysRam0Shutdown(void); 147 148 /** 149 * @brief Wakeup System Ram 0 150 */ 151 void MXC_LP_SysRam0PowerUp(void); 152 153 /** 154 * @brief Shutdown System Ram 1 155 */ 156 void MXC_LP_SysRam1Shutdown(void); 157 158 /** 159 * @brief Wakeup System Ram 1 160 */ 161 void MXC_LP_SysRam1PowerUp(void); 162 163 /** 164 * @brief Shutdown System Ram 2 165 */ 166 void MXC_LP_SysRam2Shutdown(void); 167 168 /** 169 * @brief Wakeup System Ram 2 170 */ 171 void MXC_LP_SysRam2PowerUp(void); 172 173 /** 174 * @brief Shutdown System Ram 3 175 */ 176 void MXC_LP_SysRam3Shutdown(void); 177 178 /** 179 * @brief Wakeup System Ram 3 180 */ 181 void MXC_LP_SysRam3PowerUp(void); 182 183 /** 184 * @brief Shutdown System Ram 4 185 */ 186 void MXC_LP_SysRam4Shutdown(void); 187 188 /** 189 * @brief Wakeup System Ram 4 190 */ 191 void MXC_LP_SysRam4PowerUp(void); 192 193 /** 194 * @brief Shutdown System Ram 5 195 */ 196 void MXC_LP_SysRam5Shutdown(void); 197 198 /** 199 * @brief Wakeup System Ram 5 200 */ 201 void MXC_LP_SysRam5PowerUp(void); 202 203 /** 204 * @brief Shutdown Internal Cache 205 */ 206 void MXC_LP_ICache0Shutdown(void); 207 208 /** 209 * @brief Wakeup Internal Cache 210 */ 211 void MXC_LP_ICache0PowerUp(void); 212 213 /** 214 * @brief Shutdown Internal Cache XIP 215 */ 216 void MXC_LP_ICacheXIPShutdown(void); 217 218 /** 219 * @brief Wakeup Internal Cache XIP 220 */ 221 void MXC_LP_ICacheXIPPowerUp(void); 222 223 /** 224 * @brief Shutdown Crypto 225 */ 226 void MXC_LP_CryptoShutdown(void); 227 228 /** 229 * @brief Wakeup Crypto 230 */ 231 void MXC_LP_CryptoPowerUp(void); 232 233 /** 234 * @brief Shutdown USB FIFO 235 */ 236 void MXC_LP_USBFIFOShutdown(void); 237 238 /** 239 * @brief Wakeup USB FIFO 240 */ 241 void MXC_LP_USBFIFOPowerUp(void); 242 243 /** 244 * @brief Shutdown ROM 245 */ 246 void MXC_LP_ROM0Shutdown(void); 247 248 /** 249 * @brief Wakeup ROM 250 */ 251 void MXC_LP_ROM0PowerUp(void); 252 253 /** 254 * @brief Shutdown ROM 1 255 */ 256 void MXC_LP_ROM1Shutdown(void); 257 258 /** 259 * @brief Wakeup ROM 1 260 */ 261 void MXC_LP_ROM1PowerUp(void); 262 263 /** 264 * @brief Shutdown Internal Cache 1 265 */ 266 void MXC_LP_ICache1Shutdown(void); 267 268 /** 269 * @brief Wakeup Internal Cache 1 270 */ 271 void MXC_LP_ICache1PowerUp(void); 272 273 /** 274 * @brief Disable USB Software Low Power 275 */ 276 void MXC_LP_USBSWLPDisable(void); 277 278 /** 279 * @brief Enable USB Software Low Power 280 */ 281 void MXC_LP_USBSWLPEnable(void); 282 283 /** 284 * @brief Power Down VDD2 285 */ 286 void MXC_LP_VDD2PowerDown(void); 287 288 /** 289 * @brief Power up VDD2 290 */ 291 void MXC_LP_VDD2PowerUp(void); 292 293 /** 294 * @brief Power Down VDD3 295 */ 296 void MXC_LP_VDD3PowerDown(void); 297 298 /** 299 * @brief Power Up VDD3 300 */ 301 void MXC_LP_VDD3PowerUp(void); 302 303 /** 304 * @brief Power Down VDD4 305 */ 306 void MXC_LP_VDD4PowerDown(void); 307 308 /** 309 * @brief Power Up VDD4 310 */ 311 void MXC_LP_VDD4PowerUp(void); 312 313 /** 314 * @brief Power Down VDD5 315 */ 316 void MXC_LP_VDD5PowerDown(void); 317 318 /** 319 * @brief Power Up VDD5 320 */ 321 void MXC_LP_VDD5PowerUp(void); 322 323 /** 324 * @brief Power Down SIMOV regB 325 */ 326 void MXC_LP_SIMOVregBPowerDown(void); 327 328 /** 329 * @brief Power Up SIMOV regB 330 */ 331 void MXC_LP_SIMOVregBPowerUp(void); 332 333 /** 334 * @brief Power Down SIMOV regD 335 */ 336 void MXC_LP_SIMOVregDPowerDown(void); 337 338 /** 339 * @brief Power Up SIMOV regD 340 */ 341 void MXC_LP_SIMOVregDPowerUp(void); 342 343 /** 344 * @brief Enable Fast Wakeup 345 * @details Deprecated due to issues with SIMO in wakeup. 346 */ 347 void __attribute__((deprecated("Causes SIMO soft start in wakeup"))) MXC_LP_FastWakeupEnable(void); 348 349 /** 350 * @brief Disable Fast Wakeup 351 */ 352 void MXC_LP_FastWakeupDisable(void); 353 354 /** 355 * @brief Enables the selected amount of RAM retention in backup mode 356 * Using any RAM retention removes the ability to shut down VcoreB 357 */ 358 void MXC_LP_SetRAMRetention(mxc_ram_retained_t ramRetained); 359 360 /** 361 * @brief Places the device into SLEEP mode. This function returns once any interrupt occurs. 362 */ 363 void MXC_LP_EnterSleepMode(void); 364 365 /** 366 * @brief Places the device into DEEPSLEEP mode. This function returns once an RTC or external interrupt occur. 367 */ 368 void MXC_LP_EnterDeepSleepMode(void); 369 370 /** 371 * @brief Places the device into BACKGROUND mode. This function returns once an RTC or external interrupt occur. 372 */ 373 void MXC_LP_EnterBackgroundMode(void); 374 375 /** 376 * @brief Places the device into BACKUP mode. CPU state is not maintained in this mode, so this function never returns. 377 * Instead, the device will restart once an RTC or external interrupt occur. 378 * @param func Function that backup mode returns to, if null, the part will return to Reset_Handler 379 * @note When returning from backup mode, depending on the RAM retention settings the processor 380 * could have no state information. It will not have a valid stack pointer. 381 * This function also uses MXC_PWRSEQ->gp0 and gp1. 382 */ 383 void MXC_LP_EnterBackupMode(void *func(void)); 384 385 /** 386 * @brief Places the device into Shutdown mode. CPU state is not maintained in this mode, so this function never returns. 387 * Instead, the device will restart once an RTC, USB wakeup, or external interrupt occur. 388 */ 389 void MXC_LP_EnterShutDownMode(void); 390 391 /*------------------------------------------------------------------------------------------------------------------------------------------------------*/ 392 393 /** 394 * @brief Set ovr bits to set the voltage the micro will run at. 395 * 396 * @param[in] ovr The ovr options are only 0.9V, 1.0V, and 1.1V use enum mxc_lp_ovr_t 397 */ 398 void MXC_LP_SetOVR(mxc_lp_ovr_t ovr); 399 400 /** 401 * @brief Turn bandgap on 402 */ 403 void MXC_LP_BandgapOn(void); 404 405 /** 406 * @brief Turn bandgap off 407 */ 408 void MXC_LP_BandgapOff(void); 409 410 /** 411 * @brief Is the bandgap on or off 412 * 413 * @return 1 = bandgap on , 0 = bandgap off 414 */ 415 int MXC_LP_BandgapIsOn(void); 416 417 /** 418 * @brief Is Fast wake up is Enabled 419 * 420 * @return 1 = enabled , 0 = disabled 421 */ 422 int MXC_LP_FastWakeupIsEnabled(void); 423 424 /** 425 * @brief Enables the USB to wake up the device from any low power mode. 426 */ 427 void MXC_LP_EnableUSBWakeup(void); 428 429 /** 430 * @brief Disables the USB from waking up the device. 431 */ 432 void MXC_LP_DisableUSBWakeup(void); 433 434 /** 435 * @brief Configure which clocks are powered down at deep sleep and which are not affected. 436 * 437 * @note Need to configure all clocks at once any clock not passed in the mask will be unaffected by Deepsleep. This will 438 * always overwrite the previous settings of ALL clocks. 439 * 440 * @param[in] mask The mask of the clocks to power down when part goes into deepsleep 441 * 442 * @return #E_NO_ERROR or error based on \ref MXC_Error_Codes 443 */ 444 int MXC_LP_ConfigDeepSleepClocks(uint32_t mask); 445 446 /** 447 * @brief Disable Icache 0 in light sleep 448 */ 449 void MXC_LP_ICache0LightSleepDisable(void); 450 451 /** 452 * @brief Disable Icache 1 in light sleep 453 */ 454 void MXC_LP_ICache1LightSleepDisable(void); 455 456 /** 457 * @brief Disable Icache XIP in light sleep 458 */ 459 void MXC_LP_ICacheXIPLightSleepDisable(void); 460 461 /** 462 * @brief Enable System Cache in light sleep 463 */ 464 void MXC_LP_SRCCLightSleepEnable(void); 465 466 /** 467 * @brief Enable Crypto in light sleep 468 */ 469 void MXC_LP_CryptoLightSleepEnable(void); 470 471 /** 472 * @brief Enable USB in light sleep 473 */ 474 void MXC_LP_USBFIFOLightSleepEnable(void); 475 476 /** 477 * @brief Enable ROM 0 in light sleep 478 */ 479 void MXC_LP_ROM0LightSleepEnable(void); 480 481 /** 482 * @brief Enable ROM 0 in light sleep 483 */ 484 void MXC_LP_ROM1LightSleepEnable(void); 485 486 /** 487 * @brief Disable System Ram 0 in light sleep 488 */ 489 void MXC_LP_SysRam0LightSleepDisable(void); 490 491 /** 492 * @brief Disable System Ram 1 in light sleep 493 */ 494 void MXC_LP_SysRam1LightSleepDisable(void); 495 496 /** 497 * @brief Disable System Ram 2 in light sleep 498 */ 499 void MXC_LP_SysRam2LightSleepDisable(void); 500 501 /** 502 * @brief Disable System Ram 3 in light sleep 503 */ 504 void MXC_LP_SysRam3LightSleepDisable(void); 505 506 /** 507 * @brief Disable System Ram 4 in light sleep 508 */ 509 void MXC_LP_SysRam4LightSleepDisable(void); 510 511 /** 512 * @brief Disable System Ram 5 in light sleep 513 */ 514 void MXC_LP_SysRam5LightSleepDisable(void); 515 516 /** 517 * @brief Disable System Cache in light sleep 518 */ 519 void MXC_LP_SRCCLightSleepDisable(void); 520 521 /** 522 * @brief Disable Crypto in light sleep 523 */ 524 void MXC_LP_CryptoLightSleepDisable(void); 525 526 /** 527 * @brief Disable USB in light sleep 528 */ 529 void MXC_LP_USBFIFOLightSleepDisable(void); 530 531 /** 532 * @brief Disable ROM 0 in light sleep 533 */ 534 void MXC_LP_ROM0LightSleepDisable(void); 535 536 /** 537 * @brief Disable ROM 1 in light sleep 538 */ 539 void MXC_LP_ROM1LightSleepDisable(void); 540 541 /** 542 * @brief Shutdown SRCC 543 */ 544 void MXC_LP_SRCCShutdown(void); 545 546 /** 547 * @brief PowerUp SRCC 548 */ 549 void MXC_LP_SRCCPowerUp(void); 550 551 /** 552 * @brief Enable Icache XIP in light sleep 553 */ 554 void MXC_LP_ICacheXIPLightSleepEnable(void); 555 556 /** 557 * @brief Enable Icache 0 in light sleep 558 */ 559 void MXC_LP_ICache0LightSleepEnable(void); 560 561 /** 562 * @brief Enable Icache 0 in light sleep 563 */ 564 void MXC_LP_ICache1LightSleepEnable(void); 565 566 #ifdef __cplusplus 567 } 568 #endif 569 /**@} end of group pwrseq */ 570 571 #endif // LIBRARIES_PERIPHDRIVERS_INCLUDE_MAX32665_LP_H_ 572