1 /***************************************************************************//**
\r
3 * @brief EFM32 general purpose utilities.
\r
5 *******************************************************************************
\r
7 * <b>(C) Copyright 2014 Silicon Labs, http://www.silabs.com</b>
\r
8 *******************************************************************************
\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
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
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
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
31 ******************************************************************************/
\r
34 #ifndef __SILICON_LABS_EM_COMMON_H_
\r
35 #define __SILICON_LABS_EM_COMMON_H_
\r
38 #include <stdbool.h>
\r
45 /***************************************************************************//**
\r
46 * @addtogroup EM_Library
\r
48 ******************************************************************************/
\r
50 /***************************************************************************//**
\r
51 * @addtogroup COMMON
\r
52 * @brief EFM32 general purpose utilities.
\r
54 ******************************************************************************/
\r
56 #if !defined(__GNUC__)
\r
58 /** Macro for getting minimum value. */
\r
59 #define EFM32_MIN(a, b) ((a) < (b) ? (a) : (b))
\r
60 /** Macro for getting maximum value. */
\r
61 #define EFM32_MAX(a, b) ((a) > (b) ? (a) : (b))
\r
63 /** Macros for handling packed structs. */
\r
64 #define STRINGIZE(X) #X
\r
65 #define EFM32_PACK_START(X) _Pragma( STRINGIZE( pack( X ) ) )
\r
66 #define EFM32_PACK_END() _Pragma( "pack()" )
\r
67 #define __attribute__(...)
\r
70 /** Macros for handling aligned structs. */
\r
71 #define EFM32_ALIGN(X) __align(X)
\r
74 /** Macros for handling aligned structs. */
\r
75 #define EFM32_ALIGN(X) _Pragma( STRINGIZE( data_alignment=X ) )
\r
80 /** Macro for getting minimum value. No sideeffects, a and b are evaluated once only. */
\r
81 #define EFM32_MIN(a, b) ({ __typeof__(a) _a = (a); __typeof__(b) _b = (b); _a < _b ? _a : _b; })
\r
82 /** Macro for getting maximum value. No sideeffects, a and b are evaluated once only. */
\r
83 #define EFM32_MAX(a, b) ({ __typeof__(a) _a = (a); __typeof__(b) _b = (b); _a > _b ? _a : _b; })
\r
85 /** Macro for handling packed structs.
\r
86 * @n Use this macro before the struct definition.
\r
87 * @n X denotes the maximum alignment of struct members. X is not supported on
\r
88 * gcc, gcc always use 1 byte maximum alignment.
\r
90 #define EFM32_PACK_START( x )
\r
92 /** Macro for handling packed structs.
\r
93 * @n Use this macro after the struct definition.
\r
94 * @n On gcc add __attribute__ ((packed)) after the closing } of the struct
\r
97 #define EFM32_PACK_END()
\r
99 /** Macro for aligning a variable.
\r
100 * @n Use this macro before the variable definition.
\r
101 * @n X denotes the storage alignment value in bytes.
\r
102 * @n On gcc use __attribute__ ((aligned(X))) before the ; on normal variables.
\r
103 * Use __attribute__ ((aligned(X))) before the opening { on struct variables.
\r
105 #define EFM32_ALIGN(X)
\r
109 /** @} (end addtogroup COMMON) */
\r
110 /** @} (end addtogroup EM_Library) */
\r
116 #endif /* __SILICON_LABS_EM_COMMON_H_ */
\r