Skip to content

Commit f3802a7

Browse files
committed
logging: add backend for xtensa simulator
Add backend for the xtensa simulator. Fixes zephyrproject-rtos#10164 Signed-off-by: Anas Nashif <[email protected]>
1 parent 605ae10 commit f3802a7

File tree

5 files changed

+154
-3
lines changed

5 files changed

+154
-3
lines changed

samples/subsys/logging/logger/sample.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ sample:
55
tests:
66
samples.logger:
77
tags: logging
8-
platform_exclude: qemu_xtensa qemu_x86_64
8+
platform_exclude: qemu_x86_64
99
harness: console
1010
harness_config:
1111
type: one_line

soc/xtensa/sample_controller/Kconfig.defconfig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,7 @@ config IRQ_OFFLOAD_INTNUM
1616
config XTENSA_ASM2
1717
default y
1818

19+
config LOG_BACKEND_XTENSA_SIM
20+
default LOG
21+
1922
endif

subsys/logging/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ zephyr_sources_ifdef(
2424
log_backend_native_posix.c
2525
)
2626

27+
zephyr_sources_ifdef(
28+
CONFIG_LOG_BACKEND_XTENSA_SIM
29+
log_backend_xtensa_sim.c
30+
)
31+
2732
zephyr_sources_ifdef(
2833
CONFIG_LOG_BACKEND_NET
2934
log_backend_net.c

subsys/logging/Kconfig

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,21 @@ config LOG_BACKEND_NATIVE_POSIX
438438
help
439439
Enable backend in native_posix
440440

441+
config LOG_BACKEND_XTENSA_SIM
442+
bool "Enable xtensa simulator backend"
443+
depends on SOC_XTENSA_SAMPLE_CONTROLLER
444+
help
445+
Enable backend in xtensa simulator
446+
447+
if LOG_BACKEND_XTENSA_SIM
448+
config LOG_BACKEND_XTENSA_OUTPUT_BUFFER_SIZE
449+
int "Size of the output buffer"
450+
default 16
451+
help
452+
Buffer is used by log_output module for preparing output data (e.g.
453+
string formatting).
454+
endif
455+
441456
config LOG_BACKEND_NET
442457
bool "Enable networking backend"
443458
depends on NETWORKING
@@ -488,15 +503,15 @@ endif # LOG_BACKEND_NET
488503
config LOG_BACKEND_SHOW_COLOR
489504
bool "Enable colors in the backend"
490505
depends on LOG_BACKEND_UART || LOG_BACKEND_NATIVE_POSIX || LOG_BACKEND_RTT \
491-
|| LOG_BACKEND_SWO
506+
|| LOG_BACKEND_SWO || LOG_BACKEND_XTENSA_SIM
492507
default y
493508
help
494509
When enabled selected backend prints errors in red and warning in yellow.
495510

496511
config LOG_BACKEND_FORMAT_TIMESTAMP
497512
bool "Enable timestamp formatting in the backend"
498513
depends on LOG_BACKEND_UART || LOG_BACKEND_NATIVE_POSIX || LOG_BACKEND_RTT \
499-
|| LOG_BACKEND_SWO
514+
|| LOG_BACKEND_SWO || LOG_BACKEND_XTENSA_SIM
500515
default y
501516
help
502517
When enabled timestamp is formatted to hh:mm:ss:ms,us.
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
/*
2+
* Copyright (c) 2019 Intel Corporation Inc.
3+
* Copyright (c) 2018 Nordic Semiconductor ASA
4+
* Copyright (c) 2018 Intel Corporation
5+
*
6+
* SPDX-License-Identifier: Apache-2.0
7+
*/
8+
9+
#include <stdio.h>
10+
#include <stddef.h>
11+
#include <logging/log_backend.h>
12+
#include <logging/log_core.h>
13+
#include <logging/log_msg.h>
14+
#include <logging/log_output.h>
15+
#include <xtensa/simcall.h>
16+
17+
#define CHAR_BUF_SIZE CONFIG_LOG_BACKEND_XTENSA_OUTPUT_BUFFER_SIZE
18+
19+
static u8_t buf[CHAR_BUF_SIZE];
20+
21+
static int char_out(u8_t *data, size_t length, void *ctx)
22+
{
23+
register int a1 __asm__ ("a2") = SYS_write;
24+
register int b1 __asm__ ("a3") = 1;
25+
register int c1 __asm__ ("a4") = (int) data;
26+
register int d1 __asm__ ("a5") = length;
27+
register int ret_val __asm__ ("a2");
28+
register int ret_err __asm__ ("a3");
29+
30+
__asm__ __volatile__ (
31+
"simcall\n"
32+
"mov %0, a2\n"
33+
"mov %1, a3\n"
34+
: "=a" (ret_val), "=a" (ret_err), "+r"(a1), "+r"(b1)
35+
: "r"(c1), "r"(d1)
36+
: "memory");
37+
return length;
38+
}
39+
40+
LOG_OUTPUT_DEFINE(log_output, char_out, buf, sizeof(buf));
41+
42+
static void put(const struct log_backend *const backend,
43+
struct log_msg *msg)
44+
{
45+
log_msg_get(msg);
46+
47+
u32_t flags = LOG_OUTPUT_FLAG_LEVEL | LOG_OUTPUT_FLAG_TIMESTAMP;
48+
49+
if (IS_ENABLED(CONFIG_LOG_BACKEND_SHOW_COLOR)) {
50+
flags |= LOG_OUTPUT_FLAG_COLORS;
51+
}
52+
53+
if (IS_ENABLED(CONFIG_LOG_BACKEND_FORMAT_TIMESTAMP)) {
54+
flags |= LOG_OUTPUT_FLAG_FORMAT_TIMESTAMP;
55+
}
56+
57+
log_output_msg_process(&log_output, msg, flags);
58+
59+
log_msg_put(msg);
60+
61+
}
62+
63+
static void panic(struct log_backend const *const backend)
64+
{
65+
log_output_flush(&log_output);
66+
}
67+
68+
static void dropped(const struct log_backend *const backend, u32_t cnt)
69+
{
70+
ARG_UNUSED(backend);
71+
72+
log_output_dropped_process(&log_output, cnt);
73+
}
74+
75+
static void sync_string(const struct log_backend *const backend,
76+
struct log_msg_ids src_level, u32_t timestamp,
77+
const char *fmt, va_list ap)
78+
{
79+
u32_t flags = LOG_OUTPUT_FLAG_LEVEL | LOG_OUTPUT_FLAG_TIMESTAMP;
80+
u32_t key;
81+
82+
if (IS_ENABLED(CONFIG_LOG_BACKEND_SHOW_COLOR)) {
83+
flags |= LOG_OUTPUT_FLAG_COLORS;
84+
}
85+
86+
if (IS_ENABLED(CONFIG_LOG_BACKEND_FORMAT_TIMESTAMP)) {
87+
flags |= LOG_OUTPUT_FLAG_FORMAT_TIMESTAMP;
88+
}
89+
90+
key = irq_lock();
91+
log_output_string(&log_output, src_level, timestamp, fmt, ap, flags);
92+
irq_unlock(key);
93+
}
94+
95+
static void sync_hexdump(const struct log_backend *const backend,
96+
struct log_msg_ids src_level, u32_t timestamp,
97+
const char *metadata, const u8_t *data, u32_t length)
98+
{
99+
u32_t flags = LOG_OUTPUT_FLAG_LEVEL | LOG_OUTPUT_FLAG_TIMESTAMP;
100+
u32_t key;
101+
102+
if (IS_ENABLED(CONFIG_LOG_BACKEND_SHOW_COLOR)) {
103+
flags |= LOG_OUTPUT_FLAG_COLORS;
104+
}
105+
106+
if (IS_ENABLED(CONFIG_LOG_BACKEND_FORMAT_TIMESTAMP)) {
107+
flags |= LOG_OUTPUT_FLAG_FORMAT_TIMESTAMP;
108+
}
109+
110+
key = irq_lock();
111+
log_output_hexdump(&log_output, src_level, timestamp,
112+
metadata, data, length, flags);
113+
irq_unlock(key);
114+
}
115+
116+
const struct log_backend_api log_backend_xtensa_sim_api = {
117+
.put = IS_ENABLED(CONFIG_LOG_IMMEDIATE) ? NULL : put,
118+
.put_sync_string = IS_ENABLED(CONFIG_LOG_IMMEDIATE) ?
119+
sync_string : NULL,
120+
.put_sync_hexdump = IS_ENABLED(CONFIG_LOG_IMMEDIATE) ?
121+
sync_hexdump : NULL,
122+
.panic = panic,
123+
.dropped = IS_ENABLED(CONFIG_LOG_IMMEDIATE) ? NULL : dropped,
124+
};
125+
126+
LOG_BACKEND_DEFINE(log_backend_xtensa_sim,
127+
log_backend_xtensa_sim_api,
128+
true);

0 commit comments

Comments
 (0)