EFM32 Pearl Gecko Software Documentation  efm32pg1-doc-4.2.1
em_common.h
Go to the documentation of this file.
1 /***************************************************************************/
33 #ifndef __SILICON_LABS_EM_COMMON_H__
34 #define __SILICON_LABS_EM_COMMON_H__
35 
36 #include "em_device.h"
37 #include <stdbool.h>
38 
39 #ifdef __cplusplus
40 extern "C" {
41 #endif
42 
43 /***************************************************************************/
48 /***************************************************************************/
54 #if !defined(__GNUC__)
55 
57 #define EFM32_MIN(a, b) ((a) < (b) ? (a) : (b))
58 
59 #define EFM32_MAX(a, b) ((a) > (b) ? (a) : (b))
60 
62 #define STRINGIZE(X) #X
63 #define EFM32_PACK_START(X) _Pragma( STRINGIZE( pack( X ) ) )
64 #define EFM32_PACK_END() _Pragma( "pack()" )
65 #define __attribute__(...)
66 
67 #ifdef __CC_ARM
68 
69 #define EFM32_ALIGN(X) __align(X)
70 #endif
71 #ifdef __ICCARM__
72 
73 #define EFM32_ALIGN(X) _Pragma( STRINGIZE( data_alignment=X ) )
74 #endif
75 
76 #else // !defined(__GNUC__)
77 
79 #define EFM32_MIN(a, b) ({ __typeof__(a) _a = (a); __typeof__(b) _b = (b); _a < _b ? _a : _b; })
80 
81 #define EFM32_MAX(a, b) ({ __typeof__(a) _a = (a); __typeof__(b) _b = (b); _a > _b ? _a : _b; })
82 
88 #define EFM32_PACK_START( x )
89 
95 #define EFM32_PACK_END()
96 
103 #define EFM32_ALIGN(X)
104 
105 #endif // !defined(__GNUC__)
106 
107 /***************************************************************************/
121 __STATIC_INLINE uint32_t EFM32_CTZ(uint32_t value)
122 {
123 #if (__CORTEX_M >= 3)
124  return __CLZ(__RBIT(value));
125 
126 #else
127  uint32_t zeros;
128  for(zeros=0; (zeros<32) && ((value&0x1) == 0); zeros++, value>>=1);
129  return zeros;
130 #endif
131 }
132 
136 #ifdef __cplusplus
137 }
138 #endif
139 
140 #endif /* __SILICON_LABS_EM_COMMON_H__ */
CMSIS Cortex-M Peripheral Access Layer for Silicon Laboratories microcontroller devices.
__STATIC_INLINE uint32_t EFM32_CTZ(uint32_t value)
Count trailing number of zero's.
Definition: em_common.h:121