From dbf1d5d87d0edce4e2cf0820330a29e78899bdd5 Mon Sep 17 00:00:00 2001 From: Andrei Emeltchenko Date: Mon, 10 Feb 2020 13:23:07 +0200 Subject: [PATCH] logging: log_backend_rb: Make message buffer size configurable Make slot size configurable making it easy to use with other platforms. Signed-off-by: Andrei Emeltchenko --- subsys/logging/Kconfig | 10 +++++++++- subsys/logging/log_backend_rb.c | 35 ++++++++++++++++++++------------- 2 files changed, 30 insertions(+), 15 deletions(-) diff --git a/subsys/logging/Kconfig b/subsys/logging/Kconfig index 0b7aadbfcd4..16af3f7a78e 100644 --- a/subsys/logging/Kconfig +++ b/subsys/logging/Kconfig @@ -513,7 +513,15 @@ config LOG_BACKEND_RB_MEM_BASE config LOG_BACKEND_RB_MEM_SIZE hex "Size of the ring buffer" help - Size of the ring buffer. + Size of the ring buffer. Must be multiply of the message slot + size. + +config LOG_BACKEND_RB_SLOT_SIZE + int "Size of the message slot" + default 64 + help + Size of the message slot inside ring buffer. All log messages + are split to similar sized logging slots. endif # LOG_BACKEND_RB diff --git a/subsys/logging/log_backend_rb.c b/subsys/logging/log_backend_rb.c index 4ad6c5db7bc..bed43201740 100644 --- a/subsys/logging/log_backend_rb.c +++ b/subsys/logging/log_backend_rb.c @@ -10,19 +10,24 @@ #include #include -#define BUF_SIZE 64 - -BUILD_ASSERT(CONFIG_LOG_BACKEND_RB_MEM_SIZE % BUF_SIZE == 0); - static struct ring_buf ringbuf; /* * Log message format: * Logging started with magic number 0x55aa followed by log message id. - * Log message ended with null terminator and takes BUF_SIZE slot. The - * long log message can occupy several logging slots. + * Log message ended with null terminator and takes + * CONFIG_LOG_BACKEND_RB_SLOT_SIZE slot. The long log message can occupy + * several logging slots. */ +/* + * All log messages are split to similar sized logging slots. Since ring + * buffer slots get rewritten we need to check that all slots are fit to + * the ring buffer + */ +BUILD_ASSERT(CONFIG_LOG_BACKEND_RB_MEM_SIZE % + CONFIG_LOG_BACKEND_RB_SLOT_SIZE == 0); + static void init(void) { ring_buf_init(&ringbuf, CONFIG_LOG_BACKEND_RB_MEM_SIZE, @@ -38,15 +43,17 @@ static void trace(const u8_t *data, size_t length) int i; space = ring_buf_space_get(&ringbuf); - if (space < BUF_SIZE) { + if (space < CONFIG_LOG_BACKEND_RB_SLOT_SIZE) { u8_t *dummy; /* Remove oldest entry */ - ring_buf_get_claim(&ringbuf, &dummy, BUF_SIZE); - ring_buf_get_finish(&ringbuf, BUF_SIZE); + ring_buf_get_claim(&ringbuf, &dummy, + CONFIG_LOG_BACKEND_RB_SLOT_SIZE); + ring_buf_get_finish(&ringbuf, CONFIG_LOG_BACKEND_RB_SLOT_SIZE); } - ring_buf_put_claim(&ringbuf, (u8_t **)&t, BUF_SIZE); + ring_buf_put_claim(&ringbuf, (u8_t **)&t, + CONFIG_LOG_BACKEND_RB_SLOT_SIZE); region = t; /* Add magic number at the beginning of the slot */ @@ -57,13 +64,13 @@ static void trace(const u8_t *data, size_t length) *(u16_t *)t = log_id++; t += 2; - for (i = 0; i < MIN(length, BUF_SIZE - 4); i++) { + for (i = 0; i < MIN(length, CONFIG_LOG_BACKEND_RB_SLOT_SIZE - 4); i++) { *t++ = data[i]; } - SOC_DCACHE_FLUSH((void *)region, BUF_SIZE); + SOC_DCACHE_FLUSH((void *)region, CONFIG_LOG_BACKEND_RB_SLOT_SIZE); - ring_buf_put_finish(&ringbuf, BUF_SIZE); + ring_buf_put_finish(&ringbuf, CONFIG_LOG_BACKEND_RB_SLOT_SIZE); } static int char_out(u8_t *data, size_t length, void *ctx) @@ -74,7 +81,7 @@ static int char_out(u8_t *data, size_t length, void *ctx) } /* magic and log id takes space */ -static u8_t buf[BUF_SIZE - 4]; +static u8_t buf[CONFIG_LOG_BACKEND_RB_SLOT_SIZE - 4]; LOG_OUTPUT_DEFINE(log_output, char_out, buf, sizeof(buf));