efm32_common.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /***************************************************************************//**
  2. * @file
  3. * @brief EFM32 general purpose utilities.
  4. * @author Energy Micro AS
  5. * @version 2.3.2
  6. *******************************************************************************
  7. * @section License
  8. * <b>(C) Copyright 2011 Energy Micro AS, http://www.energymicro.com</b>
  9. *******************************************************************************
  10. *
  11. * This source code is the property of Energy Micro AS. The source and compiled
  12. * code may only be used on Energy Micro "EFM32" microcontrollers.
  13. *
  14. * This copyright notice may not be removed from the source code nor changed.
  15. *
  16. * DISCLAIMER OF WARRANTY/LIMITATION OF REMEDIES: Energy Micro AS has no
  17. * obligation to support this Software. Energy Micro AS is providing the
  18. * Software "AS IS", with no express or implied warranties of any kind,
  19. * including, but not limited to, any implied warranties of merchantability
  20. * or fitness for any particular purpose or warranties against infringement
  21. * of any proprietary rights of a third party.
  22. *
  23. * Energy Micro AS will not be liable for any consequential, incidental, or
  24. * special damages, or any other relief, or for any claim by any third party,
  25. * arising from your use of this Software.
  26. *
  27. ******************************************************************************/
  28. #ifndef __EFM32_COMMON_H
  29. #define __EFM32_COMMON_H
  30. #include <stdint.h>
  31. #include <stdbool.h>
  32. #ifdef __cplusplus
  33. extern "C" {
  34. #endif
  35. /***************************************************************************//**
  36. * @addtogroup EFM32_Library
  37. * @{
  38. ******************************************************************************/
  39. /***************************************************************************//**
  40. * @addtogroup COMMON
  41. * @brief EFM32 general purpose utilities.
  42. * @{
  43. ******************************************************************************/
  44. #if !defined(__GNUC__)
  45. /** Macro for getting minimum value. */
  46. #define EFM32_MIN(a, b) ((a) < (b) ? (a) : (b))
  47. /** Macro for getting maximum value. */
  48. #define EFM32_MAX(a, b) ((a) > (b) ? (a) : (b))
  49. /** Macros for handling packed structs. */
  50. #define STRINGIZE(X) #X
  51. #define EFM32_PACK_START(X) _Pragma( STRINGIZE( pack( ##X## ) ) )
  52. #define EFM32_PACK_END() _Pragma( "pack()" )
  53. #define __attribute__(...)
  54. /** Macros for handling aligned structs. */
  55. #ifdef __CC_ARM
  56. #define EFM32_ALIGN(X) __align(X)
  57. #endif
  58. #ifdef __ICCARM__
  59. #define EFM32_ALIGN(X) _Pragma( STRINGIZE( data_alignment=##X## ) )
  60. #endif
  61. #else
  62. /** Macro for getting minimum value. No sideeffects, a and b are evaluated once only. */
  63. #define EFM32_MIN(a, b) ({ __typeof__(a) _a = (a); __typeof__(b) _b = (b); _a < _b ? _a : _b; })
  64. /** Macro for getting maximum value. No sideeffects, a and b are evaluated once only. */
  65. #define EFM32_MAX(a, b) ({ __typeof__(a) _a = (a); __typeof__(b) _b = (b); _a > _b ? _a : _b; })
  66. /** Macro for handling packed structs.
  67. * @n Use this macro before the struct definition.
  68. * @n X denotes the maximum alignment of struct members. X is not supported on
  69. * gcc, gcc always use 1 byte maximum alignment.
  70. */
  71. #define EFM32_PACK_START( x )
  72. /** Macro for handling packed structs.
  73. * @n Use this macro after the struct definition.
  74. * @n On gcc add __attribute__ ((packed)) after the closing } of the struct
  75. * definition.
  76. */
  77. #define EFM32_PACK_END()
  78. /** Macro for aligning a variable.
  79. * @n Use this macro before the variable definition.
  80. * @n X denotes the storage alignment value in bytes.
  81. * @n On gcc use __attribute__ ((aligned(X))) before the ; on normal variables.
  82. * Use __attribute__ ((aligned(X))) before the opening { on struct variables.
  83. */
  84. #define EFM32_ALIGN(X)
  85. #endif
  86. /** @} (end addtogroup COMMON) */
  87. /** @} (end addtogroup EFM32_Library) */
  88. #ifdef __cplusplus
  89. }
  90. #endif
  91. #endif /* __EFM32_COMMON_H */