Loading...
Searching...
No Matches
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 COUNT_OF
45#define COUNT_OF(x) (sizeof(x) / sizeof(x[0]))
46#endif
47
48#ifndef FURI_SWAP
49#define FURI_SWAP(x, y) \
50 do { \
51 typeof(x) SWAP = x; \
52 x = y; \
53 y = SWAP; \
54 } while(0)
55#endif
56
57#ifndef PLACE_IN_SECTION
58#define PLACE_IN_SECTION(x) __attribute__((section(x)))
59#endif
60
61#ifndef ALIGN
62#define ALIGN(n) __attribute__((aligned(n)))
63#endif
64
65#ifndef __weak
66#define __weak __attribute__((weak))
67#endif
68
69#ifndef UNUSED
70#define UNUSED(X) (void)(X)
71#endif
72
73#ifndef STRINGIFY
74#define STRINGIFY(x) #x
75#endif
76
77#ifndef TOSTRING
78#define TOSTRING(x) STRINGIFY(x)
79#endif
80
81#ifndef CONCATENATE
82#define CONCATENATE(a, b) CONCATENATE_(a, b)
83#define CONCATENATE_(a, b) a##b
84#endif
85
86#ifndef REVERSE_BYTES_U32
87#define REVERSE_BYTES_U32(x) \
88 ((((x) & 0x000000FF) << 24) | (((x) & 0x0000FF00) << 8) | (((x) & 0x00FF0000) >> 8) | \
89 (((x) & 0xFF000000) >> 24))
90#endif
91
92#ifndef FURI_BIT
93#define FURI_BIT(x, n) (((x) >> (n)) & 1)
94#endif
95
96#ifndef FURI_BIT_SET
97#define FURI_BIT_SET(x, n) \
98 ({ \
99 __typeof__(x) _x = (1); \
100 (x) |= (_x << (n)); \
101 })
102#endif
103
104#ifndef FURI_BIT_CLEAR
105#define FURI_BIT_CLEAR(x, n) \
106 ({ \
107 __typeof__(x) _x = (1); \
108 (x) &= ~(_x << (n)); \
109 })
110#endif
111
112#define FURI_SW_MEMBARRIER() asm volatile("" : : : "memory")
113
114#ifdef __cplusplus
115}
116#endif