1 /*
2 * Copyright (c) 2019 Intel Corporation.
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7 #include <zephyr/sys/printk.h>
8 #include <ctype.h>
9 #include <zephyr/logging/log.h>
10 #include <zephyr/sys/printk.h>
11 #include <zephyr/llext/symbol.h>
12
13 #define HEXDUMP_BYTES_IN_LINE 8U
14
z_log_minimal_printk(const char * fmt,...)15 void z_log_minimal_printk(const char *fmt, ...)
16 {
17 va_list ap;
18
19 va_start(ap, fmt);
20 vprintk(fmt, ap);
21 va_end(ap);
22 }
23 EXPORT_SYMBOL(z_log_minimal_printk);
24
z_log_minimal_vprintk(const char * fmt,va_list ap)25 void z_log_minimal_vprintk(const char *fmt, va_list ap)
26 {
27 vprintk(fmt, ap);
28 }
29
minimal_hexdump_line_print(const char * data,size_t length)30 static void minimal_hexdump_line_print(const char *data, size_t length)
31 {
32 for (size_t i = 0U; i < HEXDUMP_BYTES_IN_LINE; i++) {
33 if (i < length) {
34 printk("%02x ", (unsigned char)data[i] & 0xFFu);
35 } else {
36 printk(" ");
37 }
38 }
39
40 printk("|");
41
42 for (size_t i = 0U; i < HEXDUMP_BYTES_IN_LINE; i++) {
43 if (i < length) {
44 unsigned char c = data[i];
45
46 printk("%c", (isprint((int)c) != 0) ? c : '.');
47 } else {
48 printk(" ");
49 }
50 }
51 printk("\n");
52 }
53
z_log_minimal_hexdump_print(int level,const void * data,size_t size)54 void z_log_minimal_hexdump_print(int level, const void *data, size_t size)
55 {
56 const char *data_buffer = (const char *)data;
57 while (size > 0U) {
58 printk("%c: ", z_log_minimal_level_to_char(level));
59 minimal_hexdump_line_print(data_buffer, size);
60
61 if (size < HEXDUMP_BYTES_IN_LINE) {
62 break;
63 }
64
65 size -= HEXDUMP_BYTES_IN_LINE;
66 data_buffer += HEXDUMP_BYTES_IN_LINE;
67 }
68 }
69