1
0

em_common.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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. #include <stdint.h>
  36. #include <stdbool.h>
  37. #ifdef __cplusplus
  38. extern "C" {
  39. #endif
  40. /***************************************************************************//**
  41. * @addtogroup EM_Library
  42. * @{
  43. ******************************************************************************/
  44. /***************************************************************************//**
  45. * @addtogroup COMMON
  46. * @brief EFM32 general purpose utilities.
  47. * @{
  48. ******************************************************************************/
  49. #if !defined(__GNUC__)
  50. /** Macro for getting minimum value. */
  51. #define EFM32_MIN(a, b) ((a) < (b) ? (a) : (b))
  52. /** Macro for getting maximum value. */
  53. #define EFM32_MAX(a, b) ((a) > (b) ? (a) : (b))
  54. /** Macros for handling packed structs. */
  55. #define STRINGIZE(X) #X
  56. #define EFM32_PACK_START(X) _Pragma( STRINGIZE( pack( ##X## ) ) )
  57. #define EFM32_PACK_END() _Pragma( "pack()" )
  58. #define __attribute__(...)
  59. /** Macros for handling aligned structs. */
  60. #ifdef __CC_ARM
  61. #define EFM32_ALIGN(X) __align(X)
  62. #endif
  63. #ifdef __ICCARM__
  64. #define EFM32_ALIGN(X) _Pragma( STRINGIZE( data_alignment=##X## ) )
  65. #endif
  66. #else
  67. /** Macro for getting minimum value. No sideeffects, a and b are evaluated once only. */
  68. #define EFM32_MIN(a, b) ({ __typeof__(a) _a = (a); __typeof__(b) _b = (b); _a < _b ? _a : _b; })
  69. /** Macro for getting maximum value. No sideeffects, a and b are evaluated once only. */
  70. #define EFM32_MAX(a, b) ({ __typeof__(a) _a = (a); __typeof__(b) _b = (b); _a > _b ? _a : _b; })
  71. /** Macro for handling packed structs.
  72. * @n Use this macro before the struct definition.
  73. * @n X denotes the maximum alignment of struct members. X is not supported on
  74. * gcc, gcc always use 1 byte maximum alignment.
  75. */
  76. #define EFM32_PACK_START( x )
  77. /** Macro for handling packed structs.
  78. * @n Use this macro after the struct definition.
  79. * @n On gcc add __attribute__ ((packed)) after the closing } of the struct
  80. * definition.
  81. */
  82. #define EFM32_PACK_END()
  83. /** Macro for aligning a variable.
  84. * @n Use this macro before the variable definition.
  85. * @n X denotes the storage alignment value in bytes.
  86. * @n On gcc use __attribute__ ((aligned(X))) before the ; on normal variables.
  87. * Use __attribute__ ((aligned(X))) before the opening { on struct variables.
  88. */
  89. #define EFM32_ALIGN(X)
  90. #endif
  91. /** @} (end addtogroup COMMON) */
  92. /** @} (end addtogroup EM_Library) */
  93. #ifdef __cplusplus
  94. }
  95. #endif
  96. #endif /* __EM_COMMON_H */