From d915fa0c35a25e66aaf967ac9abc4bd42160d525 Mon Sep 17 00:00:00 2001 From: Krzysztof Chruscinski Date: Wed, 13 Mar 2019 08:21:00 +0100 Subject: [PATCH] logging: rtt: Fix backend behavior when LOG_IMMEDIATE enabled Backend was not initialized to work in synchronous mode if LOG_IMMEDIATE was enabled. That causes use of rtt_lock which uses mutex. That lead to assert in application. Signed-off-by: Krzysztof Chruscinski --- subsys/logging/log_backend_rtt.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/subsys/logging/log_backend_rtt.c b/subsys/logging/log_backend_rtt.c index 2a281175b98..d02ead954f0 100644 --- a/subsys/logging/log_backend_rtt.c +++ b/subsys/logging/log_backend_rtt.c @@ -51,8 +51,7 @@ static u8_t *line_pos; static u8_t char_buf[CHAR_BUF_SIZE]; static int drop_cnt; static int drop_warn; -static int panic_mode; - +static bool sync_mode; static bool host_present; static int data_out_block_mode(u8_t *data, size_t length, void *ctx); @@ -66,7 +65,7 @@ static int data_out_drop_mode(u8_t *data, size_t length, void *ctx) (void) ctx; u8_t *pos; - if (panic_mode) { + if (sync_mode) { return data_out_block_mode(data, length, ctx); } @@ -142,7 +141,7 @@ static void on_failed_write(int retry_cnt) { if (retry_cnt == 0) { host_present = false; - } else if (panic_mode) { + } else if (sync_mode) { k_busy_wait(USEC_PER_MSEC * RETRY_DELAY_MS); } else { k_sleep(RETRY_DELAY_MS); @@ -152,7 +151,7 @@ static void on_failed_write(int retry_cnt) static void on_write(int retry_cnt) { host_present = true; - if (panic_mode) { + if (sync_mode) { /* In panic mode block on each write until host reads it. This * way it is ensured that if system resets all messages are read * by the host. While pending on data being read by the host we @@ -172,14 +171,14 @@ static int data_out_block_mode(u8_t *data, size_t length, void *ctx) int retry_cnt = RETRY_CNT; do { - if (!panic_mode) { + if (!sync_mode) { RTT_LOCK(); } ret = SEGGER_RTT_WriteSkipNoLock(CONFIG_LOG_BACKEND_RTT_BUFFER, data, length); - if (!panic_mode) { + if (!sync_mode) { RTT_UNLOCK(); } @@ -232,14 +231,14 @@ static void log_backend_rtt_init(void) } host_present = true; - panic_mode = 0; + sync_mode = IS_ENABLED(CONFIG_LOG_IMMEDIATE) ? true : false; line_pos = line_buf; } static void panic(struct log_backend const *const backend) { log_output_flush(&log_output); - panic_mode = 1; + sync_mode = true; } static void dropped(const struct log_backend *const backend, u32_t cnt)