9#ifndef _FSL_COMMON_ARM_H_
10#define _FSL_COMMON_ARM_H_
18#include "RTE_Components.h"
63#if ((defined(__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \
64 (defined(__ARM_ARCH_7EM__ ) && (__ARM_ARCH_7EM__ == 1)) || \
65 (defined(__ARM_ARCH_8M_MAIN__) && (__ARM_ARCH_8M_MAIN__ == 1)) || \
66 (defined(__ARM_ARCH_8M_BASE__) && (__ARM_ARCH_8M_BASE__ == 1)))
70#define _SDK_ATOMIC_LOCAL_OPS_1BYTE(addr, val, ops) \
73 (val) = __LDREXB(addr); \
75 } while (0UL != __STREXB((val), (addr)))
77#define _SDK_ATOMIC_LOCAL_OPS_2BYTE(addr, val, ops) \
80 (val) = __LDREXH(addr); \
82 } while (0UL != __STREXH((val), (addr)))
84#define _SDK_ATOMIC_LOCAL_OPS_4BYTE(addr, val, ops) \
87 (val) = __LDREXW(addr); \
89 } while (0UL != __STREXW((val), (addr)))
91static inline void _SDK_AtomicLocalAdd1Byte(
volatile uint8_t *addr, uint8_t val)
95 _SDK_ATOMIC_LOCAL_OPS_1BYTE(addr, s_val, s_val += val);
98static inline void _SDK_AtomicLocalAdd2Byte(
volatile uint16_t *addr, uint16_t val)
102 _SDK_ATOMIC_LOCAL_OPS_2BYTE(addr, s_val, s_val += val);
105static inline void _SDK_AtomicLocalAdd4Byte(
volatile uint32_t *addr, uint32_t val)
109 _SDK_ATOMIC_LOCAL_OPS_4BYTE(addr, s_val, s_val += val);
112static inline void _SDK_AtomicLocalSub1Byte(
volatile uint8_t *addr, uint8_t val)
116 _SDK_ATOMIC_LOCAL_OPS_1BYTE(addr, s_val, s_val -= val);
119static inline void _SDK_AtomicLocalSub2Byte(
volatile uint16_t *addr, uint16_t val)
123 _SDK_ATOMIC_LOCAL_OPS_2BYTE(addr, s_val, s_val -= val);
126static inline void _SDK_AtomicLocalSub4Byte(
volatile uint32_t *addr, uint32_t val)
130 _SDK_ATOMIC_LOCAL_OPS_4BYTE(addr, s_val, s_val -= val);
133static inline void _SDK_AtomicLocalSet1Byte(
volatile uint8_t *addr, uint8_t bits)
137 _SDK_ATOMIC_LOCAL_OPS_1BYTE(addr, s_val, s_val |= bits);
140static inline void _SDK_AtomicLocalSet2Byte(
volatile uint16_t *addr, uint16_t bits)
144 _SDK_ATOMIC_LOCAL_OPS_2BYTE(addr, s_val, s_val |= bits);
147static inline void _SDK_AtomicLocalSet4Byte(
volatile uint32_t *addr, uint32_t bits)
151 _SDK_ATOMIC_LOCAL_OPS_4BYTE(addr, s_val, s_val |= bits);
154static inline void _SDK_AtomicLocalClear1Byte(
volatile uint8_t *addr, uint8_t bits)
158 _SDK_ATOMIC_LOCAL_OPS_1BYTE(addr, s_val, s_val &= ~bits);
161static inline void _SDK_AtomicLocalClear2Byte(
volatile uint16_t *addr, uint16_t bits)
165 _SDK_ATOMIC_LOCAL_OPS_2BYTE(addr, s_val, s_val &= ~bits);
168static inline void _SDK_AtomicLocalClear4Byte(
volatile uint32_t *addr, uint32_t bits)
172 _SDK_ATOMIC_LOCAL_OPS_4BYTE(addr, s_val, s_val &= ~bits);
175static inline void _SDK_AtomicLocalToggle1Byte(
volatile uint8_t *addr, uint8_t bits)
179 _SDK_ATOMIC_LOCAL_OPS_1BYTE(addr, s_val, s_val ^= bits);
182static inline void _SDK_AtomicLocalToggle2Byte(
volatile uint16_t *addr, uint16_t bits)
186 _SDK_ATOMIC_LOCAL_OPS_2BYTE(addr, s_val, s_val ^= bits);
189static inline void _SDK_AtomicLocalToggle4Byte(
volatile uint32_t *addr, uint32_t bits)
193 _SDK_ATOMIC_LOCAL_OPS_4BYTE(addr, s_val, s_val ^= bits);
196static inline void _SDK_AtomicLocalClearAndSet1Byte(
volatile uint8_t *addr, uint8_t clearBits, uint8_t setBits)
200 _SDK_ATOMIC_LOCAL_OPS_1BYTE(addr, s_val, s_val = (s_val & ~clearBits) | setBits);
203static inline void _SDK_AtomicLocalClearAndSet2Byte(
volatile uint16_t *addr, uint16_t clearBits, uint16_t setBits)
207 _SDK_ATOMIC_LOCAL_OPS_2BYTE(addr, s_val, s_val = (s_val & ~clearBits) | setBits);
210static inline void _SDK_AtomicLocalClearAndSet4Byte(
volatile uint32_t *addr, uint32_t clearBits, uint32_t setBits)
214 _SDK_ATOMIC_LOCAL_OPS_4BYTE(addr, s_val, s_val = (s_val & ~clearBits) | setBits);
217#define SDK_ATOMIC_LOCAL_ADD(addr, val) \
218 ((1UL == sizeof(*(addr))) ? \
219 _SDK_AtomicLocalAdd1Byte((volatile uint8_t *)(volatile void *)(addr), (uint8_t)(val)) : \
220 ((2UL == sizeof(*(addr))) ? _SDK_AtomicLocalAdd2Byte((volatile uint16_t *)(volatile void *)(addr), (uint16_t)(val)) : \
221 _SDK_AtomicLocalAdd4Byte((volatile uint32_t *)(volatile void *)(addr), (uint32_t)(val))))
223#define SDK_ATOMIC_LOCAL_SET(addr, bits) \
224 ((1UL == sizeof(*(addr))) ? \
225 _SDK_AtomicLocalSet1Byte((volatile uint8_t *)(volatile void *)(addr), (uint8_t)(bits)) : \
226 ((2UL == sizeof(*(addr))) ? _SDK_AtomicLocalSet2Byte((volatile uint16_t *)(volatile void *)(addr), (uint16_t)(bits)) : \
227 _SDK_AtomicLocalSet4Byte((volatile uint32_t *)(volatile void *)(addr), (uint32_t)(bits))))
229#define SDK_ATOMIC_LOCAL_CLEAR(addr, bits) \
230 ((1UL == sizeof(*(addr))) ? \
231 _SDK_AtomicLocalClear1Byte((volatile uint8_t *)(volatile void *)(addr), (uint8_t)(bits)) : \
232 ((2UL == sizeof(*(addr))) ? \
233 _SDK_AtomicLocalClear2Byte((volatile uint16_t *)(volatile void *)(addr), (uint16_t)(bits)) : \
234 _SDK_AtomicLocalClear4Byte((volatile uint32_t *)(volatile void *)(addr), (uint32_t)(bits))))
236#define SDK_ATOMIC_LOCAL_TOGGLE(addr, bits) \
237 ((1UL == sizeof(*(addr))) ? \
238 _SDK_AtomicLocalToggle1Byte((volatile uint8_t *)(volatile void *)(addr), (uint8_t)(bits)) : \
239 ((2UL == sizeof(*(addr))) ? \
240 _SDK_AtomicLocalToggle2Byte((volatile uint16_t *)(volatile void *)(addr), (uint16_t)(bits)) : \
241 _SDK_AtomicLocalToggle4Byte((volatile uint32_t *)(volatile void *)(addr), (uint32_t)(bits))))
243#define SDK_ATOMIC_LOCAL_CLEAR_AND_SET(addr, clearBits, setBits) \
244 ((1UL == sizeof(*(addr))) ? \
245 _SDK_AtomicLocalClearAndSet1Byte((volatile uint8_t *)(volatile void *)(addr), (uint8_t)(clearBits), (uint8_t)(setBits)) : \
246 ((2UL == sizeof(*(addr))) ? \
247 _SDK_AtomicLocalClearAndSet2Byte((volatile uint16_t *)(volatile void *)(addr), (uint16_t)(clearBits), (uint16_t)(setBits)) : \
248 _SDK_AtomicLocalClearAndSet4Byte((volatile uint32_t *)(volatile void *)(addr), (uint32_t)(clearBits), (uint32_t)(setBits))))
251#define SDK_ATOMIC_LOCAL_ADD(addr, val) \
254 uint32_t s_atomicOldInt; \
255 s_atomicOldInt = DisableGlobalIRQ(); \
257 EnableGlobalIRQ(s_atomicOldInt); \
260#define SDK_ATOMIC_LOCAL_SET(addr, bits) \
263 uint32_t s_atomicOldInt; \
264 s_atomicOldInt = DisableGlobalIRQ(); \
266 EnableGlobalIRQ(s_atomicOldInt); \
269#define SDK_ATOMIC_LOCAL_CLEAR(addr, bits) \
272 uint32_t s_atomicOldInt; \
273 s_atomicOldInt = DisableGlobalIRQ(); \
274 *(addr) &= ~(bits); \
275 EnableGlobalIRQ(s_atomicOldInt); \
278#define SDK_ATOMIC_LOCAL_TOGGLE(addr, bits) \
281 uint32_t s_atomicOldInt; \
282 s_atomicOldInt = DisableGlobalIRQ(); \
284 EnableGlobalIRQ(s_atomicOldInt); \
287#define SDK_ATOMIC_LOCAL_CLEAR_AND_SET(addr, clearBits, setBits) \
290 uint32_t s_atomicOldInt; \
291 s_atomicOldInt = DisableGlobalIRQ(); \
292 *(addr) = (*(addr) & ~(clearBits)) | (setBits); \
293 EnableGlobalIRQ(s_atomicOldInt); \
302#define USEC_TO_COUNT(us, clockFreqInHz) (uint64_t)(((uint64_t)(us) * (clockFreqInHz)) / 1000000U)
304#define COUNT_TO_USEC(count, clockFreqInHz) (uint64_t)((uint64_t)(count)*1000000U / (clockFreqInHz))
307#define MSEC_TO_COUNT(ms, clockFreqInHz) (uint64_t)((uint64_t)(ms) * (clockFreqInHz) / 1000U)
309#define COUNT_TO_MSEC(count, clockFreqInHz) (uint64_t)((uint64_t)(count)*1000U / (clockFreqInHz))
321#if (defined __CORTEX_M) && ((__CORTEX_M == 4U) || (__CORTEX_M == 7U))
322#define SDK_ISR_EXIT_BARRIER __DSB()
324#define SDK_ISR_EXIT_BARRIER
331#if (defined(__ICCARM__))
336_Pragma(
"diag_suppress=Pm120")
337#define SDK_PRAGMA(x) _Pragma(#x)
338 _Pragma(
"diag_error=Pm120")
340#define SDK_ALIGN(var, alignbytes) SDK_PRAGMA(data_alignment = alignbytes) var
341#elif defined(__CC_ARM) || defined(__ARMCC_VERSION)
343#define SDK_ALIGN(var, alignbytes) __attribute__((aligned(alignbytes))) var
344#elif defined(__GNUC__)
346#define SDK_ALIGN(var, alignbytes) var __attribute__((aligned(alignbytes)))
348#error Toolchain not supported
352#if defined(FSL_FEATURE_L1DCACHE_LINESIZE_BYTE)
353#define SDK_L1DCACHE_ALIGN(var) SDK_ALIGN(var, FSL_FEATURE_L1DCACHE_LINESIZE_BYTE)
356#if defined(FSL_FEATURE_L2CACHE_LINESIZE_BYTE)
357#define SDK_L2CACHE_ALIGN(var) SDK_ALIGN(var, FSL_FEATURE_L2CACHE_LINESIZE_BYTE)
361#define SDK_SIZEALIGN(var, alignbytes) \
362 ((unsigned int)((var) + ((alignbytes)-1U)) & (unsigned int)(~(unsigned int)((alignbytes)-1U)))
373#if ((!(defined(FSL_FEATURE_HAS_NO_NONCACHEABLE_SECTION) && FSL_FEATURE_HAS_NO_NONCACHEABLE_SECTION)) && \
374 defined(FSL_FEATURE_L1ICACHE_LINESIZE_BYTE))
376#if (defined(__ICCARM__))
377#define AT_NONCACHEABLE_SECTION(var) var @"NonCacheable"
378#define AT_NONCACHEABLE_SECTION_ALIGN(var, alignbytes) SDK_PRAGMA(data_alignment = alignbytes) var @"NonCacheable"
379#define AT_NONCACHEABLE_SECTION_INIT(var) var @"NonCacheable.init"
380#define AT_NONCACHEABLE_SECTION_ALIGN_INIT(var, alignbytes) \
381 SDK_PRAGMA(data_alignment = alignbytes) var @"NonCacheable.init"
383#elif (defined(__CC_ARM) || defined(__ARMCC_VERSION))
384#define AT_NONCACHEABLE_SECTION_INIT(var) __attribute__((section("NonCacheable.init"))) var
385#define AT_NONCACHEABLE_SECTION_ALIGN_INIT(var, alignbytes) \
386 __attribute__((section("NonCacheable.init"))) __attribute__((aligned(alignbytes))) var
387#if (defined(__CC_ARM))
388#define AT_NONCACHEABLE_SECTION(var) __attribute__((section("NonCacheable"), zero_init)) var
389#define AT_NONCACHEABLE_SECTION_ALIGN(var, alignbytes) \
390 __attribute__((section("NonCacheable"), zero_init)) __attribute__((aligned(alignbytes))) var
392#define AT_NONCACHEABLE_SECTION(var) __attribute__((section(".bss.NonCacheable"))) var
393#define AT_NONCACHEABLE_SECTION_ALIGN(var, alignbytes) \
394 __attribute__((section(".bss.NonCacheable"))) __attribute__((aligned(alignbytes))) var
397#elif (defined(__GNUC__))
398#if defined(__ARM_ARCH_8A__)
407#define AT_NONCACHEABLE_SECTION_INIT(var) __attribute__((section("NonCacheable.init"))) var
408#define AT_NONCACHEABLE_SECTION_ALIGN_INIT(var, alignbytes) \
409 __attribute__((section("NonCacheable.init"))) var __attribute__((aligned(alignbytes)))
410#define AT_NONCACHEABLE_SECTION(var) __attribute__((section("NonCacheable,\"aw\",%nobits " __CS))) var
411#define AT_NONCACHEABLE_SECTION_ALIGN(var, alignbytes) \
412 __attribute__((section("NonCacheable,\"aw\",%nobits " __CS))) var __attribute__((aligned(alignbytes)))
414#error Toolchain not supported.
419#define AT_NONCACHEABLE_SECTION(var) var
420#define AT_NONCACHEABLE_SECTION_ALIGN(var, alignbytes) SDK_ALIGN(var, alignbytes)
421#define AT_NONCACHEABLE_SECTION_INIT(var) var
422#define AT_NONCACHEABLE_SECTION_ALIGN_INIT(var, alignbytes) SDK_ALIGN(var, alignbytes)
432#if (defined(__ICCARM__))
433#define AT_QUICKACCESS_SECTION_CODE(func) func @"CodeQuickAccess"
434#define AT_QUICKACCESS_SECTION_DATA(var) var @"DataQuickAccess"
435#define AT_QUICKACCESS_SECTION_DATA_ALIGN(var, alignbytes) \
436 SDK_PRAGMA(data_alignment = alignbytes) var @"DataQuickAccess"
437#elif (defined(__CC_ARM) || defined(__ARMCC_VERSION))
438#define AT_QUICKACCESS_SECTION_CODE(func) __attribute__((section("CodeQuickAccess"), __noinline__)) func
439#define AT_QUICKACCESS_SECTION_DATA(var) __attribute__((section("DataQuickAccess"))) var
440#define AT_QUICKACCESS_SECTION_DATA_ALIGN(var, alignbytes) \
441 __attribute__((section("DataQuickAccess"))) __attribute__((aligned(alignbytes))) var
442#elif (defined(__GNUC__))
443#define AT_QUICKACCESS_SECTION_CODE(func) __attribute__((section("CodeQuickAccess"), __noinline__)) func
444#define AT_QUICKACCESS_SECTION_DATA(var) __attribute__((section("DataQuickAccess"))) var
445#define AT_QUICKACCESS_SECTION_DATA_ALIGN(var, alignbytes) \
446 __attribute__((section("DataQuickAccess"))) var __attribute__((aligned(alignbytes)))
448#error Toolchain not supported.
452#if (defined(__ICCARM__))
453#define RAMFUNCTION_SECTION_CODE(func) func @"RamFunction"
454#elif (defined(__CC_ARM) || defined(__ARMCC_VERSION))
455#define RAMFUNCTION_SECTION_CODE(func) __attribute__((section("RamFunction"))) func
456#elif (defined(__GNUC__))
457#define RAMFUNCTION_SECTION_CODE(func) __attribute__((section("RamFunction"))) func
459#error Toolchain not supported.
463#if defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)
464 void DefaultISR(
void);
471#include "fsl_clock.h"
476#if ((defined(FSL_FEATURE_SOC_SYSCON_COUNT) && (FSL_FEATURE_SOC_SYSCON_COUNT > 0)) || \
477 (defined(FSL_FEATURE_SOC_ASYNC_SYSCON_COUNT) && (FSL_FEATURE_SOC_ASYNC_SYSCON_COUNT > 0)))
478#include "fsl_reset.h"
485#if defined(__cplusplus)
514#if defined(FSL_FEATURE_NUMBER_OF_LEVEL1_INT_VECTORS) && (FSL_FEATURE_NUMBER_OF_LEVEL1_INT_VECTORS > 0)
515 else if ((int32_t)interrupt >= (int32_t)FSL_FEATURE_NUMBER_OF_LEVEL1_INT_VECTORS)
523#if defined(__GIC_PRIO_BITS)
524 GIC_EnableIRQ(interrupt);
526 NVIC_EnableIRQ(interrupt);
558#if defined(FSL_FEATURE_NUMBER_OF_LEVEL1_INT_VECTORS) && (FSL_FEATURE_NUMBER_OF_LEVEL1_INT_VECTORS > 0)
559 else if ((int32_t)interrupt >= (int32_t)FSL_FEATURE_NUMBER_OF_LEVEL1_INT_VECTORS)
567#if defined(__GIC_PRIO_BITS)
568 GIC_DisableIRQ(interrupt);
570 NVIC_DisableIRQ(interrupt);
577#if defined(__GIC_PRIO_BITS)
578#define NVIC_SetPriority(irq, prio) do {} while(0)
607#if defined(FSL_FEATURE_NUMBER_OF_LEVEL1_INT_VECTORS) && (FSL_FEATURE_NUMBER_OF_LEVEL1_INT_VECTORS > 0)
608 else if ((int32_t)interrupt >= (int32_t)FSL_FEATURE_NUMBER_OF_LEVEL1_INT_VECTORS)
616#if defined(__GIC_PRIO_BITS)
617 GIC_SetPriority(interrupt, priNum);
618 GIC_EnableIRQ(interrupt);
620 NVIC_SetPriority(interrupt, priNum);
621 NVIC_EnableIRQ(interrupt);
655#if defined(FSL_FEATURE_NUMBER_OF_LEVEL1_INT_VECTORS) && (FSL_FEATURE_NUMBER_OF_LEVEL1_INT_VECTORS > 0)
656 else if ((int32_t)interrupt >= (int32_t)FSL_FEATURE_NUMBER_OF_LEVEL1_INT_VECTORS)
664#if defined(__GIC_PRIO_BITS)
665 GIC_SetPriority(interrupt, priNum);
667 NVIC_SetPriority(interrupt, priNum);
700#if defined(FSL_FEATURE_NUMBER_OF_LEVEL1_INT_VECTORS) && (FSL_FEATURE_NUMBER_OF_LEVEL1_INT_VECTORS > 0)
701 else if ((int32_t)interrupt >= (int32_t)FSL_FEATURE_NUMBER_OF_LEVEL1_INT_VECTORS)
709#if defined(__GIC_PRIO_BITS)
710 GIC_ClearPendingIRQ(interrupt);
712 NVIC_ClearPendingIRQ(interrupt);
727static inline uint32_t DisableGlobalIRQ(
void)
731#if defined(CPSR_I_Msk)
732 mask = __get_CPSR() & CPSR_I_Msk;
733#elif defined(DAIF_I_BIT)
734 mask = __get_DAIF() & DAIF_I_BIT;
753static inline void EnableGlobalIRQ(uint32_t primask)
755#if defined(CPSR_I_Msk)
756 __set_CPSR((__get_CPSR() & ~CPSR_I_Msk) | primask);
757#elif defined(DAIF_I_BIT)
767#if defined(ENABLE_RAM_VECTOR_TABLE)
775uint32_t InstallIRQHandler(
IRQn_Type irq, uint32_t irqHandler);
778#if (defined(FSL_FEATURE_SOC_SYSCON_COUNT) && (FSL_FEATURE_SOC_SYSCON_COUNT > 0))
784#if !(defined(FSL_FEATURE_POWERLIB_EXTEND) && (FSL_FEATURE_POWERLIB_EXTEND != 0))
798void EnableDeepSleepIRQ(
IRQn_Type interrupt);
813void DisableDeepSleepIRQ(
IRQn_Type interrupt);
821void MSDK_EnableCpuCycleCounter(
void);
828uint32_t MSDK_GetCpuCycleCount(
void);
831#if defined(__cplusplus)
__STATIC_FORCEINLINE void __disable_irq(void)
Disable IRQ Interrupts.
Definition: cmsis_gcc.h:977
__STATIC_FORCEINLINE uint32_t __get_PRIMASK(void)
Get Priority Mask.
Definition: cmsis_gcc.h:1221
__STATIC_FORCEINLINE void __enable_irq(void)
Enable IRQ Interrupts.
Definition: cmsis_gcc.h:966
__STATIC_FORCEINLINE void __set_PRIMASK(uint32_t priMask)
Set Priority Mask.
Definition: cmsis_gcc.h:1251
@ NotAvail_IRQn
Definition: MIMXRT1052.h:82
IRQn_Type
STM32H7XX Interrupt Number Definition, according to the selected device in Library_configuration_sect...
Definition: stm32h723xx.h:49
int32_t status_t
Type used for all status and error return values.
Definition: fsl_common.h:225
@ kStatus_Success
Definition: fsl_common.h:211
@ kStatus_Fail
Definition: fsl_common.h:212