1 /**************************************************************************************************/
3 \defgroup compiler_conntrol_gr Compiler Control
4 \brief Compiler agnostic \#define symbols for generic C/C++ source code
6 The CMSIS-Core provides the header file <b>cmsis_compiler.h</b> with consistent \#define symbols for generate C or C++ source files that should be compiler agnostic.
7 Each CMSIS compliant compiler should support the functionality described in this section.
9 The header file <b>cmsis_compiler.h</b> is also included by each \ref device_h_pg so that these definitions are available.
15 \brief Set to 1 when generating code for ARMv6-M (Cortex-M0, Cortex-M1)
17 The <b>\#define __ARM_ARCH_6M__</b> is set to 1 when generating code for the ARMv6-M architecture. This architecture is for example used by the Cortex-M0, Cortex-M0+, and Cortex-M1 processor.
19 #define __ARM_ARCH_6M__
23 \brief Set to 1 when generating code for ARMv7-M (Cortex-M3)
25 The <b>\#define __ARM_ARCH_7M__</b> is set to 1 when generating code for the ARMv7-M architecture. This architecture is for example used by the Cortex-M3 processor.
27 #define __ARM_ARCH_7M__
31 \brief Set to 1 when generating code for ARMv7-M (Cortex-M4) with FPU
33 The <b>\#define __ARM_ARCH_7EM__</b> is set to 1 when generating code for the ARMv7-M architecture with floating point extension. This architecture is for example used by the Cortex-M4 processor with FPU
35 #define __ARM_ARCH_7EM__
38 \def __ARM_ARCH_8M_BASE__
39 \brief Set to 1 when generating code for ARMv8-M Baseline
41 The <b>\#define __ARM_ARCH_8M_BASE__</b> is set to 1 when generating code for the ARMv8-M architecture baseline variant.
43 #define __ARM_ARCH_8M_BASE__
46 \def __ARM_ARCH_8M_MAIN__
47 \brief Set to 1 when generating code for ARMv8-M Mainline
49 The <b>\#define __ARM_ARCH_8M_MAIN__</b> is set to 1 when generating code for the ARMv8-M architecture mainline variant.
51 #define __ARM_ARCH_8M_MAIN__
55 /**************************************************************************************************/
58 \brief Pass information from the compiler to the assembler.
60 The \b __ASM keyword can declare or define an embedded assembly function or incorporate inline assembly into a function
61 (shown in the code example below).
65 // Reverse bit order of value
67 __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __RBIT(uint32_t value)
71 __ASM volatile ("rbit %0, %1" : "=r" (result) : "r" (value) );
79 /**************************************************************************************************/
82 \brief Recommend that function should be inlined by the compiler.
84 Inline functions offer a trade-off between code size and performance. By default, the compiler decides during optimization whether to
85 inline code or not. The \b __INLINE attribute gives the compiler an hint to inline this function. Still, the compiler may decide not to inline
86 the function. As the function is global an callable function is also generated.
90 const uint32_t led_mask[] = {1UL << 4, 1UL << 5, 1UL << 6, 1UL << 7};
92 /*------------------------------------------------------------------------------
94 *------------------------------------------------------------------------------*/
95 __INLINE static void LED_On (uint32_t led) {
97 PTD->PCOR = led_mask[led];
104 /**************************************************************************************************/
107 \brief Define a static function should be inlined by the compiler.
109 Defines a static function that may be inlined by the compiler. If the compiler generates inline code for
110 all calls to this functions, no additional function implementation is generated which may further optimize space.
112 <b> Code Example:</b>
114 \\ Get Interrupt Vector
115 __STATIC_INLINE uint32_t NVIC_GetVector(IRQn_Type IRQn)
117 uint32_t *vectors = (uint32_t *)SCB->VTOR;
118 return vectors[(int32_t)IRQn + NVIC_USER_IRQ_OFFSET];
123 #define __STATIC_INLINE
125 /**************************************************************************************************/
128 \brief Inform the compiler that a function does not return.
130 Informs the compiler that the function does not return. The compiler can then perform optimizations by
131 removing code that is never reached.
133 <b> Code Example:</b>
135 // OS idle demon (running when no other thread is ready to run).
137 __NO_RETURN void os_idle_demon (void);
143 /**************************************************************************************************/
146 \brief Inform that a variable shall be retained in executable image.
148 Definitions tagged with \b __USED in the source code should be not removed by the linker when detected as unused.
150 <b> Code Example:</b>
152 /* Export following variables for debugging */
153 __USED uint32_t const CMSIS_RTOS_API_Version = osCMSIS;
154 __USED uint32_t const CMSIS_RTOS_RTX_Version = osCMSIS_RTX;
155 __USED uint32_t const os_clockrate = OS_TICK;
156 __USED uint32_t const os_timernum = 0;
162 /**************************************************************************************************/
165 \brief Export a function or variable weakly to allow overwrites.
167 Functions defined with \b __WEAK export their symbols weakly. A weakly defined function behaves like a normally defined
168 function unless a non-weakly defined function of the same name is linked into the same image. If both a non-weakly defined
169 function and a weakly defined function exist in the same image then all calls to the function resolve to call the non-weak
172 Functions declared with \b __WEAK and then defined without \b __WEAK behave as non-weak functions.
174 <b> Code Example:</b>
176 __WEAK void SystemInit(void)
179 SystemCoreClockSetup();
186 /**************************************************************************************************/
188 \def __UNALIGNED_UINT32
189 \brief Pointer for unaligned access of a uint32_t variable.
191 Defines a pointer to a uint32_t from an address that does not need to be aligned. This can then be used in read/write
192 operations. The compiler will generate the appropriate access (aligned or non-aligned) depending on the underlying ARM
193 processor core and compiler settings.
195 <b> Code Example:</b>
199 void test (uint8_t *ptr) {
200 __UNALIGNED_UINT32(ptr) = val32;
205 #define __UNALIGNED_UINT32
207 /**************************************************************************************************/
210 \brief Minimum alignment for a variable.
212 Specifies a minimum alignment for a variable or structure field, measured in bytes.
214 <b> Code Example:</b>
216 uint32_t stack_space[0x100] __ALIGNED(8); // 8-byte alignment required
222 /**************************************************************************************************/
225 \brief Request smallest possible alignment.
227 Specifies that a type must have the smallest possible alignment.
229 <b> Code Example:</b>
233 uint32_t u32[2] __PACKED;
240 /**************************************************************************************************/
243 \brief Request smallest possible alignment for a structure.
245 Specifies that a structure must have the smallest possible alignment.
247 <b> Code Example:</b>
249 __PACKED_STRUCT foo {
257 #define __PACKED_STRUCT
259 /** @} */ /** end of compiler_conntrol_gr **/