All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
core_defines.h
1#pragma once
2
3#ifdef __cplusplus
4extern "C" {
5#endif
6
7#define FURI_RETURNS_NONNULL __attribute__((returns_nonnull))
8
9#ifndef MAX
10#define MAX(a, b) \
11 ({ \
12 __typeof__(a) _a = (a); \
13 __typeof__(b) _b = (b); \
14 _a > _b ? _a : _b; \
15 })
16#endif
17
18#ifndef MIN
19#define MIN(a, b) \
20 ({ \
21 __typeof__(a) _a = (a); \
22 __typeof__(b) _b = (b); \
23 _a < _b ? _a : _b; \
24 })
25#endif
26
27#ifndef ABS
28#define ABS(a) ({ (a) < 0 ? -(a) : (a); })
29#endif
30
31#ifndef ROUND_UP_TO
32#define ROUND_UP_TO(a, b) \
33 ({ \
34 __typeof__(a) _a = (a); \
35 __typeof__(b) _b = (b); \
36 _a / _b + !!(_a % _b); \
37 })
38#endif
39
40#ifndef CLAMP
41#define CLAMP(x, upper, lower) (MIN(upper, MAX(x, lower)))
42#endif
43
44#ifndef CLAMP_WRAPAROUND
45#define CLAMP_WRAPAROUND(x, upper, lower) \
46 ({ \
47 __typeof__(x) _x = (x); \
48 __typeof__(upper) _upper = (upper); \
49 __typeof__(lower) _lower = (lower); \
50 (_x > _upper) ? _lower : ((_x < _lower) ? _upper : _x); \
51 })
52#endif
53
54#ifndef COUNT_OF
55#define COUNT_OF(x) (sizeof(x) / sizeof(x[0]))
56#endif
57
58#ifndef FURI_SWAP
59#define FURI_SWAP(x, y) \
60 do { \
61 typeof(x) SWAP = x; \
62 x = y; \
63 y = SWAP; \
64 } while(0)
65#endif
66
67#ifndef PLACE_IN_SECTION
68#define PLACE_IN_SECTION(x) __attribute__((section(x)))
69#endif
70
71#ifndef ALIGN
72#define ALIGN(n) __attribute__((aligned(n)))
73#endif
74
75#ifndef __weak
76#define __weak __attribute__((weak))
77#endif
78
79#ifndef UNUSED
80#define UNUSED(X) (void)(X)
81#endif
82
83#ifndef STRINGIFY
84#define STRINGIFY(x) #x
85#endif
86
87#ifndef TOSTRING
88#define TOSTRING(x) STRINGIFY(x)
89#endif
90
91#ifndef CONCATENATE
92#define CONCATENATE(a, b) CONCATENATE_(a, b)
93#define CONCATENATE_(a, b) a##b
94#endif
95
96#ifndef REVERSE_BYTES_U32
97#define REVERSE_BYTES_U32(x) \
98 ((((x) & 0x000000FF) << 24) | (((x) & 0x0000FF00) << 8) | (((x) & 0x00FF0000) >> 8) | \
99 (((x) & 0xFF000000) >> 24))
100#endif
101
102#ifndef FURI_BIT
103#define FURI_BIT(x, n) (((x) >> (n)) & 1)
104#endif
105
106#ifndef FURI_BIT_SET
107#define FURI_BIT_SET(x, n) \
108 ({ \
109 __typeof__(x) _x = (1); \
110 (x) |= (_x << (n)); \
111 })
112#endif
113
114#ifndef FURI_BIT_CLEAR
115#define FURI_BIT_CLEAR(x, n) \
116 ({ \
117 __typeof__(x) _x = (1); \
118 (x) &= ~(_x << (n)); \
119 })
120#endif
121
122#define FURI_SW_MEMBARRIER() asm volatile("" : : : "memory")
123
124#ifdef __cplusplus
125}
126#endif