My Kernel v0.1.0
macro.h
1#ifndef UTILS_MACRO_H
2#define UTILS_MACRO_H
3
10#define MSB(_x) ((_x) >> 8)
12#define LSB(_x) ((_x)&0xFF)
13
15#define WAIT_FOR(_cond) \
16 do { \
17 while (!(_cond)) \
18 /* wait */; \
19 } while (0)
20
22#define INFINITE_LOOP() while (true)
23
25#define BETWEEN(_x, _l, _h) ((_l) < (_x) && (_x) < (_h))
26
28#define IN_RANGE(_x, _l, _h) ((_l) <= (_x) && (_x) <= (_h))
29
31#define RANGES_OVERLAP(_start1, _end1, _start2, _end2) \
32 ((_start1) <= (_end2) && (_end1) >= (_start2))
33
35#define UNUSED(_x) (void)(_x);
36
38#define ARRAY_SIZE(_arr) (sizeof(_arr) / sizeof(_arr[0]))
39
41#define RETURN_CMP(_x, _y) \
42 do { \
43 typeof((_x)) _tmp_x = (_x); \
44 typeof((_y)) _tmp_y = (_y); \
45 if (_tmp_x == _tmp_y) \
46 return 0; \
47 return (_tmp_x < _tmp_y) ? -1 : 1; \
48 } while (0);
49
50#define CONCAT(_x, _y) _x##_y
51#define CONCAT3(_x, _y, _z) _x##_y##_z
52
53#define ALL_ONES (-1)
54
55#define SWAP(_x, _y) \
56 do { \
57 typeof((_x)) _tmp = _x; \
58 _x = _y; \
59 _y = _tmp; \
60 } while (0)
61
62#endif /* UTILS_MACRO_H */