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 145:64910690c574 1 /*
AnnaBridge 145:64910690c574 2 * Copyright (c) 2015, Freescale Semiconductor, Inc.
AnnaBridge 145:64910690c574 3 * All rights reserved.
AnnaBridge 145:64910690c574 4 *
AnnaBridge 145:64910690c574 5 * Redistribution and use in source and binary forms, with or without modification,
AnnaBridge 145:64910690c574 6 * are permitted provided that the following conditions are met:
AnnaBridge 145:64910690c574 7 *
AnnaBridge 145:64910690c574 8 * o Redistributions of source code must retain the above copyright notice, this list
AnnaBridge 145:64910690c574 9 * of conditions and the following disclaimer.
AnnaBridge 145:64910690c574 10 *
AnnaBridge 145:64910690c574 11 * o Redistributions in binary form must reproduce the above copyright notice, this
AnnaBridge 145:64910690c574 12 * list of conditions and the following disclaimer in the documentation and/or
AnnaBridge 145:64910690c574 13 * other materials provided with the distribution.
AnnaBridge 145:64910690c574 14 *
AnnaBridge 145:64910690c574 15 * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
AnnaBridge 145:64910690c574 16 * contributors may be used to endorse or promote products derived from this
AnnaBridge 145:64910690c574 17 * software without specific prior written permission.
AnnaBridge 145:64910690c574 18 *
AnnaBridge 145:64910690c574 19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
AnnaBridge 145:64910690c574 20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
AnnaBridge 145:64910690c574 21 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
AnnaBridge 145:64910690c574 22 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
AnnaBridge 145:64910690c574 23 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
AnnaBridge 145:64910690c574 24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
AnnaBridge 145:64910690c574 25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
AnnaBridge 145:64910690c574 26 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
AnnaBridge 145:64910690c574 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
AnnaBridge 145:64910690c574 28 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
AnnaBridge 145:64910690c574 29 */
AnnaBridge 145:64910690c574 30
AnnaBridge 145:64910690c574 31 #ifndef _FSL_COMMON_H_
AnnaBridge 145:64910690c574 32 #define _FSL_COMMON_H_
AnnaBridge 145:64910690c574 33
AnnaBridge 145:64910690c574 34 #include <assert.h>
AnnaBridge 145:64910690c574 35 #include <stdbool.h>
AnnaBridge 145:64910690c574 36 #include <stdint.h>
AnnaBridge 145:64910690c574 37 #include <stddef.h>
AnnaBridge 145:64910690c574 38 #include <string.h>
AnnaBridge 145:64910690c574 39 #include "fsl_device_registers.h"
AnnaBridge 145:64910690c574 40
AnnaBridge 145:64910690c574 41 /*!
AnnaBridge 145:64910690c574 42 * @addtogroup ksdk_common
AnnaBridge 145:64910690c574 43 * @{
AnnaBridge 145:64910690c574 44 */
AnnaBridge 145:64910690c574 45
AnnaBridge 145:64910690c574 46
AnnaBridge 145:64910690c574 47 /*******************************************************************************
AnnaBridge 145:64910690c574 48 * Definitions
AnnaBridge 145:64910690c574 49 ******************************************************************************/
AnnaBridge 145:64910690c574 50
AnnaBridge 145:64910690c574 51 /*! @brief Construct a status code value from a group and code number. */
AnnaBridge 145:64910690c574 52 #define MAKE_STATUS(group, code) ((((group)*100) + (code)))
AnnaBridge 145:64910690c574 53
AnnaBridge 145:64910690c574 54 /*! @brief Construct the version number for drivers. */
AnnaBridge 145:64910690c574 55 #define MAKE_VERSION(major, minor, bugfix) (((major) << 16) | ((minor) << 8) | (bugfix))
AnnaBridge 145:64910690c574 56
AnnaBridge 145:64910690c574 57 /* Debug console type definition. */
AnnaBridge 145:64910690c574 58 #define DEBUG_CONSOLE_DEVICE_TYPE_NONE 0U /*!< No debug console. */
AnnaBridge 145:64910690c574 59 #define DEBUG_CONSOLE_DEVICE_TYPE_UART 1U /*!< Debug console base on UART. */
AnnaBridge 145:64910690c574 60 #define DEBUG_CONSOLE_DEVICE_TYPE_LPUART 2U /*!< Debug console base on LPUART. */
AnnaBridge 145:64910690c574 61 #define DEBUG_CONSOLE_DEVICE_TYPE_LPSCI 3U /*!< Debug console base on LPSCI. */
AnnaBridge 145:64910690c574 62 #define DEBUG_CONSOLE_DEVICE_TYPE_USBCDC 4U /*!< Debug console base on USBCDC. */
AnnaBridge 145:64910690c574 63
AnnaBridge 145:64910690c574 64 /*! @brief Status group numbers. */
AnnaBridge 145:64910690c574 65 enum _status_groups
AnnaBridge 145:64910690c574 66 {
AnnaBridge 145:64910690c574 67 kStatusGroup_Generic = 0, /*!< Group number for generic status codes. */
AnnaBridge 145:64910690c574 68 kStatusGroup_FLASH = 1, /*!< Group number for FLASH status codes. */
AnnaBridge 145:64910690c574 69 kStatusGroup_LPSPI = 4, /*!< Group number for LPSPI status codes. */
AnnaBridge 145:64910690c574 70 kStatusGroup_FLEXIO_SPI = 5, /*!< Group number for FLEXIO SPI status codes. */
AnnaBridge 145:64910690c574 71 kStatusGroup_DSPI = 6, /*!< Group number for DSPI status codes. */
AnnaBridge 145:64910690c574 72 kStatusGroup_FLEXIO_UART = 7, /*!< Group number for FLEXIO UART status codes. */
AnnaBridge 145:64910690c574 73 kStatusGroup_FLEXIO_I2C = 8, /*!< Group number for FLEXIO I2C status codes. */
AnnaBridge 145:64910690c574 74 kStatusGroup_LPI2C = 9, /*!< Group number for LPI2C status codes. */
AnnaBridge 145:64910690c574 75 kStatusGroup_UART = 10, /*!< Group number for UART status codes. */
AnnaBridge 145:64910690c574 76 kStatusGroup_I2C = 11, /*!< Group number for UART status codes. */
AnnaBridge 145:64910690c574 77 kStatusGroup_LPSCI = 12, /*!< Group number for LPSCI status codes. */
AnnaBridge 145:64910690c574 78 kStatusGroup_LPUART = 13, /*!< Group number for LPUART status codes. */
AnnaBridge 145:64910690c574 79 kStatusGroup_SPI = 14, /*!< Group number for SPI status code.*/
AnnaBridge 145:64910690c574 80 kStatusGroup_XRDC = 15, /*!< Group number for XRDC status code.*/
AnnaBridge 145:64910690c574 81 kStatusGroup_SEMA42 = 16, /*!< Group number for SEMA42 status code.*/
AnnaBridge 145:64910690c574 82 kStatusGroup_SDHC = 17, /*!< Group number for SDHC status code */
AnnaBridge 145:64910690c574 83 kStatusGroup_SDMMC = 18, /*!< Group number for SDMMC status code */
AnnaBridge 145:64910690c574 84 kStatusGroup_SAI = 19, /*!< Group number for SAI status code */
AnnaBridge 145:64910690c574 85 kStatusGroup_MCG = 20, /*!< Group number for MCG status codes. */
AnnaBridge 145:64910690c574 86 kStatusGroup_SCG = 21, /*!< Group number for SCG status codes. */
AnnaBridge 145:64910690c574 87 kStatusGroup_SDSPI = 22, /*!< Group number for SDSPI status codes. */
AnnaBridge 145:64910690c574 88 kStatusGroup_FLEXIO_I2S = 23, /*!< Group number for FLEXIO I2S status codes */
AnnaBridge 145:64910690c574 89 kStatusGroup_SDRAMC = 35, /*!< Group number for SDRAMC status codes. */
AnnaBridge 145:64910690c574 90 kStatusGroup_POWER = 39, /*!< Group number for POWER status codes. */
AnnaBridge 145:64910690c574 91 kStatusGroup_ENET = 40, /*!< Group number for ENET status codes. */
AnnaBridge 145:64910690c574 92 kStatusGroup_PHY = 41, /*!< Group number for PHY status codes. */
AnnaBridge 145:64910690c574 93 kStatusGroup_TRGMUX = 42, /*!< Group number for TRGMUX status codes. */
AnnaBridge 145:64910690c574 94 kStatusGroup_SMARTCARD = 43, /*!< Group number for SMARTCARD status codes. */
AnnaBridge 145:64910690c574 95 kStatusGroup_LMEM = 44, /*!< Group number for LMEM status codes. */
AnnaBridge 145:64910690c574 96 kStatusGroup_QSPI = 45, /*!< Group number for QSPI status codes. */
AnnaBridge 145:64910690c574 97 kStatusGroup_DMA = 50, /*!< Group number for DMA status codes. */
AnnaBridge 145:64910690c574 98 kStatusGroup_EDMA = 51, /*!< Group number for EDMA status codes. */
AnnaBridge 145:64910690c574 99 kStatusGroup_DMAMGR = 52, /*!< Group number for DMAMGR status codes. */
AnnaBridge 145:64910690c574 100 kStatusGroup_FLEXCAN = 53, /*!< Group number for FlexCAN status codes. */
AnnaBridge 145:64910690c574 101 kStatusGroup_LTC = 54, /*!< Group number for LTC status codes. */
AnnaBridge 145:64910690c574 102 kStatusGroup_FLEXIO_CAMERA = 55, /*!< Group number for FLEXIO CAMERA status codes. */
AnnaBridge 145:64910690c574 103 kStatusGroup_NOTIFIER = 98, /*!< Group number for NOTIFIER status codes. */
AnnaBridge 145:64910690c574 104 kStatusGroup_DebugConsole = 99, /*!< Group number for debug console status codes. */
AnnaBridge 145:64910690c574 105 kStatusGroup_ApplicationRangeStart = 100, /*!< Starting number for application groups. */
AnnaBridge 145:64910690c574 106 };
AnnaBridge 145:64910690c574 107
AnnaBridge 145:64910690c574 108 /*! @brief Generic status return codes. */
AnnaBridge 145:64910690c574 109 enum _generic_status
AnnaBridge 145:64910690c574 110 {
AnnaBridge 145:64910690c574 111 kStatus_Success = MAKE_STATUS(kStatusGroup_Generic, 0),
AnnaBridge 145:64910690c574 112 kStatus_Fail = MAKE_STATUS(kStatusGroup_Generic, 1),
AnnaBridge 145:64910690c574 113 kStatus_ReadOnly = MAKE_STATUS(kStatusGroup_Generic, 2),
AnnaBridge 145:64910690c574 114 kStatus_OutOfRange = MAKE_STATUS(kStatusGroup_Generic, 3),
AnnaBridge 145:64910690c574 115 kStatus_InvalidArgument = MAKE_STATUS(kStatusGroup_Generic, 4),
AnnaBridge 145:64910690c574 116 kStatus_Timeout = MAKE_STATUS(kStatusGroup_Generic, 5),
AnnaBridge 145:64910690c574 117 kStatus_NoTransferInProgress = MAKE_STATUS(kStatusGroup_Generic, 6),
AnnaBridge 145:64910690c574 118 };
AnnaBridge 145:64910690c574 119
AnnaBridge 145:64910690c574 120 /*! @brief Type used for all status and error return values. */
AnnaBridge 145:64910690c574 121 typedef int32_t status_t;
AnnaBridge 145:64910690c574 122
AnnaBridge 145:64910690c574 123 /*
AnnaBridge 145:64910690c574 124 * The fsl_clock.h is included here because it needs MAKE_VERSION/MAKE_STATUS/status_t
AnnaBridge 145:64910690c574 125 * defined in previous of this file.
AnnaBridge 145:64910690c574 126 */
AnnaBridge 145:64910690c574 127 #include "fsl_clock.h"
AnnaBridge 145:64910690c574 128
AnnaBridge 145:64910690c574 129 /*! @name Min/max macros */
AnnaBridge 145:64910690c574 130 /* @{ */
AnnaBridge 145:64910690c574 131 #if !defined(MIN)
AnnaBridge 145:64910690c574 132 #define MIN(a, b) ((a) < (b) ? (a) : (b))
AnnaBridge 145:64910690c574 133 #endif
AnnaBridge 145:64910690c574 134
AnnaBridge 145:64910690c574 135 #if !defined(MAX)
AnnaBridge 145:64910690c574 136 #define MAX(a, b) ((a) > (b) ? (a) : (b))
AnnaBridge 145:64910690c574 137 #endif
AnnaBridge 145:64910690c574 138 /* @} */
AnnaBridge 145:64910690c574 139
AnnaBridge 145:64910690c574 140 /*! @brief Computes the number of elements in an array. */
AnnaBridge 145:64910690c574 141 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
AnnaBridge 145:64910690c574 142
AnnaBridge 145:64910690c574 143 /*! @name UINT16_MAX/UINT32_MAX value */
AnnaBridge 145:64910690c574 144 /* @{ */
AnnaBridge 145:64910690c574 145 #if !defined(UINT16_MAX)
AnnaBridge 145:64910690c574 146 #define UINT16_MAX ((uint16_t)-1)
AnnaBridge 145:64910690c574 147 #endif
AnnaBridge 145:64910690c574 148
AnnaBridge 145:64910690c574 149 #if !defined(UINT32_MAX)
AnnaBridge 145:64910690c574 150 #define UINT32_MAX ((uint32_t)-1)
AnnaBridge 145:64910690c574 151 #endif
AnnaBridge 145:64910690c574 152 /* @} */
AnnaBridge 145:64910690c574 153
AnnaBridge 145:64910690c574 154 /*! @name Timer utilities */
AnnaBridge 145:64910690c574 155 /* @{ */
AnnaBridge 145:64910690c574 156 /*! Macro to convert a microsecond period to raw count value */
AnnaBridge 145:64910690c574 157 #define USEC_TO_COUNT(us, clockFreqInHz) (uint64_t)((uint64_t)us * clockFreqInHz / 1000000U)
AnnaBridge 145:64910690c574 158 /*! Macro to convert a raw count value to microsecond */
AnnaBridge 145:64910690c574 159 #define COUNT_TO_USEC(count, clockFreqInHz) (uint64_t)((uint64_t)count * 1000000U / clockFreqInHz)
AnnaBridge 145:64910690c574 160
AnnaBridge 145:64910690c574 161 /*! Macro to convert a millisecond period to raw count value */
AnnaBridge 145:64910690c574 162 #define MSEC_TO_COUNT(ms, clockFreqInHz) (uint64_t)((uint64_t)ms * clockFreqInHz / 1000U)
AnnaBridge 145:64910690c574 163 /*! Macro to convert a raw count value to millisecond */
AnnaBridge 145:64910690c574 164 #define COUNT_TO_MSEC(count, clockFreqInHz) (uint64_t)((uint64_t)count * 1000U / clockFreqInHz)
AnnaBridge 145:64910690c574 165 /* @} */
AnnaBridge 145:64910690c574 166
AnnaBridge 145:64910690c574 167 /*******************************************************************************
AnnaBridge 145:64910690c574 168 * API
AnnaBridge 145:64910690c574 169 ******************************************************************************/
AnnaBridge 145:64910690c574 170
AnnaBridge 145:64910690c574 171 #if defined(__cplusplus)
AnnaBridge 145:64910690c574 172 extern "C" {
AnnaBridge 145:64910690c574 173 #endif
AnnaBridge 145:64910690c574 174
AnnaBridge 145:64910690c574 175 /*!
AnnaBridge 145:64910690c574 176 * @brief Enable specific interrupt.
AnnaBridge 145:64910690c574 177 *
AnnaBridge 145:64910690c574 178 * Enable the interrupt not routed from intmux.
AnnaBridge 145:64910690c574 179 *
AnnaBridge 145:64910690c574 180 * @param interrupt The IRQ number.
AnnaBridge 145:64910690c574 181 */
AnnaBridge 145:64910690c574 182 static inline void EnableIRQ(IRQn_Type interrupt)
AnnaBridge 145:64910690c574 183 {
AnnaBridge 145:64910690c574 184 #if defined(FSL_FEATURE_SOC_INTMUX_COUNT) && (FSL_FEATURE_SOC_INTMUX_COUNT > 0)
AnnaBridge 145:64910690c574 185 if (interrupt < FSL_FEATURE_INTMUX_IRQ_START_INDEX)
AnnaBridge 145:64910690c574 186 #endif
AnnaBridge 145:64910690c574 187 {
AnnaBridge 145:64910690c574 188 NVIC_EnableIRQ(interrupt);
AnnaBridge 145:64910690c574 189 }
AnnaBridge 145:64910690c574 190 }
AnnaBridge 145:64910690c574 191
AnnaBridge 145:64910690c574 192 /*!
AnnaBridge 145:64910690c574 193 * @brief Disable specific interrupt.
AnnaBridge 145:64910690c574 194 *
AnnaBridge 145:64910690c574 195 * Disable the interrupt not routed from intmux.
AnnaBridge 145:64910690c574 196 *
AnnaBridge 145:64910690c574 197 * @param interrupt The IRQ number.
AnnaBridge 145:64910690c574 198 */
AnnaBridge 145:64910690c574 199 static inline void DisableIRQ(IRQn_Type interrupt)
AnnaBridge 145:64910690c574 200 {
AnnaBridge 145:64910690c574 201 #if defined(FSL_FEATURE_SOC_INTMUX_COUNT) && (FSL_FEATURE_SOC_INTMUX_COUNT > 0)
AnnaBridge 145:64910690c574 202 if (interrupt < FSL_FEATURE_INTMUX_IRQ_START_INDEX)
AnnaBridge 145:64910690c574 203 #endif
AnnaBridge 145:64910690c574 204 {
AnnaBridge 145:64910690c574 205 NVIC_DisableIRQ(interrupt);
AnnaBridge 145:64910690c574 206 }
AnnaBridge 145:64910690c574 207 }
AnnaBridge 145:64910690c574 208
AnnaBridge 145:64910690c574 209 /*!
AnnaBridge 145:64910690c574 210 * @brief Disable the global IRQ
AnnaBridge 145:64910690c574 211 *
AnnaBridge 145:64910690c574 212 * Disable the global interrupt and return the current primask register. User is required to provided the primask
AnnaBridge 145:64910690c574 213 * register for the EnableGlobalIRQ().
AnnaBridge 145:64910690c574 214 *
AnnaBridge 145:64910690c574 215 * @return Current primask value.
AnnaBridge 145:64910690c574 216 */
AnnaBridge 145:64910690c574 217 static inline uint32_t DisableGlobalIRQ(void)
AnnaBridge 145:64910690c574 218 {
AnnaBridge 145:64910690c574 219 uint32_t regPrimask = __get_PRIMASK();
AnnaBridge 145:64910690c574 220
AnnaBridge 145:64910690c574 221 __disable_irq();
AnnaBridge 145:64910690c574 222
AnnaBridge 145:64910690c574 223 return regPrimask;
AnnaBridge 145:64910690c574 224 }
AnnaBridge 145:64910690c574 225
AnnaBridge 145:64910690c574 226 /*!
AnnaBridge 145:64910690c574 227 * @brief Enaable the global IRQ
AnnaBridge 145:64910690c574 228 *
AnnaBridge 145:64910690c574 229 * Set the primask register with the provided primask value but not just enable the primask. The idea is for the
AnnaBridge 145:64910690c574 230 * convinience of integration of RTOS. some RTOS get its own management mechanism of primask. User is required to
AnnaBridge 145:64910690c574 231 * use the EnableGlobalIRQ() and DisableGlobalIRQ() in pair.
AnnaBridge 145:64910690c574 232 *
AnnaBridge 145:64910690c574 233 * @param primask value of primask register to be restored. The primask value is supposed to be provided by the
AnnaBridge 145:64910690c574 234 * DisableGlobalIRQ().
AnnaBridge 145:64910690c574 235 */
AnnaBridge 145:64910690c574 236 static inline void EnableGlobalIRQ(uint32_t primask)
AnnaBridge 145:64910690c574 237 {
AnnaBridge 145:64910690c574 238 __set_PRIMASK(primask);
AnnaBridge 145:64910690c574 239 }
AnnaBridge 145:64910690c574 240
AnnaBridge 145:64910690c574 241 /*!
AnnaBridge 145:64910690c574 242 * @brief install IRQ handler
AnnaBridge 145:64910690c574 243 *
AnnaBridge 145:64910690c574 244 * @param irq IRQ number
AnnaBridge 145:64910690c574 245 * @param irqHandler IRQ handler address
AnnaBridge 145:64910690c574 246 */
AnnaBridge 145:64910690c574 247 void InstallIRQHandler(IRQn_Type irq, uint32_t irqHandler);
AnnaBridge 145:64910690c574 248
AnnaBridge 145:64910690c574 249 #if defined(__cplusplus)
AnnaBridge 145:64910690c574 250 }
AnnaBridge 145:64910690c574 251 #endif
AnnaBridge 145:64910690c574 252
AnnaBridge 145:64910690c574 253 /*! @} */
AnnaBridge 145:64910690c574 254
AnnaBridge 145:64910690c574 255 #endif /* _FSL_COMMON_H_ */