t

Fork of mbed-dev by mbed official

Committer:
<>
Date:
Tue Nov 08 17:45:16 2016 +0000
Revision:
150:02e0a0aed4ec
This updates the lib to the mbed lib v129

Who changed what in which revision?

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