1 /**************************************************************************************************/
\r
3 \defgroup compiler_conntrol_gr Compiler Control
\r
4 \brief Compiler specific \#defines in CMSIS-Core
\r
6 CMSIS-Core provides a set of compiler control \#defines that produce a consistent behavior, no matter which compiler is used
\r
7 to build the application code.
\r
11 /**************************************************************************************************/
\r
14 \brief Keyword passing information from the compiler to the assembler.
\r
16 The \b __ASM keyword can declare or define an embedded assembly function or incorporate inline assembly into a function
\r
17 (shown in the code example below).
\r
19 <b>Code Example:</b>
\r
21 // Reverse bit order of value
\r
23 __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __RBIT(uint32_t value)
\r
27 __ASM volatile ("rbit %0, %1" : "=r" (result) : "r" (value) );
\r
35 /**************************************************************************************************/
\r
38 \brief Keyword suggesting to the compiler that it compiles a C or C++ function inline.
\r
40 Inline functions offer a trade-off between code size and performance. By default, the compiler decides for itself whether to
\r
43 In most circumstances, the decision to inline a particular function is best left to the compiler. However, you can give the
\r
44 compiler a hint that a function is required to be inlined by using \b __INLINE. Still, the compiler can decide not to inline
\r
47 <b> Code Example:</b>
\r
49 const uint32_t led_mask[] = {1UL << 4, 1UL << 5, 1UL << 6, 1UL << 7};
\r
51 /*------------------------------------------------------------------------------
\r
53 *------------------------------------------------------------------------------*/
\r
54 __INLINE static void LED_On (uint32_t led) {
\r
56 PTD->PCOR = led_mask[led];
\r
63 /**************************************************************************************************/
\r
65 \def __STATIC_INLINE
\r
66 \brief Keyword suggesting to the compiler that it compiles a C or C++ function statically inline.
\r
68 As for \ref __INLINE, the compiler may choose to inline the function. In addition, the compiler will add a locally scoped
\r
69 version of the function in the resulting object file. As you can have one static version of the function per object file, you
\r
70 may end up with multiple definitions of the same function. This will require more space.
\r
72 <b> Code Example:</b>
\r
74 // Set Priority Grouping
\r
76 __STATIC_INLINE void NVIC_SetPriorityGrouping(uint32_t PriorityGroup)
\r
79 uint32_t PriorityGroupTmp = (PriorityGroup & (uint32_t)0x07); /* only values 0..7 are used */
\r
81 reg_value = SCB->AIRCR; /* read old register configuration */
\r
82 reg_value &= ~(SCB_AIRCR_VECTKEY_Msk | SCB_AIRCR_PRIGROUP_Msk); /* clear bits to change */
\r
83 reg_value = (reg_value |
\r
84 ((uint32_t)0x5FA << SCB_AIRCR_VECTKEY_Pos) |
\r
85 (PriorityGroupTmp << 8)); /* Insert write key and priority group */
\r
86 SCB->AIRCR = reg_value;
\r
91 #define __STATIC_INLINE
\r
93 /**************************************************************************************************/
\r
96 \brief Informs the compiler that the function does not return.
\r
98 The compiler can perform optimizations by removing code that is never reached. If the function reaches an explicit or
\r
99 implicit return, \b __NO_RETURN is ignored and the compiler generates a warning.
\r
101 <b> Code Example:</b>
\r
103 // OS idle demon (running when no other thread is ready to run).
\r
105 __NO_RETURN void os_idle_demon (void);
\r
109 #define __NO_RETURN
\r
111 /**************************************************************************************************/
\r
114 \brief Informs the compiler that a static variable is to be retained in the object file.
\r
116 Data marked with \b __USED is tagged in the object file to avoid removal by linker unused section removal. Static variables
\r
117 marked as used are emitted to a single section, in the order they are declared.
\r
119 <b> Code Example:</b>
\r
121 /* Export following defines to debugger. */
\r
122 __USED uint32_t const CMSIS_RTOS_API_Version = osCMSIS;
\r
123 __USED uint32_t const CMSIS_RTOS_RTX_Version = osCMSIS_RTX;
\r
124 __USED uint32_t const os_clockrate = OS_TICK;
\r
125 __USED uint32_t const os_timernum = 0;
\r
131 /**************************************************************************************************/
\r
134 \brief Keyword instructing the compiler to export a function or variable weakly.
\r
136 Functions defined with \b __WEAK export their symbols weakly. A weakly defined function behaves like a normally defined
\r
137 function unless a non-weakly defined function of the same name is linked into the same image. If both a non-weakly defined
\r
138 function and a weakly defined function exist in the same image then all calls to the function resolve to call the non-weak
\r
141 Functions declared with \b __WEAK and then defined without \b __WEAK behave as non-weak functions.
\r
143 <b> Code Example:</b>
\r
145 __WEAK void SystemInit(void)
\r
148 SystemCoreClockSetup();
\r
155 /**************************************************************************************************/
\r
157 \def __UNALIGNED_UINT32
\r
158 \brief Pointer to unaligned uint32_t variable.
\r
160 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
\r
161 operations. The compiler will generate the appropriate access (aligned or non-aligned) depending on the underlying ARM
\r
162 processor core and compiler settings.
\r
164 <b> Code Example:</b>
\r
168 void test (uint8_t *ptr) {
\r
169 __UNALIGNED_UINT32(ptr) = val32;
\r
174 #define __UNALIGNED_UINT32
\r
176 /**************************************************************************************************/
\r
179 \brief Alignment of a variable.
\r
181 Specifies a minimum alignment for a variable or structure field, measured in bytes.
\r
183 <b> Code Example:</b>
\r
185 uint32_t val32 __ALIGNED(4);
\r
191 /** @} */ /** end of compiler_conntrol_gr **/