EFR32 Blue Gecko 1 Software Documentation  efr32bg1-doc-5.1.2
em_common.h
Go to the documentation of this file.
1 /***************************************************************************/
32 #ifndef EM_COMMON_H
33 #define EM_COMMON_H
34 
35 #include "em_device.h"
36 #include <stdbool.h>
37 
38 #ifdef __cplusplus
39 extern "C" {
40 #endif
41 
42 /***************************************************************************/
65 /***************************************************************************/
88 #if !defined(__GNUC__)
89 /* Not GCC compilers */
90 
92 #define SL_MIN(a, b) ((a) < (b) ? (a) : (b))
93 
95 #define SL_MAX(a, b) ((a) > (b) ? (a) : (b))
96 
98 #define STRINGIZE(X) #X
99 #define SL_PACK_START(X) _Pragma(STRINGIZE(pack(X)))
100 #define SL_PACK_END() _Pragma("pack()")
101 #define SL_ATTRIBUTE_PACKED
102 
103 #if defined(__CC_ARM)
104 
105 #define SL_ALIGN(X) __align(X)
106 
108 #define SL_WEAK __attribute__ ((weak))
109 
111 #define SL_NORETURN __attribute__ ((noreturn))
112 
114 #define SL_ATTRIBUTE_SECTION(X) __attribute__ ((section(X)))
115 #endif
116 
117 #if defined(__ICCARM__)
118 
119 #define SL_ALIGN(X) _Pragma(STRINGIZE(data_alignment=X))
120 
122 #define SL_WEAK __weak
123 
125 #define SL_NORETURN __noreturn
126 
128 #define SL_ATTRIBUTE_SECTION(X) @ X
129 #endif
130 
131 #define SL_ATTRIBUTE_ALIGN(X)
132 
133 #else // !defined(__GNUC__)
134 /* GCC compilers */
135 
137 #define SL_MIN(a, b) __extension__({__typeof__(a) _a = (a); __typeof__(b) _b = (b); _a < _b ? _a : _b;})
138 
140 #define SL_MAX(a, b) __extension__({__typeof__(a) _a = (a); __typeof__(b) _b = (b); _a > _b ? _a : _b;})
141 
143 #define SL_ATTRIBUTE_PACKED __attribute__ ((packed))
144 
150 #define SL_PACK_START(x)
151 
157 #define SL_PACK_END()
158 
160 #define SL_ATTRIBUTE_ALIGN(X) __attribute__ ((aligned(X)))
161 
168 #define SL_ALIGN(X)
169 
171 #define SL_WEAK __attribute__ ((weak))
172 
174 #define SL_NORETURN __attribute__ ((noreturn))
175 
180 #define SL_ATTRIBUTE_SECTION(X) __attribute__ ((section(X)))
181 
182 #endif // !defined(__GNUC__)
183 
184 /***************************************************************************/
194 __STATIC_INLINE uint32_t SL_CTZ(uint32_t value)
195 {
196 #if (__CORTEX_M >= 3)
197  return __CLZ(__RBIT(value));
198 
199 #else
200  uint32_t zeros;
201  for(zeros=0; (zeros<32) && ((value&0x1) == 0); zeros++, value>>=1);
202  return zeros;
203 #endif
204 }
205 
206 
207 /* Deprecated function. New code should use @ref SL_CTZ. */
208 __STATIC_INLINE uint32_t EFM32_CTZ(uint32_t value)
209 {
210  return SL_CTZ(value);
211 }
212 
213 
217 #ifdef __cplusplus
218 }
219 #endif
220 
221 #endif /* EM_COMMON_H */
CMSIS Cortex-M Peripheral Access Layer for Silicon Laboratories microcontroller devices.
__STATIC_INLINE uint32_t SL_CTZ(uint32_t value)
Count trailing number of zeros. Use CLZ instruction if available.
Definition: em_common.h:194