stm32_wpan_common.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. /**
  2. ******************************************************************************
  3. * @file stm32_wpan_common.h
  4. * @author MCD Application Team
  5. * @brief Common file to utilities
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * Copyright (c) 2018-2021 STMicroelectronics.
  10. * All rights reserved.
  11. *
  12. * This software is licensed under terms that can be found in the LICENSE file
  13. * in the root directory of this software component.
  14. * If no LICENSE file comes with this software, it is provided AS-IS.
  15. *
  16. ******************************************************************************
  17. */
  18. /* Define to prevent recursive inclusion -------------------------------------*/
  19. #ifndef __STM32_WPAN_COMMON_H
  20. #define __STM32_WPAN_COMMON_H
  21. #ifdef __cplusplus
  22. extern "C" {
  23. #endif
  24. #if defined(__CC_ARM) || defined(__ARMCC_VERSION)
  25. #define __ASM __asm /*!< asm keyword for ARM Compiler */
  26. #define __INLINE __inline /*!< inline keyword for ARM Compiler */
  27. #define __STATIC_INLINE static __inline
  28. #elif defined(__ICCARM__)
  29. #define __ASM __asm /*!< asm keyword for IAR Compiler */
  30. #define __INLINE \
  31. inline /*!< inline keyword for IAR Compiler. Only available in High optimization mode! */
  32. #define __STATIC_INLINE static inline
  33. #elif defined(__GNUC__)
  34. #define __ASM __asm /*!< asm keyword for GNU Compiler */
  35. #define __INLINE inline /*!< inline keyword for GNU Compiler */
  36. #define __STATIC_INLINE static inline
  37. #endif
  38. #include <stdint.h>
  39. #include <string.h>
  40. #include <stdio.h>
  41. #include <stdlib.h>
  42. #include <stdarg.h>
  43. #include "cmsis_compiler.h"
  44. /* -------------------------------- *
  45. * Basic definitions *
  46. * -------------------------------- */
  47. #undef NULL
  48. #define NULL 0U
  49. #undef FALSE
  50. #define FALSE 0U
  51. #undef TRUE
  52. #define TRUE (!0U)
  53. /* -------------------------------- *
  54. * Critical Section definition *
  55. * -------------------------------- */
  56. #undef BACKUP_PRIMASK
  57. #define BACKUP_PRIMASK() uint32_t primask_bit = __get_PRIMASK()
  58. #undef DISABLE_IRQ
  59. #define DISABLE_IRQ() __disable_irq()
  60. #undef RESTORE_PRIMASK
  61. #define RESTORE_PRIMASK() __set_PRIMASK(primask_bit)
  62. /* -------------------------------- *
  63. * Macro delimiters *
  64. * -------------------------------- */
  65. #undef M_BEGIN
  66. #define M_BEGIN do {
  67. #undef M_END
  68. #define M_END \
  69. } \
  70. while(0)
  71. /* -------------------------------- *
  72. * Some useful macro definitions *
  73. * -------------------------------- */
  74. #undef MAX
  75. #define MAX(a, b) (((a) > (b)) ? (a) : (b))
  76. #undef MIN
  77. #define MIN(a, b) (((a) < (b)) ? (a) : (b))
  78. #undef MODINC
  79. #define MODINC(a, m) \
  80. M_BEGIN(a)++; \
  81. if((a) >= (m)) (a) = 0; \
  82. M_END
  83. #undef MODDEC
  84. #define MODDEC(a, m) \
  85. M_BEGIN if((a) == 0)(a) = (m); \
  86. (a)--; \
  87. M_END
  88. #undef MODADD
  89. #define MODADD(a, b, m) \
  90. M_BEGIN(a) += (b); \
  91. if((a) >= (m)) (a) -= (m); \
  92. M_END
  93. #undef MODSUB
  94. #define MODSUB(a, b, m) MODADD(a, (m) - (b), m)
  95. #undef ALIGN
  96. #ifdef WIN32
  97. #define ALIGN(n)
  98. #else
  99. #define ALIGN(n) __attribute__((aligned(n)))
  100. #endif
  101. #undef PAUSE
  102. #define PAUSE(t) \
  103. M_BEGIN \
  104. volatile int _i; \
  105. for(_i = t; _i > 0; _i--) \
  106. ; \
  107. M_END
  108. #undef DIVF
  109. #define DIVF(x, y) ((x) / (y))
  110. #undef DIVC
  111. #define DIVC(x, y) (((x) + (y) - 1) / (y))
  112. #undef DIVR
  113. #define DIVR(x, y) (((x) + ((y) / 2)) / (y))
  114. #undef SHRR
  115. #define SHRR(x, n) ((((x) >> ((n) - 1)) + 1) >> 1)
  116. #undef BITN
  117. #define BITN(w, n) (((w)[(n) / 32] >> ((n) % 32)) & 1)
  118. #undef BITNSET
  119. #define BITNSET(w, n, b) \
  120. M_BEGIN(w)[(n) / 32] |= ((U32)(b)) << ((n) % 32); \
  121. M_END
  122. /* -------------------------------- *
  123. * Section attribute *
  124. * -------------------------------- */
  125. #undef PLACE_IN_SECTION
  126. #define PLACE_IN_SECTION(__x__) __attribute__((section(__x__)))
  127. /* ----------------------------------- *
  128. * Packed usage (compiler dependent) *
  129. * ----------------------------------- */
  130. #undef PACKED__
  131. #undef PACKED_STRUCT
  132. #if defined(__CC_ARM)
  133. #if defined(__GNUC__)
  134. /* GNU extension */
  135. #define PACKED__ __attribute__((packed))
  136. #define PACKED_STRUCT struct PACKED__
  137. #elif defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050U)
  138. #define PACKED__ __attribute__((packed))
  139. #define PACKED_STRUCT struct PACKED__
  140. #else
  141. #define PACKED__(TYPE) __packed TYPE
  142. #define PACKED_STRUCT PACKED__(struct)
  143. #endif
  144. #elif defined(__GNUC__)
  145. #define PACKED__ __attribute__((packed))
  146. #define PACKED_STRUCT struct PACKED__
  147. #elif defined(__ICCARM__)
  148. #define PACKED_STRUCT __packed struct
  149. #else
  150. #define PACKED_STRUCT __packed struct
  151. #endif
  152. #ifdef __cplusplus
  153. }
  154. #endif
  155. #endif /*__STM32_WPAN_COMMON_H */