Mistake on this page?
Report an issue in GitHub or email us
stm32_wpan_common.h
Go to the documentation of this file.
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 BSD 3-Clause license,
13  * the "License"; You may not use this file except in compliance with the
14  * License. You may obtain a copy of the License at:
15  * opensource.org/licenses/BSD-3-Clause
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 #include <stdint.h>
30 #include <string.h>
31 #include <stdio.h>
32 #include <stdlib.h>
33 #include <stdarg.h>
34 #include "cmsis_compiler.h"
35 
36  /* -------------------------------- *
37  * Basic definitions *
38  * -------------------------------- */
39 
40 #undef NULL
41 #define NULL 0U
42 
43 #undef FALSE
44 #define FALSE 0U
45 
46 #undef TRUE
47 #define TRUE (!0U)
48 
49  /* -------------------------------- *
50  * Critical Section definition *
51  * -------------------------------- */
52 #undef BACKUP_PRIMASK
53 #define BACKUP_PRIMASK() uint32_t primask_bit= __get_PRIMASK()
54 
55 #undef DISABLE_IRQ
56 #define DISABLE_IRQ() __disable_irq()
57 
58 #undef RESTORE_PRIMASK
59 #define RESTORE_PRIMASK() __set_PRIMASK(primask_bit)
60 
61  /* -------------------------------- *
62  * Macro delimiters *
63  * -------------------------------- */
64 #undef M_BEGIN
65 #define M_BEGIN do {
66 
67 #undef M_END
68 #define M_END } while(0)
69 
70  /* -------------------------------- *
71  * Some useful macro definitions *
72  * -------------------------------- */
73 #undef MAX
74 #define MAX(a, b) (((a) > (b)) ? (a) : (b))
75 
76 #undef MIN
77 #define MIN(a, b) (((a) < (b)) ? (a) : (b))
78 
79 #undef MODINC
80 #define MODINC( a, m ) M_BEGIN (a)++; if ((a)>=(m)) (a)=0; M_END
81 
82 #undef MODDEC
83 #define MODDEC( a, m ) M_BEGIN if ((a)==0) (a)=(m); (a)--; M_END
84 
85 #undef MODADD
86 #define MODADD( a, b, m ) M_BEGIN (a)+=(b); if ((a)>=(m)) (a)-=(m); M_END
87 
88 #undef MODSUB
89 #define MODSUB( a, b, m ) MODADD( a, (m)-(b), m )
90 
91 #undef ALIGN
92 #ifdef WIN32
93 #define ALIGN(n)
94 #else
95 #define ALIGN(n) __attribute__((aligned(n)))
96 #endif
97 
98 #undef PAUSE
99 #define PAUSE( t ) M_BEGIN \
100  volatile int _i; \
101  for ( _i = t; _i > 0; _i -- ); \
102  M_END
103 #undef DIVF
104 #define DIVF( x, y ) ((x)/(y))
105 
106 #undef DIVC
107 #define DIVC( x, y ) (((x)+(y)-1)/(y))
108 
109 #undef DIVR
110 #define DIVR( x, y ) (((x)+((y)/2))/(y))
111 
112 #undef SHRR
113 #define SHRR( x, n ) ((((x)>>((n)-1))+1)>>1)
114 
115 #undef BITN
116 #define BITN( w, n ) (((w)[(n)/32] >> ((n)%32)) & 1)
117 
118 #undef BITNSET
119 #define BITNSET( w, n, b ) M_BEGIN (w)[(n)/32] |= ((U32)(b))<<((n)%32); M_END
120 
121 /* -------------------------------- *
122  * Section attribute *
123  * -------------------------------- */
124 #undef PLACE_IN_SECTION
125 #define PLACE_IN_SECTION( __x__ ) __attribute__((section (__x__)))
126 
127 /* ----------------------------------- *
128  * Packed usage (compiler dependent) *
129  * ----------------------------------- */
130 #undef PACKED__
131 #undef PACKED_STRUCT
132 
133 #if defined ( __CC_ARM )
134  #if defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050U)
135  #define PACKED__ __attribute__((packed))
136  #define PACKED_STRUCT struct PACKED__
137  #else
138  #define PACKED__(TYPE) __packed TYPE
139  #define PACKED_STRUCT PACKED__(struct)
140  #endif
141 #elif defined ( __GNUC__ )
142  #define PACKED__ __attribute__((packed))
143  #define PACKED_STRUCT struct PACKED__
144 #elif defined (__ICCARM__)
145  #define PACKED_STRUCT __packed struct
146 #else
147  #define PACKED_STRUCT __packed struct
148 #endif
149 
150 #ifdef __cplusplus
151 }
152 #endif
153 
154 #endif /*__STM32_WPAN_COMMON_H */
155 
156 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
Important Information for this Arm website

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies. If you are not happy with the use of these cookies, please review our Cookie Policy to learn how they can be disabled. By disabling cookies, some features of the site will not work.