ramlog: Add overwrite option to ramlog

Enable overwrite of circular buffer. If RAMLOG buffer overflows,
overwrite it from the top of buffer and always keep the latest log.
This commit is contained in:
SPRESENSE 2020-07-28 16:29:43 +09:00 committed by Xiang Xiao
parent e249a2f82f
commit 27835c8c0a
2 changed files with 17 additions and 0 deletions

View File

@ -59,6 +59,13 @@ config RAMLOG_NPOLLWAITERS
---help---
The maximum number of threads that may be waiting on the poll method.
config RAMLOG_OVERWRITE
bool "RAMLOG overwrite circular buffer"
default n
---help---
Enable overwrite of circular buffer. If RAMLOG buffer overflows,
overwrite it from the top of buffer and always keep the latest log.
endif
config DRIVER_NOTE

View File

@ -227,10 +227,20 @@ static ssize_t ramlog_addchar(FAR struct ramlog_dev_s *priv, char ch)
if (nexthead == priv->rl_tail)
{
#ifdef CONFIG_RAMLOG_OVERWRITE
/* Yes... Overwrite with the latest log in the circular buffer */
priv->rl_tail += 1;
if (priv->rl_tail >= priv->rl_bufsize)
{
priv->rl_tail = 0;
}
#else
/* Yes... Return an indication that nothing was saved in the buffer. */
leave_critical_section(flags);
return -EBUSY;
#endif
}
/* No... copy the byte and re-enable interrupts */