blob: 321f46a825574aff8f464e0766b97758e1f099e0 (
plain)
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
|
#ifndef AVREMU_UTIL_H_
#define AVREMU_UTIL_H_
#ifndef __GNUC__
# error "Not using the GNU GCC compiler."
#endif
#include "list.h"
#include <stdint.h>
#include <stdlib.h>
#define likely(x) __builtin_expect(!!(x), 1)
#define unlikely(x) __builtin_expect(!!(x), 0)
#ifdef RUNTIME_SANITY_CHECKS
# define CHECK(x) unlikely(x)
#else
# define CHECK(x) 0
#endif
#define ARRAY_SIZE(x) (sizeof(x)/sizeof((x)[0]))
#define is_const_value(x) __builtin_constant_p(x)
/* Force reload a variable from memory. */
#define reload_var(x) (*((volatile typeof(x) *)&(x)))
/* Break the linkage of the binary, if the constant condition is true.
* This is useful for compiletime checks of constant values. */
#define break_linkage_on(constant_condition, reason) do { \
if (constant_condition) { \
extern void __avremu_bug__##reason(void); \
__avremu_bug__##reason(); \
} \
} while (0)
#define __stringify(x) #x
#define stringify(x) __stringify(x)
typedef uint16_t le16_t;
typedef uint32_t le32_t;
typedef _Bool bool;
static inline uint16_t swap16(uint16_t x)
{
return (x >> 8) | (x << 8);
}
static inline uint16_t le16_to_cpu(le16_t x)
{
#ifdef BIG_ENDIAN_HOST
return swap16((uint16_t)x);
#else
return (uint16_t)x;
#endif
}
static inline le16_t cpu_to_le16(uint16_t x)
{
#ifdef BIG_ENDIAN_HOST
return (le16_t)swap16(x);
#else
return (le16_t)x;
#endif
}
void * avr_malloc(size_t size);
#endif /* AVREMU_UTIL_H_ */
|