1 /***************************************************************************//** 2 * @file 3 * @brief EFM32 general purpose utilities. 4 * @author Energy Micro AS 5 * @version 3.0.0 6 ******************************************************************************* 7 * @section License 8 * <b>(C) Copyright 2012 Energy Micro AS, http://www.energymicro.com</b> 9 ******************************************************************************* 10 * 11 * Permission is granted to anyone to use this software for any purpose, 12 * including commercial applications, and to alter it and redistribute it 13 * freely, subject to the following restrictions: 14 * 15 * 1. The origin of this software must not be misrepresented; you must not 16 * claim that you wrote the original software. 17 * 2. Altered source versions must be plainly marked as such, and must not be 18 * misrepresented as being the original software. 19 * 3. This notice may not be removed or altered from any source distribution. 20 * 21 * DISCLAIMER OF WARRANTY/LIMITATION OF REMEDIES: Energy Micro AS has no 22 * obligation to support this Software. Energy Micro AS is providing the 23 * Software "AS IS", with no express or implied warranties of any kind, 24 * including, but not limited to, any implied warranties of merchantability 25 * or fitness for any particular purpose or warranties against infringement 26 * of any proprietary rights of a third party. 27 * 28 * Energy Micro AS will not be liable for any consequential, incidental, or 29 * special damages, or any other relief, or for any claim by any third party, 30 * arising from your use of this Software. 31 * 32 ******************************************************************************/ 33 #ifndef __EM_COMMON_H 34 #define __EM_COMMON_H 35 36 #include <stdint.h> 37 #include <stdbool.h> 38 39 40 #ifdef __cplusplus 41 extern "C" { 42 #endif 43 44 /***************************************************************************//** 45 * @addtogroup EM_Library 46 * @{ 47 ******************************************************************************/ 48 49 /***************************************************************************//** 50 * @addtogroup COMMON 51 * @brief EFM32 general purpose utilities. 52 * @{ 53 ******************************************************************************/ 54 55 #if !defined(__GNUC__) 56 57 /** Macro for getting minimum value. */ 58 #define EFM32_MIN(a, b) ((a) < (b) ? (a) : (b)) 59 /** Macro for getting maximum value. */ 60 #define EFM32_MAX(a, b) ((a) > (b) ? (a) : (b)) 61 62 /** Macros for handling packed structs. */ 63 #define STRINGIZE(X) #X 64 #define EFM32_PACK_START(X) _Pragma( STRINGIZE( pack( ##X## ) ) ) 65 #define EFM32_PACK_END() _Pragma( "pack()" ) 66 #define __attribute__(...) 67 68 /** Macros for handling aligned structs. */ 69 #ifdef __CC_ARM 70 #define EFM32_ALIGN(X) __align(X) 71 #endif 72 #ifdef __ICCARM__ 73 #define EFM32_ALIGN(X) _Pragma( STRINGIZE( data_alignment=##X## ) ) 74 #endif 75 76 #else 77 78 /** Macro for getting minimum value. No sideeffects, a and b are evaluated once only. */ 79 #define EFM32_MIN(a, b) ({ __typeof__(a) _a = (a); __typeof__(b) _b = (b); _a < _b ? _a : _b; }) 80 /** Macro for getting maximum value. No sideeffects, a and b are evaluated once only. */ 81 #define EFM32_MAX(a, b) ({ __typeof__(a) _a = (a); __typeof__(b) _b = (b); _a > _b ? _a : _b; }) 82 83 /** Macro for handling packed structs. 84 * @n Use this macro before the struct definition. 85 * @n X denotes the maximum alignment of struct members. X is not supported on 86 * gcc, gcc always use 1 byte maximum alignment. 87 */ 88 #define EFM32_PACK_START( x ) 89 90 /** Macro for handling packed structs. 91 * @n Use this macro after the struct definition. 92 * @n On gcc add __attribute__ ((packed)) after the closing } of the struct 93 * definition. 94 */ 95 #define EFM32_PACK_END() 96 97 /** Macro for aligning a variable. 98 * @n Use this macro before the variable definition. 99 * @n X denotes the storage alignment value in bytes. 100 * @n On gcc use __attribute__ ((aligned(X))) before the ; on normal variables. 101 * Use __attribute__ ((aligned(X))) before the opening { on struct variables. 102 */ 103 #define EFM32_ALIGN(X) 104 105 #endif 106 107 /** @} (end addtogroup COMMON) */ 108 /** @} (end addtogroup EM_Library) */ 109 110 #ifdef __cplusplus 111 } 112 #endif 113 114 #endif /* __EM_COMMON_H */ 115