fsl_common.h
/*
* Copyright (c) 2015, Freescale Semiconductor, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* o Redistributions of source code must retain the above copyright notice, this list
* of conditions and the following disclaimer.
*
* o Redistributions in binary form must reproduce the above copyright notice, this
* list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
*
* o Neither the name of Freescale Semiconductor, Inc. nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _FSL_COMMON_H_
#define _FSL_COMMON_H_
#include <assert.h>
#include <stdbool.h>
#include <stdint.h>
#include <string.h>
#if !defined(BOOTLOADER_HOST)
#include "fsl_device_registers.h"
#endif // BOOTLOADER_HOST
/*******************************************************************************
* Definitions
******************************************************************************/
#define MAKE_STATUS(group, code) ((((group)*100) + (code)))
#define MAKE_VERSION(major, minor, bugfix) (((major) << 16) | ((minor) << 8) | (bugfix))
/* Debug console type definition. */
#define DEBUG_CONSOLE_DEVICE_TYPE_NONE 0U
#define DEBUG_CONSOLE_DEVICE_TYPE_UART 1U
#define DEBUG_CONSOLE_DEVICE_TYPE_LPUART 2U
#define DEBUG_CONSOLE_DEVICE_TYPE_LPSCI 3U
#define DEBUG_CONSOLE_DEVICE_TYPE_USBCDC 4U
enum _status_groups
{
kStatusGroup_Generic = 0,
kStatusGroup_FLASH = 1,
kStatusGroup_LPSPI = 4,
kStatusGroup_FLEXIO_SPI = 5,
kStatusGroup_DSPI = 6,
kStatusGroup_FLEXIO_UART = 7,
kStatusGroup_FLEXIO_I2C = 8,
kStatusGroup_LPI2C = 9,
kStatusGroup_UART = 10,
kStatusGroup_I2C = 11,
kStatusGroup_LPSCI = 12,
kStatusGroup_LPUART = 13,
kStatusGroup_SPI = 14,
kStatusGroup_XRDC = 15,
kStatusGroup_SEMA42 = 16,
kStatusGroup_SDHC = 17,
kStatusGroup_SDMMC = 18,
kStatusGroup_SAI = 19,
kStatusGroup_MCG = 20,
kStatusGroup_SCG = 21,
kStatusGroup_SDSPI = 22,
kStatusGroup_FLEXIO_I2S = 23,
kStatusGroup_SDRAMC = 35,
kStatusGroup_POWER = 39,
kStatusGroup_ENET = 40,
kStatusGroup_PHY = 41,
kStatusGroup_TRGMUX = 42,
kStatusGroup_SMARTCARD = 43,
kStatusGroup_LMEM = 44,
kStatusGroup_QSPI = 45,
kStatusGroup_DMA = 50,
kStatusGroup_EDMA = 51,
kStatusGroup_DMAMGR = 52,
kStatusGroup_FLEXCAN = 53,
kStatusGroup_LTC = 54,
kStatusGroup_FLEXIO_CAMERA = 55,
kStatusGroup_NOTIFIER = 98,
kStatusGroup_DebugConsole = 99,
kStatusGroup_ApplicationRangeStart = 100,
};
enum _generic_status
{
kStatus_Success = MAKE_STATUS(kStatusGroup_Generic, 0),
kStatus_Fail = MAKE_STATUS(kStatusGroup_Generic, 1),
kStatus_ReadOnly = MAKE_STATUS(kStatusGroup_Generic, 2),
kStatus_OutOfRange = MAKE_STATUS(kStatusGroup_Generic, 3),
kStatus_InvalidArgument = MAKE_STATUS(kStatusGroup_Generic, 4),
kStatus_Timeout = MAKE_STATUS(kStatusGroup_Generic, 5),
kStatus_NoTransferInProgress = MAKE_STATUS(kStatusGroup_Generic, 6),
};
typedef int32_t status_t;
#if !defined(BOOTLOADER_HOST)
#include "fsl_clock.h"
#endif // BOOTLOADER_HOST
/* @{ */
#if !defined(MIN)
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#endif
#if !defined(MAX)
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#endif
/* @} */
#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
/* @{ */
#define USEC_TO_COUNT(us, clockFreqInHz) (uint64_t)((uint64_t)us * clockFreqInHz / 1000000U)
#define COUNT_TO_USEC(count, clockFreqInHz) (uint64_t)((uint64_t)count * 1000000U / clockFreqInHz)
#define MSEC_TO_COUNT(ms, clockFreqInHz) (uint64_t)((uint64_t)ms * clockFreqInHz / 1000U)
#define COUNT_TO_MSEC(count, clockFreqInHz) (uint64_t)((uint64_t)count * 1000U / clockFreqInHz)
/* @} */
/*******************************************************************************
* API
******************************************************************************/
#if !defined(BOOTLOADER_HOST)
#if defined(__cplusplus)
extern "C" {
#endif
static inline void EnableIRQ(IRQn_Type interrupt)
{
#if defined(FSL_FEATURE_SOC_INTMUX_COUNT) && (FSL_FEATURE_SOC_INTMUX_COUNT > 0)
if (interrupt < FSL_FEATURE_INTMUX_IRQ_START_INDEX)
#endif
{
NVIC_EnableIRQ(interrupt);
}
}
static inline void DisableIRQ(IRQn_Type interrupt)
{
#if defined(FSL_FEATURE_SOC_INTMUX_COUNT) && (FSL_FEATURE_SOC_INTMUX_COUNT > 0)
if (interrupt < FSL_FEATURE_INTMUX_IRQ_START_INDEX)
#endif
{
NVIC_DisableIRQ(interrupt);
}
}
static inline uint32_t DisableGlobalIRQ(void)
{
uint32_t regPrimask = __get_PRIMASK();
__disable_irq();
return regPrimask;
}
static inline void EnableGlobalIRQ(uint32_t primask)
{
__set_PRIMASK(primask);
}
void InstallIRQHandler(IRQn_Type irq, uint32_t irqHandler);
#if defined(__cplusplus)
}
#endif
#endif // BOOTLOADER_HOST
#endif /* _FSL_COMMON_H_ */
kStatusGroup_DSPI
Definition: fsl_common.h:71
kStatusGroup_SMARTCARD
Definition: fsl_common.h:94
kStatusGroup_ApplicationRangeStart
Definition: fsl_common.h:105
kStatusGroup_LPUART
Definition: fsl_common.h:78
DisableGlobalIRQ
static uint32_t DisableGlobalIRQ(void)
Disable the global IRQ.
Definition: fsl_common.h:206
kStatusGroup_MCG
Definition: fsl_common.h:85
kStatusGroup_I2C
Definition: fsl_common.h:76
kStatusGroup_XRDC
Definition: fsl_common.h:80
kStatusGroup_SPI
Definition: fsl_common.h:79
kStatusGroup_LTC
Definition: fsl_common.h:101
kStatusGroup_DMA
Definition: fsl_common.h:97
kStatusGroup_FLEXCAN
Definition: fsl_common.h:100
EnableGlobalIRQ
static void EnableGlobalIRQ(uint32_t primask)
Enaable the global IRQ.
Definition: fsl_common.h:225
kStatusGroup_SCG
Definition: fsl_common.h:86
_generic_status
_generic_status
Generic status return codes.
Definition: fsl_common.h:109
kStatusGroup_SDHC
Definition: fsl_common.h:82
kStatusGroup_LPSCI
Definition: fsl_common.h:77
kStatusGroup_FLEXIO_I2S
Definition: fsl_common.h:88
kStatusGroup_POWER
Definition: fsl_common.h:90
kStatusGroup_NOTIFIER
Definition: fsl_common.h:103
kStatusGroup_LMEM
Definition: fsl_common.h:95
kStatusGroup_FLEXIO_CAMERA
Definition: fsl_common.h:102
kStatusGroup_ENET
Definition: fsl_common.h:91
kStatusGroup_SDRAMC
Definition: fsl_common.h:89
kStatusGroup_PHY
Definition: fsl_common.h:92
kStatusGroup_FLEXIO_UART
Definition: fsl_common.h:72
kStatusGroup_TRGMUX
Definition: fsl_common.h:93
kStatusGroup_FLEXIO_I2C
Definition: fsl_common.h:73
DisableIRQ
static void DisableIRQ(IRQn_Type interrupt)
Disable specific interrupt.
Definition: fsl_common.h:188
kStatusGroup_SDMMC
Definition: fsl_common.h:83
kStatusGroup_SEMA42
Definition: fsl_common.h:81
kStatusGroup_UART
Definition: fsl_common.h:75
InstallIRQHandler
void InstallIRQHandler(IRQn_Type irq, uint32_t irqHandler)
install IRQ handler
Definition: fsl_common.c:56
kStatusGroup_SDSPI
Definition: fsl_common.h:87
kStatusGroup_FLASH
Definition: fsl_common.h:68
kStatusGroup_DMAMGR
Definition: fsl_common.h:99
kStatusGroup_DebugConsole
Definition: fsl_common.h:104
kStatusGroup_QSPI
Definition: fsl_common.h:96
kStatusGroup_SAI
Definition: fsl_common.h:84
kStatusGroup_Generic
Definition: fsl_common.h:67
kStatusGroup_EDMA
Definition: fsl_common.h:98
kStatusGroup_FLEXIO_SPI
Definition: fsl_common.h:70
status_t
int32_t status_t
Type used for all status and error return values.
Definition: fsl_common.h:121
kStatusGroup_LPSPI
Definition: fsl_common.h:69
EnableIRQ
static void EnableIRQ(IRQn_Type interrupt)
Enable specific interrupt.
Definition: fsl_common.h:171
kStatusGroup_LPI2C
Definition: fsl_common.h:74