]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_EFM32_Gecko_Starter_Kit_Simplicity_Studio/Source/SilLabs_Code/emlib/inc/em_common.h
e2e9fe6f32d36c3636c0868baab1c026f35e2afc
[freertos] / FreeRTOS / Demo / CORTEX_EFM32_Gecko_Starter_Kit_Simplicity_Studio / Source / SilLabs_Code / emlib / inc / em_common.h
1 /***************************************************************************//**\r
2  * @file em_common.h\r
3  * @brief Emlib general purpose utilities.\r
4  * @version 4.2.1\r
5  *******************************************************************************\r
6  * @section License\r
7  * <b>(C) Copyright 2015 Silicon Labs, http://www.silabs.com</b>\r
8  *******************************************************************************\r
9  *\r
10  * Permission is granted to anyone to use this software for any purpose,\r
11  * including commercial applications, and to alter it and redistribute it\r
12  * freely, subject to the following restrictions:\r
13  *\r
14  * 1. The origin of this software must not be misrepresented; you must not\r
15  *    claim that you wrote the original software.\r
16  * 2. Altered source versions must be plainly marked as such, and must not be\r
17  *    misrepresented as being the original software.\r
18  * 3. This notice may not be removed or altered from any source distribution.\r
19  *\r
20  * DISCLAIMER OF WARRANTY/LIMITATION OF REMEDIES: Silicon Labs has no\r
21  * obligation to support this Software. Silicon Labs is providing the\r
22  * Software "AS IS", with no express or implied warranties of any kind,\r
23  * including, but not limited to, any implied warranties of merchantability\r
24  * or fitness for any particular purpose or warranties against infringement\r
25  * of any proprietary rights of a third party.\r
26  *\r
27  * Silicon Labs will not be liable for any consequential, incidental, or\r
28  * special damages, or any other relief, or for any claim by any third party,\r
29  * arising from your use of this Software.\r
30  *\r
31  ******************************************************************************/\r
32 \r
33 #ifndef __SILICON_LABS_EM_COMMON_H__\r
34 #define __SILICON_LABS_EM_COMMON_H__\r
35 \r
36 #include "em_device.h"\r
37 #include <stdbool.h>\r
38 \r
39 #ifdef __cplusplus\r
40 extern "C" {\r
41 #endif\r
42 \r
43 /***************************************************************************//**\r
44  * @addtogroup EM_Library\r
45  * @{\r
46  ******************************************************************************/\r
47 \r
48 /***************************************************************************//**\r
49  * @addtogroup COMMON\r
50  * @brief Emlib general purpose utilities.\r
51  * @{\r
52  ******************************************************************************/\r
53 \r
54 #if !defined(__GNUC__)\r
55 \r
56 /** Macro for getting minimum value. */\r
57 #define EFM32_MIN(a, b)    ((a) < (b) ? (a) : (b))\r
58 /** Macro for getting maximum value. */\r
59 #define EFM32_MAX(a, b)    ((a) > (b) ? (a) : (b))\r
60 \r
61 /** Macros for handling packed structs. */\r
62 #define STRINGIZE(X) #X\r
63 #define EFM32_PACK_START(X) _Pragma( STRINGIZE( pack( X ) ) )\r
64 #define EFM32_PACK_END()    _Pragma( "pack()" )\r
65 #define __attribute__(...)\r
66 \r
67 #ifdef __CC_ARM\r
68 /** Macros for handling aligned structs. */\r
69 #define EFM32_ALIGN(X) __align(X)\r
70 #endif\r
71 #ifdef __ICCARM__\r
72 /** Macros for handling aligned structs. */\r
73 #define EFM32_ALIGN(X) _Pragma( STRINGIZE( data_alignment=X ) )\r
74 #endif\r
75 \r
76 #else // !defined(__GNUC__)\r
77 \r
78 /** Macro for getting minimum value. No sideeffects, a and b are evaluated once only. */\r
79 #define EFM32_MIN(a, b)    ({ __typeof__(a) _a = (a); __typeof__(b) _b = (b); _a < _b ? _a : _b; })\r
80 /** Macro for getting maximum value. No sideeffects, a and b are evaluated once only. */\r
81 #define EFM32_MAX(a, b)    ({ __typeof__(a) _a = (a); __typeof__(b) _b = (b); _a > _b ? _a : _b; })\r
82 \r
83 /** Macro for handling packed structs.\r
84  *  @n Use this macro before the struct definition.\r
85  *  @n X denotes the maximum alignment of struct members. X is not supported on\r
86  *  gcc, gcc always use 1 byte maximum alignment.\r
87  */\r
88 #define EFM32_PACK_START( x )\r
89 \r
90 /** Macro for handling packed structs.\r
91  *  @n Use this macro after the struct definition.\r
92  *  @n On gcc add __attribute__ ((packed)) after the closing } of the struct\r
93  *  definition.\r
94  */\r
95 #define EFM32_PACK_END()\r
96 \r
97 /** Macro for aligning a variable.\r
98  *  @n Use this macro before the variable definition.\r
99  *  @n X denotes the storage alignment value in bytes.\r
100  *  @n On gcc use __attribute__ ((aligned(X))) before the ; on normal variables.\r
101  *  Use __attribute__ ((aligned(X))) before the opening { on struct variables.\r
102  */\r
103 #define EFM32_ALIGN(X)\r
104 \r
105 #endif // !defined(__GNUC__)\r
106 \r
107 /***************************************************************************//**\r
108  * @brief\r
109  *   Count trailing number of zero's.\r
110  *\r
111  * @note\r
112  *   Disabling SWDClk will disable the debug interface, which may result in\r
113  *   a lockout if done early in startup (before debugger is able to halt core).\r
114  *\r
115  * @param[in] value\r
116  *   Data value to check for number of trailing zero bits.\r
117  *\r
118  * @return\r
119  *   Number of trailing zero's in value.\r
120  ******************************************************************************/\r
121 __STATIC_INLINE uint32_t EFM32_CTZ(uint32_t value)\r
122 {\r
123 #if (__CORTEX_M >= 3)\r
124   return __CLZ(__RBIT(value));\r
125 \r
126 #else\r
127   uint32_t zeros;\r
128   for(zeros=0; (zeros<32) && ((value&0x1) == 0); zeros++, value>>=1);\r
129   return zeros;\r
130 #endif\r
131 }\r
132 \r
133 /** @} (end addtogroup COMMON) */\r
134 /** @} (end addtogroup EM_Library) */\r
135 \r
136 #ifdef __cplusplus\r
137 }\r
138 #endif\r
139 \r
140 #endif /* __SILICON_LABS_EM_COMMON_H__ */\r