Skip to content

logging: add backend for xtensa simulator #14027

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion samples/subsys/logging/logger/sample.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ sample:
tests:
samples.logger:
tags: logging
platform_exclude: qemu_xtensa qemu_x86_64
platform_exclude: qemu_x86_64
harness: console
harness_config:
type: one_line
Expand Down
3 changes: 3 additions & 0 deletions soc/xtensa/sample_controller/Kconfig.defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,7 @@ config IRQ_OFFLOAD_INTNUM
config XTENSA_ASM2
default y

config LOG_BACKEND_XTENSA_SIM
default LOG

endif
5 changes: 5 additions & 0 deletions subsys/logging/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ zephyr_sources_ifdef(
log_backend_native_posix.c
)

zephyr_sources_ifdef(
CONFIG_LOG_BACKEND_XTENSA_SIM
log_backend_xtensa_sim.c
)

zephyr_sources_ifdef(
CONFIG_LOG_BACKEND_NET
log_backend_net.c
Expand Down
19 changes: 17 additions & 2 deletions subsys/logging/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,21 @@ config LOG_BACKEND_NATIVE_POSIX
help
Enable backend in native_posix

config LOG_BACKEND_XTENSA_SIM
bool "Enable xtensa simulator backend"
depends on SOC_XTENSA_SAMPLE_CONTROLLER
help
Enable backend in xtensa simulator

if LOG_BACKEND_XTENSA_SIM
config LOG_BACKEND_XTENSA_OUTPUT_BUFFER_SIZE
int "Size of the output buffer"
default 16
help
Buffer is used by log_output module for preparing output data (e.g.
string formatting).
endif

config LOG_BACKEND_NET
bool "Enable networking backend"
depends on NETWORKING
Expand Down Expand Up @@ -488,15 +503,15 @@ endif # LOG_BACKEND_NET
config LOG_BACKEND_SHOW_COLOR
bool "Enable colors in the backend"
depends on LOG_BACKEND_UART || LOG_BACKEND_NATIVE_POSIX || LOG_BACKEND_RTT \
|| LOG_BACKEND_SWO
|| LOG_BACKEND_SWO || LOG_BACKEND_XTENSA_SIM
default y
help
When enabled selected backend prints errors in red and warning in yellow.

config LOG_BACKEND_FORMAT_TIMESTAMP
bool "Enable timestamp formatting in the backend"
depends on LOG_BACKEND_UART || LOG_BACKEND_NATIVE_POSIX || LOG_BACKEND_RTT \
|| LOG_BACKEND_SWO
|| LOG_BACKEND_SWO || LOG_BACKEND_XTENSA_SIM
default y
help
When enabled timestamp is formatted to hh:mm:ss:ms,us.
Expand Down
128 changes: 128 additions & 0 deletions subsys/logging/log_backend_xtensa_sim.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
/*
* Copyright (c) 2019 Intel Corporation Inc.
* Copyright (c) 2018 Nordic Semiconductor ASA
* Copyright (c) 2018 Intel Corporation
*
* SPDX-License-Identifier: Apache-2.0
*/

#include <stdio.h>
#include <stddef.h>
#include <logging/log_backend.h>
#include <logging/log_core.h>
#include <logging/log_msg.h>
#include <logging/log_output.h>
#include <xtensa/simcall.h>

#define CHAR_BUF_SIZE CONFIG_LOG_BACKEND_XTENSA_OUTPUT_BUFFER_SIZE

static u8_t buf[CHAR_BUF_SIZE];

static int char_out(u8_t *data, size_t length, void *ctx)
{
register int a1 __asm__ ("a2") = SYS_write;
register int b1 __asm__ ("a3") = 1;
register int c1 __asm__ ("a4") = (int) data;
register int d1 __asm__ ("a5") = length;
register int ret_val __asm__ ("a2");
register int ret_err __asm__ ("a3");

__asm__ __volatile__ (
"simcall\n"
"mov %0, a2\n"
"mov %1, a3\n"
: "=a" (ret_val), "=a" (ret_err), "+r"(a1), "+r"(b1)
: "r"(c1), "r"(d1)
: "memory");
return length;
}

LOG_OUTPUT_DEFINE(log_output, char_out, buf, sizeof(buf));

static void put(const struct log_backend *const backend,
struct log_msg *msg)
{
log_msg_get(msg);

u32_t flags = LOG_OUTPUT_FLAG_LEVEL | LOG_OUTPUT_FLAG_TIMESTAMP;

if (IS_ENABLED(CONFIG_LOG_BACKEND_SHOW_COLOR)) {
flags |= LOG_OUTPUT_FLAG_COLORS;
}

if (IS_ENABLED(CONFIG_LOG_BACKEND_FORMAT_TIMESTAMP)) {
flags |= LOG_OUTPUT_FLAG_FORMAT_TIMESTAMP;
}

log_output_msg_process(&log_output, msg, flags);

log_msg_put(msg);

}

static void panic(struct log_backend const *const backend)
{
log_output_flush(&log_output);
}

static void dropped(const struct log_backend *const backend, u32_t cnt)
{
ARG_UNUSED(backend);

log_output_dropped_process(&log_output, cnt);
}

static void sync_string(const struct log_backend *const backend,
struct log_msg_ids src_level, u32_t timestamp,
const char *fmt, va_list ap)
{
u32_t flags = LOG_OUTPUT_FLAG_LEVEL | LOG_OUTPUT_FLAG_TIMESTAMP;
u32_t key;

if (IS_ENABLED(CONFIG_LOG_BACKEND_SHOW_COLOR)) {
flags |= LOG_OUTPUT_FLAG_COLORS;
}

if (IS_ENABLED(CONFIG_LOG_BACKEND_FORMAT_TIMESTAMP)) {
flags |= LOG_OUTPUT_FLAG_FORMAT_TIMESTAMP;
}

key = irq_lock();
log_output_string(&log_output, src_level, timestamp, fmt, ap, flags);
irq_unlock(key);
}

static void sync_hexdump(const struct log_backend *const backend,
struct log_msg_ids src_level, u32_t timestamp,
const char *metadata, const u8_t *data, u32_t length)
{
u32_t flags = LOG_OUTPUT_FLAG_LEVEL | LOG_OUTPUT_FLAG_TIMESTAMP;
u32_t key;

if (IS_ENABLED(CONFIG_LOG_BACKEND_SHOW_COLOR)) {
flags |= LOG_OUTPUT_FLAG_COLORS;
}

if (IS_ENABLED(CONFIG_LOG_BACKEND_FORMAT_TIMESTAMP)) {
flags |= LOG_OUTPUT_FLAG_FORMAT_TIMESTAMP;
}

key = irq_lock();
log_output_hexdump(&log_output, src_level, timestamp,
metadata, data, length, flags);
irq_unlock(key);
}

const struct log_backend_api log_backend_xtensa_sim_api = {
.put = IS_ENABLED(CONFIG_LOG_IMMEDIATE) ? NULL : put,
.put_sync_string = IS_ENABLED(CONFIG_LOG_IMMEDIATE) ?
sync_string : NULL,
.put_sync_hexdump = IS_ENABLED(CONFIG_LOG_IMMEDIATE) ?
sync_hexdump : NULL,
.panic = panic,
.dropped = IS_ENABLED(CONFIG_LOG_IMMEDIATE) ? NULL : dropped,
};

LOG_BACKEND_DEFINE(log_backend_xtensa_sim,
log_backend_xtensa_sim_api,
true);