]> begriffs open source - cmsis/blob - CMSIS/DoxyGen/Core/src/Ref_CompilerControl.txt
Updated CMSIS Core documentation.
[cmsis] / CMSIS / DoxyGen / Core / src / Ref_CompilerControl.txt
1 /**************************************************************************************************/\r
2 /**\r
3 \defgroup   compiler_conntrol_gr    Compiler Control\r
4 \brief      Compiler specific \#defines in CMSIS-Core\r
5 \details\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
8 @{\r
9 */\r
10 \r
11 /**************************************************************************************************/\r
12 /**\r
13 \def __ASM\r
14 \brief Keyword passing information from the compiler to the assembler.\r
15 \details\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
18  \r
19 <b>Code Example:</b>\r
20 \code\r
21 // Reverse bit order of value\r
22  \r
23 __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __RBIT(uint32_t value)\r
24 {\r
25   uint32_t result;\r
26  \r
27    __ASM volatile ("rbit %0, %1" : "=r" (result) : "r" (value) );\r
28    return(result);\r
29 }\r
30 \endcode\r
31 \r
32 */\r
33 #define __ASM\r
34 \r
35 /**************************************************************************************************/\r
36 /**\r
37 \def __INLINE\r
38 \brief Keyword suggesting to the compiler that it compiles a C or C++ function inline.\r
39 \details\r
40 Inline functions offer a trade-off between code size and performance. By default, the compiler decides for itself whether to\r
41 inline code or not.\r
42 \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
45 the function.\r
46 \r
47 <b> Code Example:</b>\r
48 \code\r
49 const uint32_t led_mask[] = {1UL << 4, 1UL << 5, 1UL << 6, 1UL << 7};\r
50  \r
51 /*------------------------------------------------------------------------------\r
52   Switch on LEDs\r
53  *------------------------------------------------------------------------------*/\r
54 __INLINE static void LED_On (uint32_t led) {\r
55  \r
56   PTD->PCOR   = led_mask[led];\r
57 }\r
58 \endcode\r
59 \r
60 */\r
61 #define __INLINE\r
62 \r
63 /**************************************************************************************************/\r
64 /**\r
65 \def __STATIC_INLINE\r
66 \brief Keyword suggesting to the compiler that it compiles a C or C++ function statically inline.\r
67 \details\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
71 \r
72 <b> Code Example:</b>\r
73 \code\r
74 // Set Priority Grouping\r
75  \r
76 __STATIC_INLINE void NVIC_SetPriorityGrouping(uint32_t PriorityGroup)\r
77 {\r
78   uint32_t reg_value;\r
79   uint32_t PriorityGroupTmp = (PriorityGroup & (uint32_t)0x07);               /* only values 0..7 are used          */\r
80  \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
87 }\r
88 \endcode\r
89 \r
90 */\r
91 #define __STATIC_INLINE\r
92 \r
93 /**************************************************************************************************/\r
94 /**\r
95 \def __NO_RETURN\r
96 \brief Informs the compiler that the function does not return.\r
97 \details\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
100  \r
101 <b> Code Example:</b>\r
102 \code\r
103 // OS idle demon (running when no other thread is ready to run).\r
104  \r
105 __NO_RETURN void os_idle_demon (void);\r
106 \endcode\r
107 \r
108 */\r
109 #define __NO_RETURN\r
110 \r
111 /**************************************************************************************************/\r
112 /**\r
113 \def __USED\r
114 \brief Informs the compiler that a static variable is to be retained in the object file.\r
115 \details\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
118  \r
119 <b> Code Example:</b>\r
120 \code\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
126 \endcode\r
127 \r
128 */\r
129 #define __USED\r
130 \r
131 /**************************************************************************************************/\r
132 /**\r
133 \def __WEAK\r
134 \brief Keyword instructing the compiler to export a function or variable weakly.\r
135 \details\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
139 function.\r
140 \r
141 Functions declared with \b __WEAK and then defined without \b __WEAK behave as non-weak functions.\r
142  \r
143 <b> Code Example:</b>\r
144 \code\r
145 __WEAK void SystemInit(void)\r
146 {\r
147   SystemCoreSetup();\r
148   SystemCoreClockSetup(); \r
149 }\r
150 \endcode\r
151 \r
152 */\r
153 #define __WEAK\r
154 \r
155 /**************************************************************************************************/\r
156 /**\r
157 \def __UNALIGNED_UINT32\r
158 \brief Pointer to unaligned uint32_t variable.\r
159 \details\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
163  \r
164 <b> Code Example:</b>\r
165 \code\r
166 uint32_t val32;\r
167  \r
168 void test (uint8_t *ptr) {\r
169   __UNALIGNED_UINT32(ptr) = val32;\r
170 }\r
171 \endcode\r
172 \r
173 */\r
174 #define __UNALIGNED_UINT32\r
175 \r
176 /**************************************************************************************************/\r
177 /**\r
178 \def __ALIGNED\r
179 \brief Alignment of a variable.\r
180 \details\r
181 Specifies a minimum alignment for a variable or structure field, measured in bytes.\r
182  \r
183 <b> Code Example:</b>\r
184 \code\r
185 uint32_t val32 __ALIGNED(4);\r
186 \endcode\r
187 \r
188 */\r
189 #define __ALIGNED\r
190 \r
191 /** @} */ /** end of compiler_conntrol_gr **/