1 /* ram_console.c - Console messages to a RAM buffer */
2 
3 /*
4  * Copyright (c) 2015 Intel Corporation
5  *
6  * SPDX-License-Identifier: Apache-2.0
7  */
8 
9 
10 #include <zephyr/kernel.h>
11 #include <zephyr/sys/printk.h>
12 #include <zephyr/device.h>
13 #include <zephyr/init.h>
14 
15 extern void __printk_hook_install(int (*fn)(int));
16 extern void __stdout_hook_install(int (*fn)(int));
17 
18 /* Extra byte to ensure we're always NULL-terminated */
19 char ram_console[CONFIG_RAM_CONSOLE_BUFFER_SIZE + 1];
20 static int pos;
21 
ram_console_out(int character)22 static int ram_console_out(int character)
23 {
24 	ram_console[pos] = (char)character;
25 	pos = (pos + 1) % CONFIG_RAM_CONSOLE_BUFFER_SIZE;
26 	return character;
27 }
28 
ram_console_init(void)29 static int ram_console_init(void)
30 {
31 	__printk_hook_install(ram_console_out);
32 	__stdout_hook_install(ram_console_out);
33 
34 	return 0;
35 }
36 
37 SYS_INIT(ram_console_init, PRE_KERNEL_1, CONFIG_CONSOLE_INIT_PRIORITY);
38