Midnight Sun Firmware
Loading...
Searching...
No Matches
misc.h
1#pragma once
2
3/************************************************************************************************
4 * @file misc.h
5 *
6 * @brief Common helper functions
7 *
8 * @date 2024-10-27
9 * @author Midnight Sun Team #24 - MSXVI
10 ************************************************************************************************/
11
12/* Standard library Headers */
13
14/* Inter-component Headers */
15
16/* Intra-component Headers */
17
24#define SIZEOF_ARRAY(arr) (sizeof((arr)) / sizeof((arr)[0]))
25#define SIZEOF_FIELD(type, field) (sizeof(((type *)0)->field))
26#define SWAP_UINT16(x) (uint16_t)(((uint16_t)(x) >> 8) | ((uint16_t)(x) << 8))
27
28#define STRINGIFY_(x) #x
29#define STRINGIFY(x) STRINGIFY_(x)
30
31#define MIN(a, b) \
32 ({ \
33 __typeof__(a) _a = (a); \
34 __typeof__(b) _b = (b); \
35 _a < _b ? _a : _b; \
36 })
37
38#define MAX(a, b) \
39 ({ \
40 __typeof__(a) _a = (a); \
41 __typeof__(b) _b = (b); \
42 _a > _b ? _a : _b; \
43 })
44