openaliro
Aliro reader: UWB/CCC core and ESP32-S3/C5/C6 port
Loading...
Searching...
No Matches
woz_log.h
1/*
2 * Copyright (c) 2026 asxeem
3 * SPDX-License-Identifier: ISC
4 * woz_log.h - logging contract for the UWB engine.
5 *
6 * Zephyr's LOG_* spellings are kept so the call sites need only swap an
7 * include; on Zephyr this defers to the real header, elsewhere it maps them
8 * onto the platform logger. woz_printf replaces bare printk.
9 *
10 * WOZ_PRINTK_COMPAT: the non-Zephyr branches also alias `printk` itself. That
11 * exists for exactly one caller: the DIAG instrumentation this repo added to
12 * the vendored DW3000 sources (deca_compat.c, deca_interface.c,
13 * dw3000_device.c), which has ~18 printk call sites. Aliasing the spelling
14 * keeps those vendor files to a one-line include change instead of rewriting
15 * vendor call sites. Our own code uses woz_printf; if the vendor DIAG tracing
16 * is ever dropped, this alias goes with it.
17 */
18#ifndef WOZ_LOG_H
19#define WOZ_LOG_H
20
21#if defined(__ZEPHYR__)
22
23#include <zephyr/logging/log.h>
24#include <zephyr/sys/printk.h>
25
26#define woz_printf(...) printk(__VA_ARGS__)
27
28#elif defined(ESP_PLATFORM)
29
30#include <stdio.h>
31
32#include "esp_log.h"
33
34#define LOG_LEVEL_NONE 0
35#define LOG_LEVEL_ERR 1
36#define LOG_LEVEL_WRN 2
37#define LOG_LEVEL_INF 3
38#define LOG_LEVEL_DBG 4
39
40/* Each module's LOG_MODULE_REGISTER/DECLARE(name, ...) fixes a per-file tag. */
41#define LOG_MODULE_REGISTER(name, ...) \
42 static const char *const WOZ_LOG_TAG __attribute__((unused)) = #name
43#define LOG_MODULE_DECLARE(name, ...) \
44 static const char *const WOZ_LOG_TAG __attribute__((unused)) = #name
45
46#define LOG_ERR(...) ESP_LOGE(WOZ_LOG_TAG, __VA_ARGS__)
47#define LOG_WRN(...) ESP_LOGW(WOZ_LOG_TAG, __VA_ARGS__)
48#define LOG_INF(...) ESP_LOGI(WOZ_LOG_TAG, __VA_ARGS__)
49#define LOG_DBG(...) ESP_LOGD(WOZ_LOG_TAG, __VA_ARGS__)
50#define LOG_PRINTK(...) printf(__VA_ARGS__)
51
52#define LOG_HEXDUMP_ERR(p, l, s) ESP_LOG_BUFFER_HEX_LEVEL(WOZ_LOG_TAG, (p), (l), ESP_LOG_ERROR)
53#define LOG_HEXDUMP_WRN(p, l, s) ESP_LOG_BUFFER_HEX_LEVEL(WOZ_LOG_TAG, (p), (l), ESP_LOG_WARN)
54#define LOG_HEXDUMP_INF(p, l, s) ESP_LOG_BUFFER_HEX_LEVEL(WOZ_LOG_TAG, (p), (l), ESP_LOG_INFO)
55#define LOG_HEXDUMP_DBG(p, l, s) ESP_LOG_BUFFER_HEX_LEVEL(WOZ_LOG_TAG, (p), (l), ESP_LOG_DEBUG)
56
57#define woz_printf(...) printf(__VA_ARGS__)
58#ifndef printk
59#define printk(...) printf(__VA_ARGS__) /* see WOZ_PRINTK_COMPAT below */
60#endif
61
62#elif defined(WOZ_PORT_HOST)
63
64#include <stdio.h>
65
66#define LOG_LEVEL_NONE 0
67#define LOG_LEVEL_ERR 1
68#define LOG_LEVEL_WRN 2
69#define LOG_LEVEL_INF 3
70#define LOG_LEVEL_DBG 4
71
72/* Logging compiles out to no-ops off-target: log calls have no side effect a
73 * unit test observes. Matches the behaviour of the shim this replaces. */
74#define LOG_MODULE_REGISTER(...)
75#define LOG_MODULE_DECLARE(...)
76
77#define LOG_ERR(...) ((void)0)
78#define LOG_WRN(...) ((void)0)
79#define LOG_INF(...) ((void)0)
80#define LOG_DBG(...) ((void)0)
81#define LOG_PRINTK(...) ((void)0)
82
83#define LOG_HEXDUMP_ERR(...) ((void)0)
84#define LOG_HEXDUMP_WRN(...) ((void)0)
85#define LOG_HEXDUMP_INF(...) ((void)0)
86#define LOG_HEXDUMP_DBG(...) ((void)0)
87
88/* printk did map to stdio in the host shim, and some diagnostics are asserted
89 * on in test output, so keep woz_printf real here. */
90#define woz_printf(...) printf(__VA_ARGS__)
91#ifndef printk
92#define printk(...) printf(__VA_ARGS__) /* see WOZ_PRINTK_COMPAT below */
93#endif
94
95#else
96#error "woz_log.h: no platform backend. Define WOZ_PORT_HOST, or build under Zephyr/ESP-IDF."
97#endif
98
99#endif /* WOZ_LOG_H */