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