mbed official / mbed

Dependents:   hello SerialTestv11 SerialTestv12 Sierpinski ... more

Committer:
AnnaBridge
Date:
Fri May 11 16:51:14 2018 +0100
Revision:
167:84c0a372a020
Parent:
129:0ab6a29f35bf
mbed library. Release version 162

Who changed what in which revision?

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