The official Mbed 2 C/C++ SDK provides the software platform and libraries to build your applications.
Dependents: hello SerialTestv11 SerialTestv12 Sierpinski ... more
mbed 2
This is the mbed 2 library. If you'd like to learn about Mbed OS please see the mbed-os docs.
TARGET_SDT32620B/TOOLCHAIN_IAR/lp.h@172:65be27845400, 2019-02-20 (annotated)
- Committer:
- AnnaBridge
- Date:
- Wed Feb 20 20:53:29 2019 +0000
- Revision:
- 172:65be27845400
- Parent:
- 171:3a7713b1edbc
mbed library release version 165
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
AnnaBridge | 167:84c0a372a020 | 1 | /******************************************************************************* |
AnnaBridge | 167:84c0a372a020 | 2 | * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. |
AnnaBridge | 167:84c0a372a020 | 3 | * |
AnnaBridge | 167:84c0a372a020 | 4 | * Permission is hereby granted, free of charge, to any person obtaining a |
AnnaBridge | 167:84c0a372a020 | 5 | * copy of this software and associated documentation files (the "Software"), |
AnnaBridge | 167:84c0a372a020 | 6 | * to deal in the Software without restriction, including without limitation |
AnnaBridge | 167:84c0a372a020 | 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
AnnaBridge | 167:84c0a372a020 | 8 | * and/or sell copies of the Software, and to permit persons to whom the |
AnnaBridge | 167:84c0a372a020 | 9 | * Software is furnished to do so, subject to the following conditions: |
AnnaBridge | 167:84c0a372a020 | 10 | * |
AnnaBridge | 167:84c0a372a020 | 11 | * The above copyright notice and this permission notice shall be included |
AnnaBridge | 167:84c0a372a020 | 12 | * in all copies or substantial portions of the Software. |
AnnaBridge | 167:84c0a372a020 | 13 | * |
AnnaBridge | 167:84c0a372a020 | 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
AnnaBridge | 167:84c0a372a020 | 15 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
AnnaBridge | 167:84c0a372a020 | 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
AnnaBridge | 167:84c0a372a020 | 17 | * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES |
AnnaBridge | 167:84c0a372a020 | 18 | * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
AnnaBridge | 167:84c0a372a020 | 19 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
AnnaBridge | 167:84c0a372a020 | 20 | * OTHER DEALINGS IN THE SOFTWARE. |
AnnaBridge | 167:84c0a372a020 | 21 | * |
AnnaBridge | 167:84c0a372a020 | 22 | * Except as contained in this notice, the name of Maxim Integrated |
AnnaBridge | 167:84c0a372a020 | 23 | * Products, Inc. shall not be used except as stated in the Maxim Integrated |
AnnaBridge | 167:84c0a372a020 | 24 | * Products, Inc. Branding Policy. |
AnnaBridge | 167:84c0a372a020 | 25 | * |
AnnaBridge | 167:84c0a372a020 | 26 | * The mere transfer of this software does not imply any licenses |
AnnaBridge | 167:84c0a372a020 | 27 | * of trade secrets, proprietary technology, copyrights, patents, |
AnnaBridge | 167:84c0a372a020 | 28 | * trademarks, maskwork rights, or any other form of intellectual |
AnnaBridge | 167:84c0a372a020 | 29 | * property whatsoever. Maxim Integrated Products, Inc. retains all |
AnnaBridge | 167:84c0a372a020 | 30 | * ownership rights. |
AnnaBridge | 167:84c0a372a020 | 31 | * |
AnnaBridge | 167:84c0a372a020 | 32 | * $Date: 2016-03-21 09:04:59 -0500 (Mon, 21 Mar 2016) $ |
AnnaBridge | 167:84c0a372a020 | 33 | * $Revision: 22006 $ |
AnnaBridge | 167:84c0a372a020 | 34 | * |
AnnaBridge | 167:84c0a372a020 | 35 | ******************************************************************************/ |
AnnaBridge | 167:84c0a372a020 | 36 | |
AnnaBridge | 167:84c0a372a020 | 37 | /** |
AnnaBridge | 167:84c0a372a020 | 38 | * @file lp.h |
AnnaBridge | 167:84c0a372a020 | 39 | * @brief This is the high level API for the Lower Power |
AnnaBridge | 167:84c0a372a020 | 40 | */ |
AnnaBridge | 167:84c0a372a020 | 41 | |
AnnaBridge | 167:84c0a372a020 | 42 | #ifndef _LP_H_ |
AnnaBridge | 167:84c0a372a020 | 43 | #define _LP_H_ |
AnnaBridge | 167:84c0a372a020 | 44 | |
AnnaBridge | 167:84c0a372a020 | 45 | #include "gpio.h" |
AnnaBridge | 167:84c0a372a020 | 46 | #include "pwrman_regs.h" |
AnnaBridge | 167:84c0a372a020 | 47 | #include "pwrseq_regs.h" |
AnnaBridge | 167:84c0a372a020 | 48 | |
AnnaBridge | 167:84c0a372a020 | 49 | #ifdef __cplusplus |
AnnaBridge | 167:84c0a372a020 | 50 | extern "C" { |
AnnaBridge | 167:84c0a372a020 | 51 | #endif |
AnnaBridge | 167:84c0a372a020 | 52 | |
AnnaBridge | 167:84c0a372a020 | 53 | /***** Definitions *****/ |
AnnaBridge | 167:84c0a372a020 | 54 | /** |
AnnaBridge | 167:84c0a372a020 | 55 | * @brief Enumerations for pull-up and pull-downs |
AnnaBridge | 167:84c0a372a020 | 56 | * |
AnnaBridge | 167:84c0a372a020 | 57 | */ |
AnnaBridge | 167:84c0a372a020 | 58 | typedef enum { |
AnnaBridge | 167:84c0a372a020 | 59 | LP_WEAK_PULL_DOWN = -1, |
AnnaBridge | 167:84c0a372a020 | 60 | LP_NO_PULL = 0, |
AnnaBridge | 167:84c0a372a020 | 61 | LP_WEAK_PULL_UP = 1 |
AnnaBridge | 167:84c0a372a020 | 62 | } |
AnnaBridge | 167:84c0a372a020 | 63 | lp_pu_pd_select_t; |
AnnaBridge | 167:84c0a372a020 | 64 | |
AnnaBridge | 167:84c0a372a020 | 65 | /***** Function Prototypes *****/ |
AnnaBridge | 167:84c0a372a020 | 66 | |
AnnaBridge | 167:84c0a372a020 | 67 | /** |
AnnaBridge | 167:84c0a372a020 | 68 | * @brief Gets the first boot flag |
AnnaBridge | 167:84c0a372a020 | 69 | * |
AnnaBridge | 167:84c0a372a020 | 70 | * @returns 0 if FIRST_BOOT was not set, or 1 if FIRST_BOOT was set |
AnnaBridge | 167:84c0a372a020 | 71 | */ |
AnnaBridge | 167:84c0a372a020 | 72 | __STATIC_INLINE unsigned int LP_IsFirstBoot() |
AnnaBridge | 167:84c0a372a020 | 73 | { |
AnnaBridge | 167:84c0a372a020 | 74 | return ((MXC_PWRSEQ->reg0 & MXC_F_PWRSEQ_REG0_PWR_FIRST_BOOT) >> MXC_F_PWRSEQ_REG0_PWR_FIRST_BOOT_POS); |
AnnaBridge | 167:84c0a372a020 | 75 | } |
AnnaBridge | 167:84c0a372a020 | 76 | |
AnnaBridge | 167:84c0a372a020 | 77 | /** |
AnnaBridge | 167:84c0a372a020 | 78 | * @brief Clears the first boot flag |
AnnaBridge | 167:84c0a372a020 | 79 | * |
AnnaBridge | 167:84c0a372a020 | 80 | */ |
AnnaBridge | 167:84c0a372a020 | 81 | __STATIC_INLINE void LP_ClearFirstBoot() |
AnnaBridge | 167:84c0a372a020 | 82 | { |
AnnaBridge | 167:84c0a372a020 | 83 | MXC_PWRSEQ->reg0 &= ~MXC_F_PWRSEQ_REG0_PWR_FIRST_BOOT; |
AnnaBridge | 167:84c0a372a020 | 84 | } |
AnnaBridge | 167:84c0a372a020 | 85 | |
AnnaBridge | 167:84c0a372a020 | 86 | /** |
AnnaBridge | 167:84c0a372a020 | 87 | * @brief Determines of program woke up from LP0 |
AnnaBridge | 167:84c0a372a020 | 88 | * |
AnnaBridge | 167:84c0a372a020 | 89 | * @returns 0 if not woken up from LP0, or 1 if woken from LP0 |
AnnaBridge | 167:84c0a372a020 | 90 | */ |
AnnaBridge | 167:84c0a372a020 | 91 | __STATIC_INLINE unsigned int LP_IsLP0WakeUp() |
AnnaBridge | 167:84c0a372a020 | 92 | { |
AnnaBridge | 167:84c0a372a020 | 93 | //POR should be set and first boot clear |
AnnaBridge | 167:84c0a372a020 | 94 | if((MXC_PWRMAN->pwr_rst_ctrl & MXC_F_PWRMAN_PWR_RST_CTRL_POR) && |
AnnaBridge | 167:84c0a372a020 | 95 | ((MXC_PWRSEQ->reg0 & MXC_F_PWRSEQ_REG0_PWR_FIRST_BOOT) == 0)) |
AnnaBridge | 167:84c0a372a020 | 96 | return 1; |
AnnaBridge | 167:84c0a372a020 | 97 | else |
AnnaBridge | 167:84c0a372a020 | 98 | return 0; |
AnnaBridge | 167:84c0a372a020 | 99 | |
AnnaBridge | 167:84c0a372a020 | 100 | } |
AnnaBridge | 167:84c0a372a020 | 101 | |
AnnaBridge | 167:84c0a372a020 | 102 | __STATIC_INLINE unsigned int LP_GetWakeUpFlags(void) |
AnnaBridge | 167:84c0a372a020 | 103 | { |
AnnaBridge | 167:84c0a372a020 | 104 | return MXC_PWRSEQ->flags; |
AnnaBridge | 167:84c0a372a020 | 105 | } |
AnnaBridge | 167:84c0a372a020 | 106 | /** |
AnnaBridge | 167:84c0a372a020 | 107 | * @brief Clear ALL wake-up configuration on all pins. Disables wake-up entirely. |
AnnaBridge | 167:84c0a372a020 | 108 | */ |
AnnaBridge | 167:84c0a372a020 | 109 | void LP_ClearWakeUpConfig(void); |
AnnaBridge | 167:84c0a372a020 | 110 | |
AnnaBridge | 167:84c0a372a020 | 111 | /** |
AnnaBridge | 167:84c0a372a020 | 112 | * @brief Read wake-up flags, clear flags, and return to caller. |
AnnaBridge | 167:84c0a372a020 | 113 | * @returns Wake-up flags from Power Sequencer |
AnnaBridge | 167:84c0a372a020 | 114 | */ |
AnnaBridge | 167:84c0a372a020 | 115 | unsigned int LP_ClearWakeUpFlags(void); |
AnnaBridge | 167:84c0a372a020 | 116 | |
AnnaBridge | 167:84c0a372a020 | 117 | /** |
AnnaBridge | 167:84c0a372a020 | 118 | * @brief This function configures one GPIO pin to wake the processor from LP0 or LP1. |
AnnaBridge | 167:84c0a372a020 | 119 | * It is not used for LP2 wake-up, as normal GPIO interrupt processing is active in that mode. |
AnnaBridge | 167:84c0a372a020 | 120 | * @param gpio GPIO pointer describing the port and pin for selected wake-up source |
AnnaBridge | 167:84c0a372a020 | 121 | * @param act_high If non-zero, the signal is configured for active high wake-up. Otherwise, active low. |
AnnaBridge | 167:84c0a372a020 | 122 | * @param wk_pu_pd Selection for the 1 Meg ohm pull-up or pull-down on this pin, see #lp_pu_pd_select_t |
AnnaBridge | 167:84c0a372a020 | 123 | * @returns #E_NO_ERROR on success, error if unsuccessful. |
AnnaBridge | 167:84c0a372a020 | 124 | */ |
AnnaBridge | 167:84c0a372a020 | 125 | int LP_ConfigGPIOWakeUpDetect(const gpio_cfg_t *gpio, unsigned int act_high, lp_pu_pd_select_t wk_pu_pd); |
AnnaBridge | 167:84c0a372a020 | 126 | |
AnnaBridge | 167:84c0a372a020 | 127 | /** |
AnnaBridge | 167:84c0a372a020 | 128 | * @brief Clear the wake-up configuration on one specific GPIO pin |
AnnaBridge | 167:84c0a372a020 | 129 | * @param gpio GPIO pointer describing the port and pin for selected wake-up source |
AnnaBridge | 167:84c0a372a020 | 130 | * @returns #E_NO_ERROR on success, error if unsuccessful. |
AnnaBridge | 167:84c0a372a020 | 131 | */ |
AnnaBridge | 167:84c0a372a020 | 132 | int LP_ClearGPIOWakeUpDetect(const gpio_cfg_t *gpio); |
AnnaBridge | 167:84c0a372a020 | 133 | |
AnnaBridge | 167:84c0a372a020 | 134 | /** |
AnnaBridge | 167:84c0a372a020 | 135 | * @brief Check if a specific gpio triggered the wake up |
AnnaBridge | 167:84c0a372a020 | 136 | * @param gpio GPIO pointer describing the port and pin(s) |
AnnaBridge | 167:84c0a372a020 | 137 | * @returns 0 = gpio passed in did not trigger a wake up |
AnnaBridge | 167:84c0a372a020 | 138 | * nonzero = at least one of the gpio passed in triggered a wake up |
AnnaBridge | 167:84c0a372a020 | 139 | * the bit set represents which pin is the wake up source |
AnnaBridge | 167:84c0a372a020 | 140 | */ |
AnnaBridge | 167:84c0a372a020 | 141 | int LP_IsGPIOWakeUpSource(const gpio_cfg_t *gpio); |
AnnaBridge | 167:84c0a372a020 | 142 | |
AnnaBridge | 167:84c0a372a020 | 143 | /** |
AnnaBridge | 167:84c0a372a020 | 144 | * @brief Wake on USB plug or unplug |
AnnaBridge | 167:84c0a372a020 | 145 | * @param plug_en set to 1 to enable wake-up when USB VBUS is detected |
AnnaBridge | 167:84c0a372a020 | 146 | * @param unplug_en set to 1 to enable wake-up when USB VBUS disappears |
AnnaBridge | 167:84c0a372a020 | 147 | * @returns #E_NO_ERROR on success, error if unsuccessful. |
AnnaBridge | 167:84c0a372a020 | 148 | */ |
AnnaBridge | 167:84c0a372a020 | 149 | int LP_ConfigUSBWakeUp(unsigned int plug_en, unsigned int unplug_en); |
AnnaBridge | 167:84c0a372a020 | 150 | |
AnnaBridge | 167:84c0a372a020 | 151 | /** |
AnnaBridge | 167:84c0a372a020 | 152 | * @brief Wake on any enabled event signal from RTC |
AnnaBridge | 167:84c0a372a020 | 153 | * @param comp0_en set to 1 to enable wake-up when RTC Comparison 0 is set |
AnnaBridge | 167:84c0a372a020 | 154 | * @param comp1_en set to 1 to enable wake-up when RTC Comparison 1 is set |
AnnaBridge | 167:84c0a372a020 | 155 | * @param prescale_cmp_en set to 1 to enable wake-up when RTC Prescaler Compare is set |
AnnaBridge | 167:84c0a372a020 | 156 | * @param rollover_en set to 1 to enable wake-up when RTC Roll-over is set |
AnnaBridge | 167:84c0a372a020 | 157 | * @returns #E_NO_ERROR on success, error if unsuccessful. |
AnnaBridge | 167:84c0a372a020 | 158 | */ |
AnnaBridge | 167:84c0a372a020 | 159 | int LP_ConfigRTCWakeUp(unsigned int comp0_en, unsigned int comp1_en, unsigned int prescale_cmp_en, unsigned int rollover_en); |
AnnaBridge | 167:84c0a372a020 | 160 | |
AnnaBridge | 167:84c0a372a020 | 161 | /** |
AnnaBridge | 167:84c0a372a020 | 162 | * @brief Enter LP2 power-saving mode |
AnnaBridge | 167:84c0a372a020 | 163 | * @returns #E_NO_ERROR on success, error if unsuccessful. |
AnnaBridge | 167:84c0a372a020 | 164 | */ |
AnnaBridge | 167:84c0a372a020 | 165 | int LP_EnterLP2(void); |
AnnaBridge | 167:84c0a372a020 | 166 | |
AnnaBridge | 167:84c0a372a020 | 167 | /** |
AnnaBridge | 167:84c0a372a020 | 168 | * @brief Enter LP1 mode, which saves CPU state and SRAM. Execution resumes after this call. |
AnnaBridge | 167:84c0a372a020 | 169 | * @note Interrupts should be globally disabled before calling this function. |
AnnaBridge | 167:84c0a372a020 | 170 | * @returns #E_NO_ERROR on success, error if unsuccessful. |
AnnaBridge | 167:84c0a372a020 | 171 | */ |
AnnaBridge | 167:84c0a372a020 | 172 | int LP_EnterLP1(void); |
AnnaBridge | 167:84c0a372a020 | 173 | |
AnnaBridge | 167:84c0a372a020 | 174 | /** |
AnnaBridge | 167:84c0a372a020 | 175 | * @brief Enter the lowest-possible power mode, known as LP0. SRAM contents are lost. |
AnnaBridge | 167:84c0a372a020 | 176 | * Waking up from LP0 is like a system reset. This function does not return. |
AnnaBridge | 167:84c0a372a020 | 177 | * @note Interrupts are globally disabled upon entering this function. |
AnnaBridge | 167:84c0a372a020 | 178 | */ |
AnnaBridge | 167:84c0a372a020 | 179 | void LP_EnterLP0(void); |
AnnaBridge | 167:84c0a372a020 | 180 | |
AnnaBridge | 167:84c0a372a020 | 181 | #ifdef __cplusplus |
AnnaBridge | 167:84c0a372a020 | 182 | } |
AnnaBridge | 167:84c0a372a020 | 183 | #endif |
AnnaBridge | 167:84c0a372a020 | 184 | |
AnnaBridge | 167:84c0a372a020 | 185 | #endif /* _LP_H_ */ |