-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharm_attributes.h
306 lines (267 loc) · 13.6 KB
/
arm_attributes.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
/*!\file arm_attributes.h
** \author SMFSW
** \copyright MIT (c) 2017-2024, SMFSW
** \brief ARM common compilers attributes
** \details Set attributes following compiler
** \warning Cosmic compiler for STM32 attributes not implemented
** \MISRA Header scope deviation has been granted for following rules:\n
** \b Rule-20.5 - \b Advisory: \c \#undef (misra-c2012-20.5)\n
** \b Rule-20.10 - \b Advisory: \c # and \c ## preprocessor operators (misra-c2012-20.10)\n
** \MISRA Header scope legitimate use derogation authorized for:\n
** \b Rule-21.1 - \b Required: \c \#define and \c \#undef on reserved identifiers (misra-c2012-21.1)\n
** \a Justification: \c \#define are generic reserved identifiers for attributes.\n
*/
// cppcheck-suppress-begin [misra-c2012-20.5, misra-c2012-20.10]
// cppcheck-suppress-begin [misra-c2012-21.1]
/****************************************************************/
#ifndef ARM_ATTRIBUTES_H_
#define ARM_ATTRIBUTES_H_
#ifdef __cplusplus
extern "C" {
#endif
/****************************************************************/
#if defined (__CC_ARM)
/*** ARM REAL VIEW ***/
// Declared as qualifier
#define __WEAK __weak //!< Weak attribute
#define __IRQ __irq //!< Interrupt attribute
// Declared as attribute
#define ATTR__(...) __attribute__((__VA_ARGS__)) //!< Macro to define one or multiple attribute(s) \p ... for a declaration
#define ALIGN__(n) __attribute__((align(n))) //!< Align attribute padded to \p n
#define COLD__
#define DEPRECATED__ __attribute__((deprecated)) //!< Deprecated attribute
#define HOT__
#define INLINE__ __attribute__((always_inline)) //!< Always \c inline attribute
#define NONNULL__
#define NONNULLX__(...)
#define NORETURN__ __attribute__((noreturn)) //!< No \c return attribute
#define PACK__ __attribute__((packed)) //!< Packed attribute
#define PURE__ __attribute__((pure)) //!< Pure attribute
#define SECTION__(s) __attribute__((section(#s))) //!< Section attribute to place declaration into section \p s
#define USED__ __attribute__((used)) //!< Used attribute ensures declaration won't be removed by garbage collector
// Common mixed attributes
#define NONNULL_INLINE__ ATTR__(nonnull, always_inline) //!< Non \c null and Always \c inline attributes
#if (!defined(__OPTIMIZE__))
#define __NOOPT__ //!< No Optimizations attribute
#endif
#elif defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)
/*** ARM COMPILER TOOLCHAIN ***/
// Declared as qualifier
#define __WEAK __weak //!< Weak attribute
#define __IRQ __irq //!< Interrupt attribute
// Declared as attribute
#define ATTR__(...) __attribute__((__VA_ARGS__)) //!< Macro to define one or multiple attribute(s) \p ... for a declaration
#define ALIGN__(n) __attribute__((align(n))) //!< Align attribute padded to \p n
#define COLD__
#define DEPRECATED__ __attribute__((deprecated)) //!< Deprecated attribute
#define HOT__
#define INLINE__ __attribute__((always_inline)) //!< Always \c inline attribute
#define NONNULL__ __attribute__((nonnull)) //!< Non \c null attribute (all pointers will be checked)
#define NONNULLX__(...) __attribute__((nonnull(__VA_ARGS__))) //!< Non \c null attribute for \p ... pointers indexes
#define NORETURN__ __attribute__((noreturn)) //!< No \c return attribute
#define PACK__ __attribute__((packed)) //!< Packed attribute
#define PURE__ __attribute__((pure)) //!< Pure attribute
#define SECTION__(s) __attribute__((section(#s))) //!< Section attribute to place declaration into section \p s
#define USED__ __attribute__((used)) //!< Used attribute ensures declaration won't be removed by garbage collector
// Common mixed attributes
#define NONNULL_INLINE__ ATTR__(nonnull, always_inline) //!< Non \c null and Always \c inline attributes
#if (!defined(__OPTIMIZE__))
#define __NOOPT__ //!< No Optimizations attribute
#endif
#elif defined (__XC__) // Defined prior to __GNUC__ as also defined for some __XC__ compilers
/*** Microchip XC ***/
// Declared as qualifier
#define __WEAK __attribute__((weak)) //!< Weak attribute
#define __IRQ __attribute__((interrupt)) //!< Interrupt attribute
// Declared as attribute
#define ATTR__(...) __attribute__((__VA_ARGS__)) //!< Macro to define one or multiple attribute(s) \p ... for a declaration
#define ALIGN__(n) __attribute__((aligned (n))) //!< Align attribute padded to \p n
#define COLD__
#define DEPRECATED__ __attribute__((deprecated)) //!< Deprecated attribute
#define HOT__
#define INLINE__ __attribute__((always_inline)) //!< Always \c inline attribute
#define NONNULL__
#define NONNULLX__(...)
#define NORETURN__
#define PACK__ __attribute__((packed)) //!< Packed attribute
#define PURE__
#define SECTION__(s) __attribute__((section(#s))) //!< Section attribute to place declaration into section \p s
#define USED__
// Common mixed attributes
#define NONNULL_INLINE__ __attribute__((always_inline)) //!< Always \c inline attribute
#if (!defined(__OPTIMIZE__))
#define __NOOPT__ //!< No Optimizations attribute
#endif
#elif defined (__GNUC__)
/*** GCC ***/
// Declared as qualifier
#define __WEAK __attribute__((weak)) //!< Weak attribute
#define __IRQ __attribute__((interrupt_handler)) //!< Interrupt attribute
// Declared as attribute
#define ATTR__(...) __attribute__((__VA_ARGS__)) //!< Macro to define one or multiple attribute(s) \p ... for a declaration
#define ALIGN__(n) __attribute__((align(n))) //!< Align attribute padded to \p n
#define COLD__ __attribute__((cold)) //!< Cold attribute
#define DEPRECATED__ __attribute__((deprecated)) //!< Deprecated attribute
#define HOT__ __attribute__((hot)) //!< Hot attribute
#define INLINE__ __attribute__((always_inline)) //!< Always \c inline attribute
#define NONNULL__ __attribute__((nonnull)) //!< Non \c null attribute (all pointers will be checked)
#define NONNULLX__(...) __attribute__((nonnull(__VA_ARGS__))) //!< Non \c null attribute for \p ... pointers indexes
#define NORETURN__ __attribute__((__noreturn__)) //!< No \c return attribute
#define PACK__ __attribute__((packed)) //!< Packed attribute
#define PURE__ __attribute__((pure)) //!< Pure attribute
#define SECTION__(s) __attribute__((section(#s))) //!< Section attribute to place declaration into section \p s
#define USED__ __attribute__((used)) //!< Used attribute ensures declaration won't be removed by garbage collector
// Common mixed attributes
#define NONNULL_INLINE__ ATTR__(nonnull, always_inline) //!< Non \c null and Always \c inline attributes
// Only supported starting GCC 6 (WARNING: here mostly for reference and specific cases, not defined for other compilers)
#define SSO(o) scalar_storage_order(#o) //!< Alias for Scalar Storage Order
#define BIG_ENDIAN__ ATTR__(packed, SSO(big-endian)) //!< Force structure in Big-Endian (use wisely or not at all)
#define LITTLE_ENDIAN__ ATTR__(packed, SSO(little-endian)) //!< Force structure in Little-Endian (use wisely or not at all)
#if (!defined(__OPTIMIZE__))
#define __NOOPT__ //!< No Optimizations attribute
#endif
#elif defined (__ICCARM__)
// FIXME: most likely will not work, check cmsis_iccarm.h to fix attributes
/*** IAR ***/
// Declared as qualifier
#define __WEAK __weak //!< Weak attribute
#define __IRQ __irq //!< Interrupt attribute
// Declared as attribute
#define ATTR__(...) __attribute__((__VA_ARGS__)) //!< Macro to define one or multiple attribute(s) \p ... for a declaration
#define ALIGN__(n) __attribute__((align(n))) //!< Align attribute padded to \p n
#define COLD__
#define DEPRECATED__
#define HOT__
#define INLINE__
#define NONNULL__
#define NONNULLX__(...)
#define NORETURN__ __noreturn //!< No \c return attribute
#define PACK__ __packed //!< Packed attribute
#define PURE__
#define SECTION__(s)
#define USED__
// Common mixed attributes
#define NONNULL_INLINE__
//#define __NOOPT__ //!< No Optimizations attribute not identified on IAR toolchain
#elif defined (__TI_ARM__)
/*** TEXAS INSTRUMENTS ***/
// Declared as qualifier
#define __WEAK __attribute__((weak)) //!< Weak attribute only through \c #pragma weak(symbol)
#define __IRQ __interrupt //!< Interrupt attribute
// Declared as attribute
#define ATTR__(...) __attribute__((__VA_ARGS__)) //!< Macro to define one or multiple attribute(s) \p ... for a declaration
#define ALIGN__(n)
#define COLD__
#define DEPRECATED__ __attribute__((deprecated)) //!< Deprecated attribute
#define HOT__
#define INLINE__
#define NONNULL__
#define NONNULLX__(...)
#define NORETURN__ __attribute__((noreturn)) //!< No \c return attribute
#define PACK__ __attribute__((packed)) //!< Packed attribute
#define PURE__ __attribute__((pure)) //!< Pure attribute
#define SECTION__(s) __attribute__((section(#s))) //!< Section attribute to place declaration into section \p s
#define USED__ __attribute__((used)) //!< Used attribute ensures declaration won't be removed by garbage collector
// Common mixed attributes
#define NONNULL_INLINE__
#if (!defined(__OPTIMIZE__))
#define __NOOPT__ //!< No Optimizations attribute
#define __STATIC_FORCEINLINE static inline //!< Static \c inline attribute alias when \c __NOOPT__ defined
#endif
#elif defined (__TASKING__)
/*** TASKING ***/
// Declared as qualifier
#define __WEAK __attribute__((weak)) //!< Weak attribute
#define __IRQ __interrupt_irq //!< Interrupt attribute
// Declared as attribute
#define ATTR__(...) __attribute__((__VA_ARGS__)) //!< Macro to define one or multiple attribute(s) \p ... for a declaration
#define ALIGN__(n) __align(n) //!< Align attribute padded to \p n
#define COLD__
#define DEPRECATED__
#define HOT__
#define INLINE__ __attribute__((always_inline)) //!< Always \c inline attribute
#define NONNULL__
#define NONNULLX__(...)
#define NORETURN__ __attribute__((noreturn)) //!< No \c return attribute
#define PACK__ __packed__ //!< Packed attribute
#define PURE__ __attribute__((pure)) //!< Pure attribute
#define SECTION__(s) __attribute__((section(#s))) //!< Section attribute to place declaration into section \p s
#define USED__ __attribute__((used)) //!< Used attribute ensures declaration won't be removed by garbage collector
// Common mixed attributes
#define NONNULL_INLINE__ __attribute__((always_inline)) //!< Always \c inline attribute
#if (!defined(__OPTIMIZE__))
#define __NOOPT__ //!< No Optimizations attribute
#define __STATIC_FORCEINLINE static inline //!< Static \c inline attribute alias when \c __NOOPT__ defined
#endif
#elif defined (__CSMC__)
/*** GCC ***/
// Declared as qualifier
#define __WEAK __weak //!< Weak attribute
#define __IRQ @interrupt //!< Interrupt attribute
// Declared as attribute
#define ATTR__(...)
#define ALIGN__(n)
#define COLD__
#define DEPRECATED__
#define HOT__
#define INLINE__
#define NONNULL__
#define NONNULLX__(...)
#define NORETURN__
#define PACK__ @packed //!< Packed attribute
#define PURE__
#define SECTION__(s)
#define USED__
// Common mixed attributes
#define NONNULL_INLINE__
#if (!defined(__OPTIMIZE__))
#define __NOOPT__ //!< No Optimizations attribute
#define __STATIC_FORCEINLINE static inline //!< Static \c inline attribute alias when \c __NOOPT__ defined
#endif
#else
#error Unknown compiler. Attributes will not be recognized.
#endif
/*** C extensions keywords ***/
#ifndef __TYPEOF
#define __TYPEOF __typeof__ //!< \c typeof keyword alias (\note so that it may prior be set to other expansion following compiler)
#endif
#ifndef __ASM
#define __ASM __asm__ //!< \c asm keyword alias (\note so that it may prior be set to other expansion following compiler)
#endif
/*** C standard keywords ***/
#ifdef __STATIC
#undef __STATIC
#endif
#if defined(NO_STATIC_FUNC) || defined(UNITY_TESTING)
#define __STATIC //!< \c static alias when functions visibility may be required (__INLINE remaining static)
#else
#define __STATIC static //!< \c static alias when functions visibility may be required (__INLINE remaining static)
#endif
#ifdef __INLINE
#undef __INLINE
#endif
//!\note Doesn't optimize code size much (when generated as functions) as code will be static to each file and hidden from others (leading to code duplicates)
#define __INLINE static inline //!< \c inline attribute alias
#ifndef __STATIC_INLINE
#define __STATIC_INLINE static inline //!< \c static \c inline attribute alias
#endif
/*** INLINES WORKAROUND WHEN OPTIMIZATION LEVEL SET TO NONE (GCC like toolchains) ***/
#if defined(__NOOPT__)
#undef __INLINE
#undef __STATIC_INLINE
#ifdef __STATIC_FORCEINLINE
#define __INLINE __STATIC_FORCEINLINE //!< \c inline attribute alias when \c __NOOPT__ defined
#define __STATIC_INLINE __STATIC_FORCEINLINE //!< \c static \c inline attribute alias when \c __NOOPT__ defined
#else
#define __INLINE __attribute__((always_inline)) static inline //!< \c inline attribute alias when \c __NOOPT__ defined
#define __STATIC_INLINE __attribute__((always_inline)) static inline //!< \c static \c inline attribute alias when \c __NOOPT__ defined
#endif
#endif
/****************************************************************/
#ifdef __cplusplus
}
#endif
#endif /* ARM_ATTRIBUTES_H_ */
// cppcheck-suppress-end [misra-c2012-20.5, misra-c2012-20.10]
// cppcheck-suppress-end [misra-c2012-21.1]
/****************************************************************/