Commit 209568ea authored by Hou Zhiqiang's avatar Hou Zhiqiang Committed by David Leach
Browse files

driver: ram_console: leave one byte from the defined buffer size



Leave one byte from the CONFIG_RAM_CONSOLE_BUFFER_SIZE to ensure
the NULL-termination.

Signed-off-by: default avatarHou Zhiqiang <Zhiqiang.Hou@nxp.com>
parent c1765ff6
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -108,8 +108,10 @@ config RAM_CONSOLE_BUFFER_SIZE
	default 1024
	depends on RAM_CONSOLE
	help
	  Size of the RAM console buffer. Messages will wrap around if the
	  length is exceeded.
	  Total size of the RAM console buffer, to ensure it's always
	  NULL-terminated leave one byte unused, the actual length is
	  one byte less. Messages will wrap around if the actual length
	  is exceeded.

config RTT_CONSOLE
	bool "Use RTT console"
+3 −3
Original line number Diff line number Diff line
@@ -15,14 +15,14 @@
extern void __printk_hook_install(int (*fn)(int));
extern void __stdout_hook_install(int (*fn)(int));

/* Extra byte to ensure we're always NULL-terminated */
char ram_console[CONFIG_RAM_CONSOLE_BUFFER_SIZE + 1];
char ram_console[CONFIG_RAM_CONSOLE_BUFFER_SIZE];
static int pos;

static int ram_console_out(int character)
{
	ram_console[pos] = (char)character;
	pos = (pos + 1) % CONFIG_RAM_CONSOLE_BUFFER_SIZE;
	/* Leave one byte to ensure we're always NULL-terminated */
	pos = (pos + 1) % (CONFIG_RAM_CONSOLE_BUFFER_SIZE - 1);
	return character;
}

+1 −1
Original line number Diff line number Diff line
@@ -68,7 +68,7 @@ static struct fw_resource_table __resource resource_table = {
#if defined(CONFIG_RAM_CONSOLE)
	.cm_trace = {
		RSC_TRACE,
		(uint32_t)ram_console, CONFIG_RAM_CONSOLE_BUFFER_SIZE + 1, 0,
		(uint32_t)ram_console, CONFIG_RAM_CONSOLE_BUFFER_SIZE, 0,
		"Zephyr_log",
	},
#endif