stm32_wpan_common.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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 inline /*!< inline keyword for IAR Compiler. Only available in High optimization mode! */
  31. #define __STATIC_INLINE static inline
  32. #elif defined ( __GNUC__ )
  33. #define __ASM __asm /*!< asm keyword for GNU Compiler */
  34. #define __INLINE inline /*!< inline keyword for GNU Compiler */
  35. #define __STATIC_INLINE static inline
  36. #endif
  37. #include <stdint.h>
  38. #include <string.h>
  39. #include <stdio.h>
  40. #include <stdlib.h>
  41. #include <stdarg.h>
  42. #include "cmsis_compiler.h"
  43. /* -------------------------------- *
  44. * Basic definitions *
  45. * -------------------------------- */
  46. #undef NULL
  47. #define NULL 0U
  48. #undef FALSE
  49. #define FALSE 0U
  50. #undef TRUE
  51. #define TRUE (!0U)
  52. /* -------------------------------- *
  53. * Critical Section definition *
  54. * -------------------------------- */
  55. #undef BACKUP_PRIMASK
  56. #define BACKUP_PRIMASK() uint32_t primask_bit= __get_PRIMASK()
  57. #undef DISABLE_IRQ
  58. #define DISABLE_IRQ() __disable_irq()
  59. #undef RESTORE_PRIMASK
  60. #define RESTORE_PRIMASK() __set_PRIMASK(primask_bit)
  61. /* -------------------------------- *
  62. * Macro delimiters *
  63. * -------------------------------- */
  64. #undef M_BEGIN
  65. #define M_BEGIN do {
  66. #undef M_END
  67. #define M_END } while(0)
  68. /* -------------------------------- *
  69. * Some useful macro definitions *
  70. * -------------------------------- */
  71. #undef MAX
  72. #define MAX(a, b) (((a) > (b)) ? (a) : (b))
  73. #undef MIN
  74. #define MIN(a, b) (((a) < (b)) ? (a) : (b))
  75. #undef MODINC
  76. #define MODINC( a, m ) M_BEGIN (a)++; if ((a)>=(m)) (a)=0; M_END
  77. #undef MODDEC
  78. #define MODDEC( a, m ) M_BEGIN if ((a)==0) (a)=(m); (a)--; M_END
  79. #undef MODADD
  80. #define MODADD( a, b, m ) M_BEGIN (a)+=(b); if ((a)>=(m)) (a)-=(m); M_END
  81. #undef MODSUB
  82. #define MODSUB( a, b, m ) MODADD( a, (m)-(b), m )
  83. #undef ALIGN
  84. #ifdef WIN32
  85. #define ALIGN(n)
  86. #else
  87. #define ALIGN(n) __attribute__((aligned(n)))
  88. #endif
  89. #undef PAUSE
  90. #define PAUSE( t ) M_BEGIN \
  91. volatile int _i; \
  92. for ( _i = t; _i > 0; _i -- ); \
  93. M_END
  94. #undef DIVF
  95. #define DIVF( x, y ) ((x)/(y))
  96. #undef DIVC
  97. #define DIVC( x, y ) (((x)+(y)-1)/(y))
  98. #undef DIVR
  99. #define DIVR( x, y ) (((x)+((y)/2))/(y))
  100. #undef SHRR
  101. #define SHRR( x, n ) ((((x)>>((n)-1))+1)>>1)
  102. #undef BITN
  103. #define BITN( w, n ) (((w)[(n)/32] >> ((n)%32)) & 1)
  104. #undef BITNSET
  105. #define BITNSET( w, n, b ) M_BEGIN (w)[(n)/32] |= ((U32)(b))<<((n)%32); M_END
  106. /* -------------------------------- *
  107. * Section attribute *
  108. * -------------------------------- */
  109. #undef PLACE_IN_SECTION
  110. #define PLACE_IN_SECTION( __x__ ) __attribute__((section (__x__)))
  111. /* ----------------------------------- *
  112. * Packed usage (compiler dependent) *
  113. * ----------------------------------- */
  114. #undef PACKED__
  115. #undef PACKED_STRUCT
  116. #if defined ( __CC_ARM )
  117. #if defined ( __GNUC__ )
  118. /* GNU extension */
  119. #define PACKED__ __attribute__((packed))
  120. #define PACKED_STRUCT struct PACKED__
  121. #elif defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050U)
  122. #define PACKED__ __attribute__((packed))
  123. #define PACKED_STRUCT struct PACKED__
  124. #else
  125. #define PACKED__(TYPE) __packed TYPE
  126. #define PACKED_STRUCT PACKED__(struct)
  127. #endif
  128. #elif defined ( __GNUC__ )
  129. #define PACKED__ __attribute__((packed))
  130. #define PACKED_STRUCT struct PACKED__
  131. #elif defined (__ICCARM__)
  132. #define PACKED_STRUCT __packed struct
  133. #else
  134. #define PACKED_STRUCT __packed struct
  135. #endif
  136. #ifdef __cplusplus
  137. }
  138. #endif
  139. #endif /*__STM32_WPAN_COMMON_H */