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