logging: rtt: Add overwrite mode

In this mode the oldest data is overwritten
when the buffer is full

Closes #36282

Signed-off-by: Guillaume Lager <g.lager@innoseis.com>
This commit is contained in:
Guillaume Lager 2021-08-19 13:56:39 +02:00 committed by Carles Cufí
commit a55a5b744d
2 changed files with 25 additions and 1 deletions

View file

@ -121,6 +121,12 @@ config LOG_BACKEND_RTT_SYST_ENABLE
help help
When enabled backend is using RTT to output syst format logs. When enabled backend is using RTT to output syst format logs.
config LOG_BACKEND_RTT_MODE_OVERWRITE
bool "Overwrite messages if up-buffer full"
help
If there is not enough space in up-buffer for a message overwrite
oldest one.
endchoice endchoice
config LOG_BACKEND_RTT_MESSAGE_SIZE config LOG_BACKEND_RTT_MESSAGE_SIZE

View file

@ -231,9 +231,27 @@ static int data_out_block_mode(uint8_t *data, size_t length, void *ctx)
return ((ret == 0) && host_present) ? 0 : length; return ((ret == 0) && host_present) ? 0 : length;
} }
static int data_out_overwrite_mode(uint8_t *data, size_t length, void *ctx)
{
if (!is_sync_mode()) {
RTT_LOCK();
}
SEGGER_RTT_WriteWithOverwriteNoLock(CONFIG_LOG_BACKEND_RTT_BUFFER,
data, length);
if (!is_sync_mode()) {
RTT_UNLOCK();
}
return length;
}
LOG_OUTPUT_DEFINE(log_output_rtt, LOG_OUTPUT_DEFINE(log_output_rtt,
IS_ENABLED(CONFIG_LOG_BACKEND_RTT_MODE_BLOCK) ? IS_ENABLED(CONFIG_LOG_BACKEND_RTT_MODE_BLOCK) ?
data_out_block_mode : data_out_drop_mode, data_out_block_mode :
IS_ENABLED(CONFIG_LOG_BACKEND_RTT_MODE_OVERWRITE) ?
data_out_overwrite_mode : data_out_drop_mode,
char_buf, sizeof(char_buf)); char_buf, sizeof(char_buf));
static void put(const struct log_backend *const backend, static void put(const struct log_backend *const backend,