Go to the documentation of this file.
10 #define _FSL_COMMON_H_
18 #if defined(__ICCARM__)
28 #include "RTE_Components.h"
43 #define MAKE_STATUS(group, code) ((((group)*100) + (code)))
46 #define MAKE_VERSION(major, minor, bugfix) (((major) << 16) | ((minor) << 8) | (bugfix))
51 #define FSL_COMMON_DRIVER_VERSION (MAKE_VERSION(2, 2, 4))
55 #define DEBUG_CONSOLE_DEVICE_TYPE_NONE 0U
56 #define DEBUG_CONSOLE_DEVICE_TYPE_UART 1U
57 #define DEBUG_CONSOLE_DEVICE_TYPE_LPUART 2U
58 #define DEBUG_CONSOLE_DEVICE_TYPE_LPSCI 3U
59 #define DEBUG_CONSOLE_DEVICE_TYPE_USBCDC 4U
60 #define DEBUG_CONSOLE_DEVICE_TYPE_FLEXCOMM 5U
61 #define DEBUG_CONSOLE_DEVICE_TYPE_IUART 6U
62 #define DEBUG_CONSOLE_DEVICE_TYPE_VUSART 7U
63 #define DEBUG_CONSOLE_DEVICE_TYPE_MINI_USART 8U
64 #define DEBUG_CONSOLE_DEVICE_TYPE_SWO 9U
194 #ifndef FSL_DRIVER_TRANSFER_DOUBLE_WEAK_IRQ
195 #define FSL_DRIVER_TRANSFER_DOUBLE_WEAK_IRQ 1
201 #define MIN(a, b) (((a) < (b)) ? (a) : (b))
205 #define MAX(a, b) (((a) > (b)) ? (a) : (b))
210 #if !defined(ARRAY_SIZE)
211 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
216 #if !defined(UINT16_MAX)
217 #define UINT16_MAX ((uint16_t)-1)
220 #if !defined(UINT32_MAX)
221 #define UINT32_MAX ((uint32_t)-1)
228 #define USEC_TO_COUNT(us, clockFreqInHz) (uint64_t)(((uint64_t)(us) * (clockFreqInHz)) / 1000000U)
230 #define COUNT_TO_USEC(count, clockFreqInHz) (uint64_t)((uint64_t)(count) * 1000000U / (clockFreqInHz))
233 #define MSEC_TO_COUNT(ms, clockFreqInHz) (uint64_t)((uint64_t)(ms) * (clockFreqInHz) / 1000U)
235 #define COUNT_TO_MSEC(count, clockFreqInHz) (uint64_t)((uint64_t)(count) * 1000U / (clockFreqInHz))
247 #if (defined __CORTEX_M) && ((__CORTEX_M == 4U) || (__CORTEX_M == 7U))
248 #define SDK_ISR_EXIT_BARRIER __DSB()
250 #define SDK_ISR_EXIT_BARRIER
257 #if (defined(__ICCARM__))
262 _Pragma(
"diag_suppress=Pm120")
263 #define SDK_PRAGMA(x) _Pragma(#x)
264 _Pragma(
"diag_error=Pm120")
266 #define SDK_ALIGN(var, alignbytes) SDK_PRAGMA(data_alignment = alignbytes) var
268 #if defined(FSL_FEATURE_L1DCACHE_LINESIZE_BYTE)
269 #define SDK_L1DCACHE_ALIGN(var) SDK_PRAGMA(data_alignment = FSL_FEATURE_L1DCACHE_LINESIZE_BYTE) var
272 #if defined(FSL_FEATURE_L2CACHE_LINESIZE_BYTE)
273 #define SDK_L2CACHE_ALIGN(var) SDK_PRAGMA(data_alignment = FSL_FEATURE_L2CACHE_LINESIZE_BYTE) var
275 #elif defined(__CC_ARM) || defined(__ARMCC_VERSION)
277 #define SDK_ALIGN(var, alignbytes) __attribute__((aligned(alignbytes))) var
279 #if defined(FSL_FEATURE_L1DCACHE_LINESIZE_BYTE)
280 #define SDK_L1DCACHE_ALIGN(var) __attribute__((aligned(FSL_FEATURE_L1DCACHE_LINESIZE_BYTE))) var
283 #if defined(FSL_FEATURE_L2CACHE_LINESIZE_BYTE)
284 #define SDK_L2CACHE_ALIGN(var) __attribute__((aligned(FSL_FEATURE_L2CACHE_LINESIZE_BYTE))) var
286 #elif defined(__GNUC__)
288 #define SDK_ALIGN(var, alignbytes) var __attribute__((aligned(alignbytes)))
290 #if defined(FSL_FEATURE_L1DCACHE_LINESIZE_BYTE)
291 #define SDK_L1DCACHE_ALIGN(var) var __attribute__((aligned(FSL_FEATURE_L1DCACHE_LINESIZE_BYTE)))
294 #if defined(FSL_FEATURE_L2CACHE_LINESIZE_BYTE)
295 #define SDK_L2CACHE_ALIGN(var) var __attribute__((aligned(FSL_FEATURE_L2CACHE_LINESIZE_BYTE)))
298 #error Toolchain not supported
299 #define SDK_ALIGN(var, alignbytes) var
300 #if defined(FSL_FEATURE_L1DCACHE_LINESIZE_BYTE)
301 #define SDK_L1DCACHE_ALIGN(var) var
303 #if defined(FSL_FEATURE_L2CACHE_LINESIZE_BYTE)
304 #define SDK_L2CACHE_ALIGN(var) var
309 #define SDK_SIZEALIGN(var, alignbytes) \
310 ((unsigned int)((var) + ((alignbytes)-1U)) & (unsigned int)(~(unsigned int)((alignbytes)-1U)))
320 #if (defined(__ICCARM__))
321 #if ((!(defined(FSL_FEATURE_HAS_NO_NONCACHEABLE_SECTION) && FSL_FEATURE_HAS_NO_NONCACHEABLE_SECTION)) && defined(FSL_FEATURE_L1ICACHE_LINESIZE_BYTE))
322 #define AT_NONCACHEABLE_SECTION(var) var @"NonCacheable"
323 #define AT_NONCACHEABLE_SECTION_ALIGN(var, alignbytes) SDK_PRAGMA(data_alignment = alignbytes) var @"NonCacheable"
324 #define AT_NONCACHEABLE_SECTION_INIT(var) var @"NonCacheable.init"
325 #define AT_NONCACHEABLE_SECTION_ALIGN_INIT(var, alignbytes) SDK_PRAGMA(data_alignment = alignbytes) var @"NonCacheable.init"
327 #define AT_NONCACHEABLE_SECTION(var) var
328 #define AT_NONCACHEABLE_SECTION_ALIGN(var, alignbytes) SDK_PRAGMA(data_alignment = alignbytes) var
329 #define AT_NONCACHEABLE_SECTION_INIT(var) var
330 #define AT_NONCACHEABLE_SECTION_ALIGN_INIT(var, alignbytes) SDK_PRAGMA(data_alignment = alignbytes) var
332 #elif(defined(__CC_ARM) || defined(__ARMCC_VERSION))
333 #if ((!(defined(FSL_FEATURE_HAS_NO_NONCACHEABLE_SECTION) && FSL_FEATURE_HAS_NO_NONCACHEABLE_SECTION)) && defined(FSL_FEATURE_L1ICACHE_LINESIZE_BYTE))
334 #define AT_NONCACHEABLE_SECTION_INIT(var) __attribute__((section("NonCacheable.init"))) var
335 #define AT_NONCACHEABLE_SECTION_ALIGN_INIT(var, alignbytes) \
336 __attribute__((section("NonCacheable.init"))) __attribute__((aligned(alignbytes))) var
337 #if(defined(__CC_ARM))
338 #define AT_NONCACHEABLE_SECTION(var) __attribute__((section("NonCacheable"), zero_init)) var
339 #define AT_NONCACHEABLE_SECTION_ALIGN(var, alignbytes) \
340 __attribute__((section("NonCacheable"), zero_init)) __attribute__((aligned(alignbytes))) var
342 #define AT_NONCACHEABLE_SECTION(var) __attribute__((section(".bss.NonCacheable"))) var
343 #define AT_NONCACHEABLE_SECTION_ALIGN(var, alignbytes) \
344 __attribute__((section(".bss.NonCacheable"))) __attribute__((aligned(alignbytes))) var
347 #define AT_NONCACHEABLE_SECTION(var) var
348 #define AT_NONCACHEABLE_SECTION_ALIGN(var, alignbytes) __attribute__((aligned(alignbytes))) var
349 #define AT_NONCACHEABLE_SECTION_INIT(var) var
350 #define AT_NONCACHEABLE_SECTION_ALIGN_INIT(var, alignbytes) __attribute__((aligned(alignbytes))) var
352 #elif(defined(__XCC__))
353 #define AT_NONCACHEABLE_SECTION_INIT(var) __attribute__((section("NonCacheable.init"))) var
354 #define AT_NONCACHEABLE_SECTION_ALIGN_INIT(var, alignbytes) \
355 __attribute__((section("NonCacheable.init"))) var __attribute__((aligned(alignbytes)))
356 #define AT_NONCACHEABLE_SECTION(var) __attribute__((section("NonCacheable"))) var
357 #define AT_NONCACHEABLE_SECTION_ALIGN(var, alignbytes) \
358 __attribute__((section("NonCacheable"))) var __attribute__((aligned(alignbytes)))
359 #elif(defined(__GNUC__))
363 #if ((!(defined(FSL_FEATURE_HAS_NO_NONCACHEABLE_SECTION) && FSL_FEATURE_HAS_NO_NONCACHEABLE_SECTION)) && defined(FSL_FEATURE_L1ICACHE_LINESIZE_BYTE))
364 #define AT_NONCACHEABLE_SECTION_INIT(var) __attribute__((section("NonCacheable.init"))) var
365 #define AT_NONCACHEABLE_SECTION_ALIGN_INIT(var, alignbytes) \
366 __attribute__((section("NonCacheable.init"))) var __attribute__((aligned(alignbytes)))
367 #define AT_NONCACHEABLE_SECTION(var) __attribute__((section("NonCacheable,\"aw\",%nobits @"))) var
368 #define AT_NONCACHEABLE_SECTION_ALIGN(var, alignbytes) \
369 __attribute__((section("NonCacheable,\"aw\",%nobits @"))) var __attribute__((aligned(alignbytes)))
371 #define AT_NONCACHEABLE_SECTION(var) var
372 #define AT_NONCACHEABLE_SECTION_ALIGN(var, alignbytes) var __attribute__((aligned(alignbytes)))
373 #define AT_NONCACHEABLE_SECTION_INIT(var) var
374 #define AT_NONCACHEABLE_SECTION_ALIGN_INIT(var, alignbytes) var __attribute__((aligned(alignbytes)))
377 #error Toolchain not supported.
378 #define AT_NONCACHEABLE_SECTION(var) var
379 #define AT_NONCACHEABLE_SECTION_ALIGN(var, alignbytes) var
380 #define AT_NONCACHEABLE_SECTION_INIT(var) var
381 #define AT_NONCACHEABLE_SECTION_ALIGN_INIT(var, alignbytes) var
387 #if defined(FSL_SDK_DRIVER_QUICK_ACCESS_ENABLE) && FSL_SDK_DRIVER_QUICK_ACCESS_ENABLE
388 #if (defined(__ICCARM__))
389 #define AT_QUICKACCESS_SECTION_CODE(func) func @"CodeQuickAccess"
390 #define AT_QUICKACCESS_SECTION_DATA(func) func @"DataQuickAccess"
391 #elif(defined(__CC_ARM) || defined(__ARMCC_VERSION))
392 #define AT_QUICKACCESS_SECTION_CODE(func) __attribute__((section("CodeQuickAccess"), __noinline__)) func
393 #define AT_QUICKACCESS_SECTION_DATA(func) __attribute__((section("DataQuickAccess"))) func
394 #elif(defined(__GNUC__))
395 #define AT_QUICKACCESS_SECTION_CODE(func) __attribute__((section("CodeQuickAccess"), __noinline__)) func
396 #define AT_QUICKACCESS_SECTION_DATA(func) __attribute__((section("DataQuickAccess"))) func
398 #error Toolchain not supported.
401 #if (defined(__ICCARM__))
402 #define AT_QUICKACCESS_SECTION_CODE(func) func
403 #define AT_QUICKACCESS_SECTION_DATA(func) func
404 #elif(defined(__CC_ARM) || defined(__ARMCC_VERSION))
405 #define AT_QUICKACCESS_SECTION_CODE(func) func
406 #define AT_QUICKACCESS_SECTION_DATA(func) func
407 #elif(defined(__GNUC__))
408 #define AT_QUICKACCESS_SECTION_CODE(func) func
409 #define AT_QUICKACCESS_SECTION_DATA(func) func
411 #error Toolchain not supported.
417 #if (defined(__ICCARM__))
418 #define RAMFUNCTION_SECTION_CODE(func) func @"RamFunction"
419 #elif(defined(__CC_ARM) || defined(__ARMCC_VERSION))
420 #define RAMFUNCTION_SECTION_CODE(func) __attribute__((section("RamFunction"))) func
421 #elif(defined(__GNUC__))
422 #define RAMFUNCTION_SECTION_CODE(func) __attribute__((section("RamFunction"))) func
424 #error Toolchain not supported.
435 #if defined(__GNUC__) && !defined(__ARMCC_VERSION)
436 #define SUPPRESS_FALL_THROUGH_WARNING() __attribute__ ((fallthrough))
438 #define SUPPRESS_FALL_THROUGH_WARNING()
442 #if defined ( __ARMCC_VERSION ) && ( __ARMCC_VERSION >= 6010050 )
443 void DefaultISR(
void);
454 #if ((defined(FSL_FEATURE_SOC_SYSCON_COUNT) && (FSL_FEATURE_SOC_SYSCON_COUNT > 0)) || \
455 (defined(FSL_FEATURE_SOC_ASYNC_SYSCON_COUNT) && (FSL_FEATURE_SOC_ASYNC_SYSCON_COUNT > 0)))
456 #include "fsl_reset.h"
463 #if defined(__cplusplus)
491 #if defined(FSL_FEATURE_NUMBER_OF_LEVEL1_INT_VECTORS) && (FSL_FEATURE_NUMBER_OF_LEVEL1_INT_VECTORS > 0)
492 if ((uint32_t)interrupt >= (uint32_t)FSL_FEATURE_NUMBER_OF_LEVEL1_INT_VECTORS)
498 #if defined(__GIC_PRIO_BITS)
499 GIC_EnableIRQ(interrupt);
529 #if defined(FSL_FEATURE_NUMBER_OF_LEVEL1_INT_VECTORS) && (FSL_FEATURE_NUMBER_OF_LEVEL1_INT_VECTORS > 0)
530 if ((uint32_t)interrupt >= (uint32_t)FSL_FEATURE_NUMBER_OF_LEVEL1_INT_VECTORS)
536 #if defined(__GIC_PRIO_BITS)
537 GIC_DisableIRQ(interrupt);
554 #if defined (__XCC__)
557 #if defined(CPSR_I_Msk)
558 uint32_t cpsr = __get_CPSR() & CPSR_I_Msk;
585 #if defined (__XCC__)
587 #if defined(CPSR_I_Msk)
588 __set_CPSR((__get_CPSR() & ~CPSR_I_Msk) | primask);
595 #if defined(ENABLE_RAM_VECTOR_TABLE)
603 uint32_t InstallIRQHandler(
IRQn_Type irq, uint32_t irqHandler);
606 #if (defined(FSL_FEATURE_SOC_SYSCON_COUNT) && (FSL_FEATURE_SOC_SYSCON_COUNT > 0))
620 void EnableDeepSleepIRQ(
IRQn_Type interrupt);
635 void DisableDeepSleepIRQ(
IRQn_Type interrupt);
647 void *
SDK_Malloc(
size_t size,
size_t alignbytes);
666 #if defined(__cplusplus)
@ kStatusGroup_ApplicationRangeStart
@ kStatus_InvalidArgument
__STATIC_INLINE uint32_t __get_PRIMASK(void)
Get Priority Mask.
@ kStatusGroup_COMMON_TASK
@ kStatusGroup_FLEXIO_UART
@ kStatusGroup_FLEXIO_MCULCD
@ kStatusGroup_FLEXIO_CAMERA
@ kStatus_NoTransferInProgress
__STATIC_FORCEINLINE void __disable_irq(void)
Disable IRQ Interrupts.
@ kStatusGroup_SDK_FLEXSPINOR
@ kStatusGroup_LPC_MINISPI
@ kStatusGroup_TIMERMANAGER
void SDK_DelayAtLeastUs(uint32_t delay_us, uint32_t coreClock_Hz)
Delay at least for some time. Please note that, this API uses while loop for delay,...
@ kStatusGroup_MEM_MANAGER
void SDK_Free(void *ptr)
Free memory.
void * SDK_Malloc(size_t size, size_t alignbytes)
Allocate memory with given alignment and aligned size.
@ kStatusGroup_FLEXIO_I2S
__STATIC_INLINE void __set_PRIMASK(uint32_t priMask)
Set Priority Mask.
@ kStatusGroup_DebugConsole
@ kStatusGroup_FLEXCOMM_I2C
#define MAKE_STATUS(group, code)
Construct a status code value from a group and code number.
static status_t DisableIRQ(IRQn_Type interrupt)
Disable specific interrupt.
@ kStatusGroup_FLEXIO_I2C
@ kStatusGroup_EXTERN_EEPROM
IRQn_Type
STM32F4XX Interrupt Number Definition, according to the selected device in Library_configuration_sect...
@ kStatusGroup_LPC_SPI_SSP
@ kStatusGroup_SERIALMANAGER
static uint32_t DisableGlobalIRQ(void)
Disable the global IRQ.
static status_t EnableIRQ(IRQn_Type interrupt)
Enable specific interrupt.
@ kStatusGroup_FLEXIO_SPI
int32_t status_t
Type used for all status and error return values.
static void EnableGlobalIRQ(uint32_t primask)
Enable the global IRQ.