Skip to content
Permalink
Browse files

logging: Removing redundant code from SWO backend

Refactored SWO backend to use standard backend functions

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
  • Loading branch information...
nordic-krch authored and nashif committed Jul 17, 2019
1 parent 9768f78 commit 65b47f89c25ba22cd758802f409e9077d8cc9650
Showing with 14 additions and 44 deletions.
  1. +14 −44 subsys/logging/log_backend_swo.c
@@ -26,6 +26,7 @@
#include <logging/log_core.h>
#include <logging/log_msg.h>
#include <logging/log_output.h>
#include "log_backend_std.h"
#include <soc.h>

/** The stimulus port from which SWO data is received and displayed */
@@ -63,21 +64,7 @@ LOG_OUTPUT_DEFINE(log_output, char_out, buf, sizeof(buf));
static void log_backend_swo_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);
log_backend_std_put(&log_output, 0, msg);
}

static void log_backend_swo_init(void)
@@ -110,46 +97,28 @@ static void log_backend_swo_panic(struct log_backend const *const backend)
{
}

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

log_backend_std_dropped(&log_output, cnt);
}

static void log_backend_swo_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);
log_backend_std_sync_string(&log_output, 0, src_level,
timestamp, fmt, ap);
}

static void log_backend_swo_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);
log_backend_std_sync_hexdump(&log_output, 0, src_level,
timestamp, metadata, data, length);
}

const struct log_backend_api log_backend_swo_api = {
@@ -160,6 +129,7 @@ const struct log_backend_api log_backend_swo_api = {
log_backend_swo_sync_hexdump : NULL,
.panic = log_backend_swo_panic,
.init = log_backend_swo_init,
.dropped = IS_ENABLED(CONFIG_LOG_IMMEDIATE) ? NULL : dropped,
};

LOG_BACKEND_DEFINE(log_backend_swo, log_backend_swo_api, true);

0 comments on commit 65b47f8

Please sign in to comment.
You can’t perform that action at this time.