forked from rtlabs-com/osal
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathosal_cc.h
More file actions
92 lines (80 loc) · 3.04 KB
/
Copy pathosal_cc.h
File metadata and controls
92 lines (80 loc) · 3.04 KB
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
/*********************************************************************
* _ _ _
* _ __ | |_ _ | | __ _ | |__ ___
* | '__|| __|(_)| | / _` || '_ \ / __|
* | | | |_ _ | || (_| || |_) |\__ \
* |_| \__|(_)|_| \__,_||_.__/ |___/
*
* www.rt-labs.com
* Copyright 2021 rt-labs AB, Sweden.
*
* This software is licensed under the terms of the BSD 3-clause
* license. See the file LICENSE distributed with this software for
* full license information.
********************************************************************/
#ifndef CC_H
#define CC_H
#include <assert.h>
#ifdef __cplusplus
extern "C"
{
#endif
#define CC_PACKED_BEGIN
#define CC_PACKED_END
#define CC_PACKED __attribute__((packed))
#define CC_ALIGNED(n) __attribute__((aligned (n)))
#define CC_FORMAT(str,arg) __attribute__((format (printf, str, arg)))
#if BYTE_ORDER == LITTLE_ENDIAN
#define CC_TO_LE16(x) ((uint16_t)(x))
#define CC_TO_LE32(x) ((uint32_t)(x))
#define CC_TO_LE64(x) ((uint64_t)(x))
#define CC_FROM_LE16(x) ((uint16_t)(x))
#define CC_FROM_LE32(x) ((uint32_t)(x))
#define CC_FROM_LE64(x) ((uint64_t)(x))
#define CC_TO_BE16(x) ((uint16_t)__builtin_bswap16 (x))
#define CC_TO_BE32(x) ((uint32_t)__builtin_bswap32 (x))
#define CC_TO_BE64(x) ((uint64_t)__builtin_bswap64 (x))
#define CC_FROM_BE16(x) ((uint16_t)__builtin_bswap16 (x))
#define CC_FROM_BE32(x) ((uint32_t)__builtin_bswap32 (x))
#define CC_FROM_BE64(x) ((uint64_t)__builtin_bswap64 (x))
#else
#define CC_TO_LE16(x) ((uint16_t)__builtin_bswap16 (x))
#define CC_TO_LE32(x) ((uint32_t)__builtin_bswap32 (x))
#define CC_TO_LE64(x) ((uint64_t)__builtin_bswap64 (x))
#define CC_FROM_LE16(x) ((uint16_t)__builtin_bswap16 (x))
#define CC_FROM_LE32(x) ((uint32_t)__builtin_bswap32 (x))
#define CC_FROM_LE64(x) ((uint64_t)__builtin_bswap64 (x))
#define CC_TO_BE16(x) ((uint16_t)(x))
#define CC_TO_BE32(x) ((uint32_t)(x))
#define CC_TO_BE64(x) ((uint64_t)(x))
#define CC_FROM_BE16(x) ((uint16_t)(x))
#define CC_FROM_BE32(x) ((uint32_t)(x))
#define CC_FROM_BE64(x) ((uint64_t)(x))
#endif
#define CC_ATOMIC_GET8(p) (*p)
#define CC_ATOMIC_GET16(p) (*p)
#define CC_ATOMIC_GET32(p) (*p)
#define CC_ATOMIC_GET64(p) \
({ \
uint64_t v; \
/*int_lock();*/ \
v = *p; \
/*int_unlock();*/ \
v; \
})
#define CC_ATOMIC_SET8(p, v) ((*p) = (v))
#define CC_ATOMIC_SET16(p, v) ((*p) = (v))
#define CC_ATOMIC_SET32(p, v) ((*p) = (v))
#define CC_ATOMIC_SET64(p, v) \
({ \
/*int_lock();*/ \
*p = v; \
/*int_unlock();*/ \
})
#define CC_ASSERT(exp) assert (exp)
#define CC_STATIC_ASSERT(exp) _Static_assert (exp, "")
#define CC_UNUSED(var) (void)(var)
#ifdef __cplusplus
}
#endif
#endif /* CC_H */