Andrew Boie | d5feec5 | 2015-09-18 09:57:13 -0700 | [diff] [blame] | 1 | /* ram_console.c - Console messages to a RAM buffer */ |
| 2 | |
| 3 | /* |
| 4 | * Copyright (c) 2015 Intel Corporation |
| 5 | * |
David B. Kinder | ac74d8b | 2017-01-18 17:01:01 -0800 | [diff] [blame] | 6 | * SPDX-License-Identifier: Apache-2.0 |
Andrew Boie | d5feec5 | 2015-09-18 09:57:13 -0700 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | |
Gerard Marull-Paretas | fb60aab | 2022-05-06 10:25:46 +0200 | [diff] [blame] | 10 | #include <zephyr/kernel.h> |
| 11 | #include <zephyr/sys/printk.h> |
| 12 | #include <zephyr/device.h> |
| 13 | #include <zephyr/init.h> |
Andrew Boie | d5feec5 | 2015-09-18 09:57:13 -0700 | [diff] [blame] | 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 | |
| 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 | |
Gerard Marull-Paretas | a5fd0d1 | 2022-10-19 09:33:44 +0200 | [diff] [blame] | 29 | static int ram_console_init(void) |
Andrew Boie | d5feec5 | 2015-09-18 09:57:13 -0700 | [diff] [blame] | 30 | { |
Andrew Boie | d5feec5 | 2015-09-18 09:57:13 -0700 | [diff] [blame] | 31 | __printk_hook_install(ram_console_out); |
| 32 | __stdout_hook_install(ram_console_out); |
| 33 | |
Andre Guedes | 024cfe7 | 2016-03-09 14:01:20 -0300 | [diff] [blame] | 34 | return 0; |
Andrew Boie | d5feec5 | 2015-09-18 09:57:13 -0700 | [diff] [blame] | 35 | } |
| 36 | |
Maureen Helm | 43fa7ce | 2021-10-21 13:29:33 -0500 | [diff] [blame] | 37 | SYS_INIT(ram_console_init, PRE_KERNEL_1, CONFIG_CONSOLE_INIT_PRIORITY); |