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.

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?

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