Hardware Abstraction Layer for FreeRTOS
system.h
Go to the documentation of this file.
1
/* SPDX-License-Identifier: MIT */
2
/*
3
* Author: Andreas Werner <kernel@andy89.org>
4
* Date: 2016
5
*/
6
#ifndef SYSTEM_H_
7
#define SYSTEM_H_
8
27
#define WEAK __attribute__ ((weak))
28
37
#define ALIAS(x) __attribute__ ((alias(#x)))
38
50
#define INTERRUPT(x) __attribute__ ((interrut(x)))
51
60
#define SECTION(x) __attribute__ ((section(x)))
61
64
#define NAKED __attribute__ ((naked))
65
68
#define USED __attribute__ ((used))
69
89
#define PACKED __attribute__ ((__packed__))
90
#if __GNUC__ >= 5
91
#define NO_REORDER __attribute__ ((no_reorder))
92
#else
93
/* Not GCC or < GCC 5.0 has no no_reoder attribute */
100
#define NO_REORDER
101
#endif
102
105
#define ALIGN(x) __attribute__((aligned(x)))
106
109
#define NSEC_PER_SEC 1000000000ULL
110
114
#define BIT(x) ((uint32_t) (1UL << (x)))
115
121
#define BITS(x, mask, shift) ((uint32_t) ((((uint32_t) (x))<<(shift)) & (mask)))
122
128
#define BITS_INV(x, mask, shift) ((uint32_t) ((((uint32_t) (x)) & (mask))>>(shift)))
129
134
#define BITS_MASK(bits, shift) ((uint32_t) ((~(0xFFFFFFFFUL << (bits))) << (shift)))
135
139
#define BIT64(x) ((uint64_t) (1ULL << (x)))
140
146
#define BITS64(x, mask, shift) ((uint64_t) ((((uint64_t) (x))<<(shift)) & (mask)))
147
153
#define BITS64_INV(x, mask, shift) ((uint64_t) ((((uint64_t) (x)) & (mask))>>(shift)))
154
159
#define BITS64_MASK(bits, shift) ((uint64_t) ((~(0xFFFFFFFFFFFFFFFFULL << (bits))) << (shift)))
160
166
#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
167
172
#define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d))
173
179
#define MAX(a, b) (((a) > (b)) ? (a) : (b))
180
186
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
187
192
#define swap32(d) ({ \
193
union {uint32_t ret; uint8_t ret8[4];} tmp;\
194
tmp.ret = (d); \
195
/* swap 0 -> 3 and 1 -> 2 -> 0123 -> 3210 */
\
196
/* use XOR Swap */
\
197
tmp.ret8[0] ^= tmp.ret8[3]; \
198
tmp.ret8[3] ^= tmp.ret8[0]; \
199
tmp.ret8[0] ^= tmp.ret8[3]; \
200
tmp.ret8[1] ^= tmp.ret8[2]; \
201
tmp.ret8[2] ^= tmp.ret8[1]; \
202
tmp.ret8[1] ^= tmp.ret8[2]; \
203
tmp.ret; \
204
})
205
210
#define swap16(d) ({ \
211
union {uint16_t ret; uint8_t ret8[2];} tmp;\
212
tmp.ret = (d); \
213
/* use XOR Swap */
\
214
tmp.ret8[0] ^= tmp.ret8[1]; \
215
tmp.ret8[1] ^= tmp.ret8[0]; \
216
tmp.ret8[0] ^= tmp.ret8[1]; \
217
tmp.ret; \
218
})
219
224
#define cpu_to_be32(d) swap32(d)
225
230
#define be32_to_cpu(d) swap32(d)
231
236
#define cpu_to_be16(d) swap16(d)
237
242
#define be16_to_cpu(d) swap16(d)
243
248
#define cpu_to_le32(d) d
249
254
#define le32_to_cpu(d) d
255
260
#define cpu_to_le16(d) d
261
266
#define le16_to_cpu(d) d
267
269
#endif
driver
include
system.h
Generated on Tue Aug 17 2021 15:19:23 for Hardware Abstraction Layer for FreeRTOS by
1.8.20