CMSIS-Core (Cortex-A)  
CMSIS-Core support for Cortex-A processor-based devices
 
Loading...
Searching...
No Matches
Compiler Control

Compiler agnostic #define symbols for generic C/C++ source code. More...

Macros

#define __ARM_ARCH_7A__
 Set to 1 when generating code for Armv7-A (Cortex-A7)
 
#define __ASM   __asm
 Pass information from the compiler to the assembler.
 
#define __INLINE   __inline
 Recommend that function should be inlined by the compiler.
 
#define __STATIC_INLINE   static __inline
 Define a static function should be inlined by the compiler.
 
#define __STATIC_FORCEINLINE
 Define a static function that should be always inlined by the compiler.
 
#define __NO_RETURN   __attribute__((__noreturn__))
 Inform the compiler that a function does not return.
 
#define __USED   __attribute__((used))
 Inform that a variable shall be retained in executable image.
 
#define __WEAK   __attribute__((weak))
 Export a function or variable weakly to allow overwrites.
 
#define __ALIGNED(x)   __attribute__((aligned(x)))
 Minimum alignment for a variable.
 
#define __PACKED   __attribute__((packed, aligned(1)))
 Request smallest possible alignment.
 
#define __PACKED_STRUCT
 Request smallest possible alignment for a structure.
 
#define __UNALIGNED_UINT16_READ
 Pointer for unaligned read of a uint16_t variable.
 
#define __UNALIGNED_UINT16_WRITE
 Pointer for unaligned write of a uint16_t variable.
 
#define __UNALIGNED_UINT32_READ
 Pointer for unaligned read of a uint32_t variable.
 
#define __UNALIGNED_UINT32_WRITE
 Pointer for unaligned write of a uint32_t variable.
 

Description

Compiler agnostic #define symbols for generic C/C++ source code.

The CMSIS-Core provides the header file cmsis_compiler.h with consistent #define symbols to generate C or C++ source files that should be compiler agnostic. Each CMSIS compliant compiler should support the functionality described in this section.

Macro Definition Documentation

◆ __ALIGNED

#define __ALIGNED (   x)    __attribute__((aligned(x)))

Minimum alignment for a variable.

Specifies a minimum alignment for a variable or structure field, measured in bytes.

Code Example:

uint32_t stack_space[0x100] __ALIGNED(8); // 8-byte alignment required
#define __ALIGNED(x)
Minimum alignment for a variable.

◆ __ARM_ARCH_7A__

#define __ARM_ARCH_7A__

Set to 1 when generating code for Armv7-A (Cortex-A7)

The #define ARM_ARCH_7A is set to 1 when generating code for the Armv7-A architecture. This architecture is for example used by the Cortex-A7 processor.

◆ __ASM

#define __ASM   __asm

Pass information from the compiler to the assembler.

The __ASM keyword can declare or define an embedded assembly function or incorporate inline assembly into a function (shown in the code example below).

Code Example:

// Reverse bit order of value
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __RBIT(uint32_t value)
{
uint32_t result;
__ASM volatile ("rbit %0, %1" : "=r" (result) : "r" (value) );
return(result);
}
#define __RBIT
Reverse bit order of value.
Definition: cmsis_armclang_a.h:219
#define __ASM
Pass information from the compiler to the assembler.
#define __STATIC_INLINE
Define a static function should be inlined by the compiler.

◆ __INLINE

#define __INLINE   __inline

Recommend that function should be inlined by the compiler.

Inline functions offer a trade-off between code size and performance. By default, the compiler decides during optimization whether to inline code or not. The __INLINE attribute gives the compiler an hint to inline this function. Still, the compiler may decide not to inline the function. As the function is global an callable function is also generated.

Code Example:

const uint32_t led_mask[] = {1U << 4, 1U << 5, 1U << 6, 1U << 7};
//------------------------------------------------------------------------------
// Switch on LEDs
//------------------------------------------------------------------------------
__INLINE static void LED_On (uint32_t led) {
PTD->PCOR = led_mask[led];
}
#define __INLINE
Recommend that function should be inlined by the compiler.

◆ __NO_RETURN

#define __NO_RETURN   __attribute__((__noreturn__))

Inform the compiler that a function does not return.

Informs the compiler that the function does not return. The compiler can then perform optimizations by removing code that is never reached.

Code Example:

// OS idle demon (running when no other thread is ready to run).
__NO_RETURN void os_idle_demon (void);
#define __NO_RETURN
Inform the compiler that a function does not return.

◆ __PACKED

#define __PACKED   __attribute__((packed, aligned(1)))

Request smallest possible alignment.

Specifies that a type must have the smallest possible alignment.

Code Example:

struct foo {
uint8_t u8;
uint32_t u32[2] __PACKED;
};
#define __PACKED
Request smallest possible alignment.

◆ __PACKED_STRUCT

#define __PACKED_STRUCT

Request smallest possible alignment for a structure.

Specifies that a structure must have the smallest possible alignment.

Code Example:

uint8_t u8;
uint32_t u32;
uint16_t u16;
};
#define __PACKED_STRUCT
Definition: cmsis_armclang_a.h:60

◆ __STATIC_FORCEINLINE

#define __STATIC_FORCEINLINE

Define a static function that should be always inlined by the compiler.

Defines a static function that should be always inlined by the compiler.

Note
For compilers that do not allow to force function inlining, the macro maps to __STATIC_INLINE.

Code Example:

\\ Get Interrupt Vector
__STATIC_FORCEINLINE uint32_t NVIC_GetVector(IRQn_Type IRQn)
{
uint32_t *vectors = (uint32_t *) ((uintptr_t) SCB->VTOR);
return vectors[(int32_t)IRQn + NVIC_USER_IRQ_OFFSET];
}
#define __STATIC_FORCEINLINE
Definition: cmsis_armclang_a.h:42
IRQn_Type
Definition of IRQn numbers.
Definition: ref_irq_ctrl.txt:79

◆ __STATIC_INLINE

#define __STATIC_INLINE   static __inline

Define a static function should be inlined by the compiler.

Defines a static function that may be inlined by the compiler. If the compiler generates inline code for all calls to this functions, no additional function implementation is generated which may further optimize space.

Code Example:

{
return((uint32_t)GICDistributor->D_IPRIORITYR[((uint32_t)(int32_t)IRQn)]);
}
__STATIC_INLINE uint32_t GIC_GetPriority(IRQn_Type IRQn)
Read the current interrupt priority from GIC's IPRIORITYR register.
Definition: core_ca.h:1664
#define GICDistributor
GIC Distributor register set access pointer.

◆ __UNALIGNED_UINT16_READ

#define __UNALIGNED_UINT16_READ

Pointer for unaligned read of a uint16_t variable.

Defines a pointer to a uint16_t from an address that does not need to be aligned. This can then be used in read operations. The compiler will generate the appropriate access (aligned or non-aligned) depending on the underlying Arm processor core and compiler settings.

Code Example:

uint16_t val16;
void test (uint8_t *ptr) {
}
#define __UNALIGNED_UINT16_READ(addr)
Definition: cmsis_armclang_a.h:76

◆ __UNALIGNED_UINT16_WRITE

#define __UNALIGNED_UINT16_WRITE

Pointer for unaligned write of a uint16_t variable.

Defines a pointer to a uint16_t from an address that does not need to be aligned. This can then be used in write operations. The compiler will generate the appropriate access (aligned or non-aligned) depending on the underlying Arm processor core and compiler settings.

Code Example:

uint16_t val16 = 0U;
void test (uint8_t *ptr) {
}
#define __UNALIGNED_UINT16_WRITE(addr, val)
Definition: cmsis_armclang_a.h:68

◆ __UNALIGNED_UINT32_READ

#define __UNALIGNED_UINT32_READ

Pointer for unaligned read of a uint32_t variable.

Defines a pointer to a uint32_t from an address that does not need to be aligned. This can then be used in read operations. The compiler will generate the appropriate access (aligned or non-aligned) depending on the underlying Arm processor core and compiler settings.

Code Example:

uint32_t val32;
void test (uint8_t *ptr) {
}
#define __UNALIGNED_UINT32_READ(addr)
Definition: cmsis_armclang_a.h:91

◆ __UNALIGNED_UINT32_WRITE

#define __UNALIGNED_UINT32_WRITE

Pointer for unaligned write of a uint32_t variable.

Defines a pointer to a uint32_t from an address that does not need to be aligned. This can then be used in write operations. The compiler will generate the appropriate access (aligned or non-aligned) depending on the underlying Arm processor core and compiler settings.

Code Example:

uint32_t val32 = 0U;
void test (uint8_t *ptr) {
}
#define __UNALIGNED_UINT32_WRITE(addr, val)
Definition: cmsis_armclang_a.h:84

◆ __USED

#define __USED   __attribute__((used))

Inform that a variable shall be retained in executable image.

Definitions tagged with __USED in the source code should be not removed by the linker when detected as unused.

Code Example:

// Export following variables for debugging
__USED uint32_t const CMSIS_RTOS_API_Version = osCMSIS;
__USED uint32_t const CMSIS_RTOS_RTX_Version = osCMSIS_RTX;
__USED uint32_t const os_clockrate = OS_TICK;
__USED uint32_t const os_timernum = 0;
#define __USED
Inform that a variable shall be retained in executable image.

◆ __WEAK

#define __WEAK   __attribute__((weak))

Export a function or variable weakly to allow overwrites.

Functions defined with __WEAK export their symbols weakly. A function defined weak behaves like a normal defined function unless a non-weak function with the same name is linked into the same image. If both a non-weak function and a weak defined function exist in the same image, then all calls to the function resolve to the non-weak function.

Functions declared with __WEAK and then defined without __WEAK behave as non-weak functions.

Code Example:

__WEAK void SystemInit(void)
{
SystemCoreSetup();
SystemCoreClockSetup();
}
#define __WEAK
Export a function or variable weakly to allow overwrites.
void SystemInit(void)
Function to Initialize the system.