xt-sdk 文档 v1.0.3
xt-sdk 嵌入式 SDK API 参考
载入中...
搜索中...
未找到
xt_macro.h
浏览该文件的文档.
1
12
13#ifndef __XT_MACRO_H__
14#define __XT_MACRO_H__
15
16/* ==================== [Includes] ========================================== */
17
18#include <stddef.h>
19#include <stdint.h>
20
21#ifdef __cplusplus
22extern "C" {
23#endif
24
31
32/* ==================== [Defines] =========================================== */
33
34#define XT_STATIC_ASSERT(const_expression) extern char (*O_o(char static_assertion_failure[1 - 2 * !(const_expression)]))
35#define XT_STATIC_ASSERT_MSG(const_expression, msg) extern char (*O_o(char static_assertion_failure[1 - 2 * !(const_expression)]))
36
37#define XT_ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
38#define XT_UNUSED(x) (void)(x)
39
40#define XT_OFFSETOF(type, member) ((size_t)&((type *)0)->member)
41#define XT_CONTAINER_OF(ptr, type, member) ((type *)((char *)(ptr) - XT_OFFSETOF(type, member)))
42
43#define XT_ABS(x) ((x) < 0 ? -(x) : (x))
44#define XT_MAX(x, y) ((x) > (y) ? (x) : (y))
45#define XT_MIN(x, y) ((x) < (y) ? (x) : (y))
46#define XT_DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d))
47#define XT_DIV_ROUND_DOWN(n, d) ((n) / (d))
48#define XT_IN_RANGE(val, min, max) ((min) <= (val) && (val) <= (max))
49
50#define __XT_ALIGN_MASK(x, mask) (((x) + (mask)) & ~(mask))
51#define XT_ALIGN(x, num_pow_of_2) __XT_ALIGN_MASK(x, (num_pow_of_2) - 1)
52#define XT_ALIGN_DOWN(x, num_pow_of_2) XT_ALIGN((x) - ((num_pow_of_2) - 1), (num_pow_of_2))
53#define XT_PTR_ALIGN(p, num_pow_of_2) XT_ALIGN((uintptr_t)(p), (num_pow_of_2))
54#define XT_IS_ALIGNED(x, num_pow_of_2) (((x) & ((num_pow_of_2) - 1)) == 0)
55
56#define XT_IS_POWER_OF_TWO(x) (((x) != 0) && ((((x) - 1) & (x)) == 0))
57
58/* ==================== [Typedefs] ========================================== */
59
60/* ==================== [Global Prototypes] ================================= */
61
62/* ==================== [Macros] ============================================ */
63 /* xt_macro */
65
66#ifdef __cplusplus
67} /* extern "C" */
68#endif
69
70#endif /* __XT_MACRO_H__ */