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
AnnaBridge 143:86740a56073b 1 /*
AnnaBridge 143:86740a56073b 2 * Copyright (c) 2015, Freescale Semiconductor, Inc.
AnnaBridge 143:86740a56073b 3 * Copyright 2016-2017 NXP
AnnaBridge 143:86740a56073b 4 *
AnnaBridge 143:86740a56073b 5 * Redistribution and use in source and binary forms, with or without modification,
AnnaBridge 143:86740a56073b 6 * are permitted provided that the following conditions are met:
AnnaBridge 143:86740a56073b 7 *
AnnaBridge 143:86740a56073b 8 * o Redistributions of source code must retain the above copyright notice, this list
AnnaBridge 143:86740a56073b 9 * of conditions and the following disclaimer.
AnnaBridge 143:86740a56073b 10 *
AnnaBridge 143:86740a56073b 11 * o Redistributions in binary form must reproduce the above copyright notice, this
AnnaBridge 143:86740a56073b 12 * list of conditions and the following disclaimer in the documentation and/or
AnnaBridge 143:86740a56073b 13 * other materials provided with the distribution.
AnnaBridge 143:86740a56073b 14 *
AnnaBridge 143:86740a56073b 15 * o Neither the name of the copyright holder nor the names of its
AnnaBridge 143:86740a56073b 16 * contributors may be used to endorse or promote products derived from this
AnnaBridge 143:86740a56073b 17 * software without specific prior written permission.
AnnaBridge 143:86740a56073b 18 *
AnnaBridge 143:86740a56073b 19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
AnnaBridge 143:86740a56073b 20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
AnnaBridge 143:86740a56073b 21 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
AnnaBridge 143:86740a56073b 22 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
AnnaBridge 143:86740a56073b 23 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
AnnaBridge 143:86740a56073b 24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
AnnaBridge 143:86740a56073b 25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
AnnaBridge 143:86740a56073b 26 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
AnnaBridge 143:86740a56073b 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
AnnaBridge 143:86740a56073b 28 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
AnnaBridge 143:86740a56073b 29 */
AnnaBridge 143:86740a56073b 30
AnnaBridge 143:86740a56073b 31 #ifndef _FSL_VREF_H_
AnnaBridge 143:86740a56073b 32 #define _FSL_VREF_H_
AnnaBridge 143:86740a56073b 33
AnnaBridge 143:86740a56073b 34 #include "fsl_common.h"
AnnaBridge 143:86740a56073b 35
AnnaBridge 143:86740a56073b 36 /*!
AnnaBridge 143:86740a56073b 37 * @addtogroup vref
AnnaBridge 143:86740a56073b 38 * @{
AnnaBridge 143:86740a56073b 39 */
AnnaBridge 143:86740a56073b 40
AnnaBridge 143:86740a56073b 41
AnnaBridge 143:86740a56073b 42 /******************************************************************************
AnnaBridge 143:86740a56073b 43 * Definitions
AnnaBridge 143:86740a56073b 44 ******************************************************************************/
AnnaBridge 143:86740a56073b 45
AnnaBridge 143:86740a56073b 46 /*! @name Driver version */
AnnaBridge 143:86740a56073b 47 /*@{*/
AnnaBridge 143:86740a56073b 48 #define FSL_VREF_DRIVER_VERSION (MAKE_VERSION(2, 1, 0)) /*!< Version 2.1.0. */
AnnaBridge 143:86740a56073b 49 /*@}*/
AnnaBridge 143:86740a56073b 50
AnnaBridge 143:86740a56073b 51 /* Those macros below defined to support SoC family which have VREFL (0.4V) reference */
AnnaBridge 143:86740a56073b 52 #if defined(FSL_FEATURE_VREF_HAS_LOW_REFERENCE) && FSL_FEATURE_VREF_HAS_LOW_REFERENCE
AnnaBridge 143:86740a56073b 53 #define VREF_SC_MODE_LV VREF_VREFH_SC_MODE_LV
AnnaBridge 143:86740a56073b 54 #define VREF_SC_REGEN VREF_VREFH_SC_REGEN
AnnaBridge 143:86740a56073b 55 #define VREF_SC_VREFEN VREF_VREFH_SC_VREFEN
AnnaBridge 143:86740a56073b 56 #define VREF_SC_ICOMPEN VREF_VREFH_SC_ICOMPEN
AnnaBridge 143:86740a56073b 57 #define VREF_SC_REGEN_MASK VREF_VREFH_SC_REGEN_MASK
AnnaBridge 143:86740a56073b 58 #define VREF_SC_VREFST_MASK VREF_VREFH_SC_VREFST_MASK
AnnaBridge 143:86740a56073b 59 #define VREF_SC_VREFEN_MASK VREF_VREFH_SC_VREFEN_MASK
AnnaBridge 143:86740a56073b 60 #define VREF_SC_MODE_LV_MASK VREF_VREFH_SC_MODE_LV_MASK
AnnaBridge 143:86740a56073b 61 #define VREF_SC_ICOMPEN_MASK VREF_VREFH_SC_ICOMPEN_MASK
AnnaBridge 143:86740a56073b 62 #define TRM VREFH_TRM
AnnaBridge 143:86740a56073b 63 #define VREF_TRM_TRIM VREF_VREFH_TRM_TRIM
AnnaBridge 143:86740a56073b 64 #define VREF_TRM_CHOPEN_MASK VREF_VREFH_TRM_CHOPEN_MASK
AnnaBridge 143:86740a56073b 65 #define VREF_TRM_TRIM_MASK VREF_VREFH_TRM_TRIM_MASK
AnnaBridge 143:86740a56073b 66 #define VREF_TRM_CHOPEN_SHIFT VREF_VREFH_TRM_CHOPEN_SHIFT
AnnaBridge 143:86740a56073b 67 #define VREF_TRM_TRIM_SHIFT VREF_VREFH_TRM_TRIM_SHIFT
AnnaBridge 143:86740a56073b 68 #define VREF_SC_MODE_LV_SHIFT VREF_VREFH_SC_MODE_LV_SHIFT
AnnaBridge 143:86740a56073b 69 #define VREF_SC_REGEN_SHIFT VREF_VREFH_SC_REGEN_SHIFT
AnnaBridge 143:86740a56073b 70 #define VREF_SC_VREFST_SHIFT VREF_VREFH_SC_VREFST_SHIFT
AnnaBridge 143:86740a56073b 71 #define VREF_SC_ICOMPEN_SHIFT VREF_VREFH_SC_ICOMPEN_SHIFT
AnnaBridge 143:86740a56073b 72 #endif /* FSL_FEATURE_VREF_HAS_LOW_REFERENCE */
AnnaBridge 143:86740a56073b 73
AnnaBridge 143:86740a56073b 74 /*!
AnnaBridge 143:86740a56073b 75 * @brief VREF modes.
AnnaBridge 143:86740a56073b 76 */
AnnaBridge 143:86740a56073b 77 typedef enum _vref_buffer_mode
AnnaBridge 143:86740a56073b 78 {
AnnaBridge 143:86740a56073b 79 kVREF_ModeBandgapOnly = 0U, /*!< Bandgap on only, for stabilization and startup */
AnnaBridge 143:86740a56073b 80 #if defined(FSL_FEATURE_VREF_MODE_LV_TYPE) && FSL_FEATURE_VREF_MODE_LV_TYPE
AnnaBridge 143:86740a56073b 81 kVREF_ModeHighPowerBuffer = 1U, /*!< High-power buffer mode enabled */
AnnaBridge 143:86740a56073b 82 kVREF_ModeLowPowerBuffer = 2U /*!< Low-power buffer mode enabled */
AnnaBridge 143:86740a56073b 83 #else
AnnaBridge 143:86740a56073b 84 kVREF_ModeTightRegulationBuffer = 2U /*!< Tight regulation buffer enabled */
AnnaBridge 143:86740a56073b 85 #endif /* FSL_FEATURE_VREF_MODE_LV_TYPE */
AnnaBridge 143:86740a56073b 86 } vref_buffer_mode_t;
AnnaBridge 143:86740a56073b 87
AnnaBridge 143:86740a56073b 88 /*!
AnnaBridge 143:86740a56073b 89 * @brief The description structure for the VREF module.
AnnaBridge 143:86740a56073b 90 */
AnnaBridge 143:86740a56073b 91 typedef struct _vref_config
AnnaBridge 143:86740a56073b 92 {
AnnaBridge 143:86740a56073b 93 vref_buffer_mode_t bufferMode; /*!< Buffer mode selection */
AnnaBridge 143:86740a56073b 94 #if defined(FSL_FEATURE_VREF_HAS_LOW_REFERENCE) && FSL_FEATURE_VREF_HAS_LOW_REFERENCE
AnnaBridge 143:86740a56073b 95 bool enableLowRef; /*!< Set VREFL (0.4 V) reference buffer enable or disable */
AnnaBridge 143:86740a56073b 96 bool enableExternalVoltRef; /*!< Select external voltage reference or not (internal) */
AnnaBridge 143:86740a56073b 97 #endif /* FSL_FEATURE_VREF_HAS_LOW_REFERENCE */
AnnaBridge 143:86740a56073b 98 #if defined(FSL_FEATURE_VREF_HAS_TRM4) && FSL_FEATURE_VREF_HAS_TRM4
AnnaBridge 143:86740a56073b 99 bool enable2V1VoltRef; /*!< Enable Internal Voltage Reference (2.1V) */
AnnaBridge 143:86740a56073b 100 #endif /* FSL_FEATURE_VREF_HAS_TRM4 */
AnnaBridge 143:86740a56073b 101 } vref_config_t;
AnnaBridge 143:86740a56073b 102
AnnaBridge 143:86740a56073b 103 /******************************************************************************
AnnaBridge 143:86740a56073b 104 * API
AnnaBridge 143:86740a56073b 105 ******************************************************************************/
AnnaBridge 143:86740a56073b 106
AnnaBridge 143:86740a56073b 107 #if defined(__cplusplus)
AnnaBridge 143:86740a56073b 108 extern "C" {
AnnaBridge 143:86740a56073b 109 #endif /* __cplusplus */
AnnaBridge 143:86740a56073b 110
AnnaBridge 143:86740a56073b 111 /*!
AnnaBridge 143:86740a56073b 112 * @name VREF functional operation
AnnaBridge 143:86740a56073b 113 * @{
AnnaBridge 143:86740a56073b 114 */
AnnaBridge 143:86740a56073b 115
AnnaBridge 143:86740a56073b 116 /*!
AnnaBridge 143:86740a56073b 117 * @brief Enables the clock gate and configures the VREF module according to the configuration structure.
AnnaBridge 143:86740a56073b 118 *
AnnaBridge 143:86740a56073b 119 * This function must be called before calling all other VREF driver functions,
AnnaBridge 143:86740a56073b 120 * read/write registers, and configurations with user-defined settings.
AnnaBridge 143:86740a56073b 121 * The example below shows how to set up vref_config_t parameters and
AnnaBridge 143:86740a56073b 122 * how to call the VREF_Init function by passing in these parameters.
AnnaBridge 143:86740a56073b 123 * This is an example.
AnnaBridge 143:86740a56073b 124 * @code
AnnaBridge 143:86740a56073b 125 * vref_config_t vrefConfig;
AnnaBridge 143:86740a56073b 126 * vrefConfig.bufferMode = kVREF_ModeHighPowerBuffer;
AnnaBridge 143:86740a56073b 127 * vrefConfig.enableExternalVoltRef = false;
AnnaBridge 143:86740a56073b 128 * vrefConfig.enableLowRef = false;
AnnaBridge 143:86740a56073b 129 * VREF_Init(VREF, &vrefConfig);
AnnaBridge 143:86740a56073b 130 * @endcode
AnnaBridge 143:86740a56073b 131 *
AnnaBridge 143:86740a56073b 132 * @param base VREF peripheral address.
AnnaBridge 143:86740a56073b 133 * @param config Pointer to the configuration structure.
AnnaBridge 143:86740a56073b 134 */
AnnaBridge 143:86740a56073b 135 void VREF_Init(VREF_Type *base, const vref_config_t *config);
AnnaBridge 143:86740a56073b 136
AnnaBridge 143:86740a56073b 137 /*!
AnnaBridge 143:86740a56073b 138 * @brief Stops and disables the clock for the VREF module.
AnnaBridge 143:86740a56073b 139 *
AnnaBridge 143:86740a56073b 140 * This function should be called to shut down the module.
AnnaBridge 143:86740a56073b 141 * This is an example.
AnnaBridge 143:86740a56073b 142 * @code
AnnaBridge 143:86740a56073b 143 * vref_config_t vrefUserConfig;
AnnaBridge 143:86740a56073b 144 * VREF_Init(VREF);
AnnaBridge 143:86740a56073b 145 * VREF_GetDefaultConfig(&vrefUserConfig);
AnnaBridge 143:86740a56073b 146 * ...
AnnaBridge 143:86740a56073b 147 * VREF_Deinit(VREF);
AnnaBridge 143:86740a56073b 148 * @endcode
AnnaBridge 143:86740a56073b 149 *
AnnaBridge 143:86740a56073b 150 * @param base VREF peripheral address.
AnnaBridge 143:86740a56073b 151 */
AnnaBridge 143:86740a56073b 152 void VREF_Deinit(VREF_Type *base);
AnnaBridge 143:86740a56073b 153
AnnaBridge 143:86740a56073b 154 /*!
AnnaBridge 143:86740a56073b 155 * @brief Initializes the VREF configuration structure.
AnnaBridge 143:86740a56073b 156 *
AnnaBridge 143:86740a56073b 157 * This function initializes the VREF configuration structure to default values.
AnnaBridge 143:86740a56073b 158 * This is an example.
AnnaBridge 143:86740a56073b 159 * @code
AnnaBridge 143:86740a56073b 160 * vrefConfig->bufferMode = kVREF_ModeHighPowerBuffer;
AnnaBridge 143:86740a56073b 161 * vrefConfig->enableExternalVoltRef = false;
AnnaBridge 143:86740a56073b 162 * vrefConfig->enableLowRef = false;
AnnaBridge 143:86740a56073b 163 * @endcode
AnnaBridge 143:86740a56073b 164 *
AnnaBridge 143:86740a56073b 165 * @param config Pointer to the initialization structure.
AnnaBridge 143:86740a56073b 166 */
AnnaBridge 143:86740a56073b 167 void VREF_GetDefaultConfig(vref_config_t *config);
AnnaBridge 143:86740a56073b 168
AnnaBridge 143:86740a56073b 169 /*!
AnnaBridge 143:86740a56073b 170 * @brief Sets a TRIM value for the reference voltage.
AnnaBridge 143:86740a56073b 171 *
AnnaBridge 143:86740a56073b 172 * This function sets a TRIM value for the reference voltage.
AnnaBridge 143:86740a56073b 173 * Note that the TRIM value maximum is 0x3F.
AnnaBridge 143:86740a56073b 174 *
AnnaBridge 143:86740a56073b 175 * @param base VREF peripheral address.
AnnaBridge 143:86740a56073b 176 * @param trimValue Value of the trim register to set the output reference voltage (maximum 0x3F (6-bit)).
AnnaBridge 143:86740a56073b 177 */
AnnaBridge 143:86740a56073b 178 void VREF_SetTrimVal(VREF_Type *base, uint8_t trimValue);
AnnaBridge 143:86740a56073b 179
AnnaBridge 143:86740a56073b 180 /*!
AnnaBridge 143:86740a56073b 181 * @brief Reads the value of the TRIM meaning output voltage.
AnnaBridge 143:86740a56073b 182 *
AnnaBridge 143:86740a56073b 183 * This function gets the TRIM value from the TRM register.
AnnaBridge 143:86740a56073b 184 *
AnnaBridge 143:86740a56073b 185 * @param base VREF peripheral address.
AnnaBridge 143:86740a56073b 186 * @return Six-bit value of trim setting.
AnnaBridge 143:86740a56073b 187 */
AnnaBridge 143:86740a56073b 188 static inline uint8_t VREF_GetTrimVal(VREF_Type *base)
AnnaBridge 143:86740a56073b 189 {
AnnaBridge 143:86740a56073b 190 return (base->TRM & VREF_TRM_TRIM_MASK);
AnnaBridge 143:86740a56073b 191 }
AnnaBridge 143:86740a56073b 192
AnnaBridge 143:86740a56073b 193 #if defined(FSL_FEATURE_VREF_HAS_TRM4) && FSL_FEATURE_VREF_HAS_TRM4
AnnaBridge 143:86740a56073b 194 /*!
AnnaBridge 143:86740a56073b 195 * @brief Sets a TRIM value for the reference voltage (2V1).
AnnaBridge 143:86740a56073b 196 *
AnnaBridge 143:86740a56073b 197 * This function sets a TRIM value for the reference voltage (2V1).
AnnaBridge 143:86740a56073b 198 * Note that the TRIM value maximum is 0x3F.
AnnaBridge 143:86740a56073b 199 *
AnnaBridge 143:86740a56073b 200 * @param base VREF peripheral address.
AnnaBridge 143:86740a56073b 201 * @param trimValue Value of the trim register to set the output reference voltage (maximum 0x3F (6-bit)).
AnnaBridge 143:86740a56073b 202 */
AnnaBridge 143:86740a56073b 203 void VREF_SetTrim2V1Val(VREF_Type *base, uint8_t trimValue);
AnnaBridge 143:86740a56073b 204
AnnaBridge 143:86740a56073b 205 /*!
AnnaBridge 143:86740a56073b 206 * @brief Reads the value of the TRIM meaning output voltage (2V1).
AnnaBridge 143:86740a56073b 207 *
AnnaBridge 143:86740a56073b 208 * This function gets the TRIM value from the VREF_TRM4 register.
AnnaBridge 143:86740a56073b 209 *
AnnaBridge 143:86740a56073b 210 * @param base VREF peripheral address.
AnnaBridge 143:86740a56073b 211 * @return Six-bit value of trim setting.
AnnaBridge 143:86740a56073b 212 */
AnnaBridge 143:86740a56073b 213 static inline uint8_t VREF_GetTrim2V1Val(VREF_Type *base)
AnnaBridge 143:86740a56073b 214 {
AnnaBridge 143:86740a56073b 215 return (base->TRM4 & VREF_TRM4_TRIM2V1_MASK);
AnnaBridge 143:86740a56073b 216 }
AnnaBridge 143:86740a56073b 217 #endif /* FSL_FEATURE_VREF_HAS_TRM4 */
AnnaBridge 143:86740a56073b 218
AnnaBridge 143:86740a56073b 219 #if defined(FSL_FEATURE_VREF_HAS_LOW_REFERENCE) && FSL_FEATURE_VREF_HAS_LOW_REFERENCE
AnnaBridge 143:86740a56073b 220
AnnaBridge 143:86740a56073b 221 /*!
AnnaBridge 143:86740a56073b 222 * @brief Sets the TRIM value for the low voltage reference.
AnnaBridge 143:86740a56073b 223 *
AnnaBridge 143:86740a56073b 224 * This function sets the TRIM value for low reference voltage.
AnnaBridge 143:86740a56073b 225 * Note the following.
AnnaBridge 143:86740a56073b 226 * - The TRIM value maximum is 0x05U
AnnaBridge 143:86740a56073b 227 * - The values 111b and 110b are not valid/allowed.
AnnaBridge 143:86740a56073b 228 *
AnnaBridge 143:86740a56073b 229 * @param base VREF peripheral address.
AnnaBridge 143:86740a56073b 230 * @param trimValue Value of the trim register to set output low reference voltage (maximum 0x05U (3-bit)).
AnnaBridge 143:86740a56073b 231 */
AnnaBridge 143:86740a56073b 232 void VREF_SetLowReferenceTrimVal(VREF_Type *base, uint8_t trimValue);
AnnaBridge 143:86740a56073b 233
AnnaBridge 143:86740a56073b 234 /*!
AnnaBridge 143:86740a56073b 235 * @brief Reads the value of the TRIM meaning output voltage.
AnnaBridge 143:86740a56073b 236 *
AnnaBridge 143:86740a56073b 237 * This function gets the TRIM value from the VREFL_TRM register.
AnnaBridge 143:86740a56073b 238 *
AnnaBridge 143:86740a56073b 239 * @param base VREF peripheral address.
AnnaBridge 143:86740a56073b 240 * @return Three-bit value of the trim setting.
AnnaBridge 143:86740a56073b 241 */
AnnaBridge 143:86740a56073b 242 static inline uint8_t VREF_GetLowReferenceTrimVal(VREF_Type *base)
AnnaBridge 143:86740a56073b 243 {
AnnaBridge 143:86740a56073b 244 return (base->VREFL_TRM & VREF_VREFL_TRM_VREFL_TRIM_MASK);
AnnaBridge 143:86740a56073b 245 }
AnnaBridge 143:86740a56073b 246 #endif /* FSL_FEATURE_VREF_HAS_LOW_REFERENCE */
AnnaBridge 143:86740a56073b 247
AnnaBridge 143:86740a56073b 248 /*@}*/
AnnaBridge 143:86740a56073b 249
AnnaBridge 143:86740a56073b 250 #if defined(__cplusplus)
AnnaBridge 143:86740a56073b 251 }
AnnaBridge 143:86740a56073b 252 #endif /* __cplusplus */
AnnaBridge 143:86740a56073b 253
AnnaBridge 143:86740a56073b 254 /*! @}*/
AnnaBridge 143:86740a56073b 255
AnnaBridge 143:86740a56073b 256 #endif /* _FSL_VREF_H_ */