openaliro
Aliro reader: UWB/CCC core and ESP32-S3/C5/C6 port
Loading...
Searching...
No Matches
woz_util.h
1
/*
2
* Copyright (c) 2026 asxeem
3
* SPDX-License-Identifier: ISC
4
* woz_util.h - container and compare macros.
5
*
6
* Pure code, same rationale as woz_bytes.h: none of this is platform-specific,
7
* so it does not belong behind a <zephyr/sys/util.h> compat header.
8
*
9
* Every macro is #ifndef-guarded, so on Zephyr the real header wins if it was
10
* already included and these are inert.
11
*/
12
#ifndef WOZ_UTIL_H
13
#define WOZ_UTIL_H
14
15
#include <stddef.h>
16
17
#if defined(__ZEPHYR__)
18
#include <zephyr/sys/util.h>
19
#endif
20
21
#ifndef ARRAY_SIZE
22
#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
23
#endif
24
#ifndef MIN
25
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
26
#endif
27
#ifndef MAX
28
#define MAX(a, b) (((a) > (b)) ? (a) : (b))
29
#endif
30
#ifndef CLAMP
31
#define CLAMP(x, lo, hi) MIN(MAX((x), (lo)), (hi))
32
#endif
33
#ifndef BIT
34
#define BIT(n) (1UL << (n))
35
#endif
36
#ifndef DIV_ROUND_UP
37
#define DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d))
38
#endif
39
#ifndef ROUND_UP
40
#define ROUND_UP(x, align) (DIV_ROUND_UP((x), (align)) * (align))
41
#endif
42
#ifndef CONTAINER_OF
43
#define CONTAINER_OF(ptr, type, field) ((type *)(((char *)(ptr)) - offsetof(type, field)))
44
#endif
45
#ifndef ARG_UNUSED
46
#define ARG_UNUSED(x) ((void)(x))
47
#endif
48
49
/* Zephyr's IS_ENABLED: 1 when the arg is defined to 1, 0 when undefined. */
50
#ifndef IS_ENABLED
51
#define IS_ENABLED(config_macro) Z_IS_ENABLED1(config_macro)
52
#define Z_IS_ENABLED1(config_macro) Z_IS_ENABLED2(_XXXX##config_macro)
53
#define _XXXX1 _YYYY,
54
/* Token-splice: the bare arg is the mechanism. NOLINTNEXTLINE(bugprone-macro-parentheses) */
55
#define Z_IS_ENABLED2(one_or_two_args) Z_IS_ENABLED3(one_or_two_args 1, 0)
56
#define Z_IS_ENABLED3(ignore_this, val, ...) val
57
#endif
58
59
#endif
/* WOZ_UTIL_H */
modules
woz_uwb
src
facade
woz_util.h
Generated by
1.9.8