From 4f25c287d206289a92a3ac588e4d4cfa5557f298 Mon Sep 17 00:00:00 2001 From: yinshengkai Date: Mon, 21 Aug 2023 11:33:01 +0800 Subject: [PATCH] arch/sim: add sim uart_ram support Signed-off-by: yinshengkai --- arch/sim/Kconfig | 49 +++++++++++++++++++++++++++++++++++++ arch/sim/src/sim/sim_uart.c | 41 +++++++++++++++++++++++++++++++ 2 files changed, 90 insertions(+) diff --git a/arch/sim/Kconfig b/arch/sim/Kconfig index c55d729f1d..05d379f627 100644 --- a/arch/sim/Kconfig +++ b/arch/sim/Kconfig @@ -625,6 +625,55 @@ config SIM_UART3_NAME A UART port must also exist on the host system with the exact same name specified here. +config SIM_RAM_UART + bool "SIM RAM UART Device" + depends on RAM_UART + default n + ---help--- + SIM RAM UART. It emulates a UART device but using a RAM memory + instead a physical peripheral. + +if SIM_RAM_UART +config SIM_RAM_UART0 + bool "SIM RAM UART Device 0" + default n + ---help--- + sim ram uart device 0 + +config SIM_RAM_UART0_SLAVE + bool "SIM_RAM_UART0 is slave" + depends on SIM_RAM_UART0 + default n + ---help--- + The sim ram uart0 is slave + +config SIM_RAM_UART1 + bool "SIM RAM UART Device 1" + default n + ---help--- + sim ram uart device 1 + +config SIM_RAM_UART1_SLAVE + bool "SIM_RAM_UART1 is slave" + depends on SIM_RAM_UART1 + default n + ---help--- + The sim ram uart1 is slave + +config SIM_RAM_UART2 + bool "SIM RAM UART Device 2" + default n + ---help--- + sim ram uart device 2 + +config SIM_RAM_UART2_SLAVE + bool "SIM_RAM_UART2 is slave" + depends on SIM_RAM_UART2 + default n + ---help--- + The sim ram uart2 is slave +endif + endmenu config SIM_USB_DEV diff --git a/arch/sim/src/sim/sim_uart.c b/arch/sim/src/sim/sim_uart.c index fbd42a6e41..2d4b04bb3a 100644 --- a/arch/sim/src/sim/sim_uart.c +++ b/arch/sim/src/sim/sim_uart.c @@ -25,7 +25,9 @@ #include #include #include +#include #include +#include #include #include #include @@ -666,6 +668,21 @@ static bool tty_txempty(struct uart_dev_s *dev) } #endif +#ifdef CONFIG_SIM_RAM_UART +static int sim_uartram_register(FAR const char *devname, bool slave) +{ + char name[NAME_MAX]; + FAR struct uart_rambuf_s *shmem; + + strlcpy(name, strrchr(devname, '/') + 1, NAME_MAX); + shmem = host_allocshmem(name, sizeof(struct uart_rambuf_s) * 2, !slave); + DEBUGASSERT(shmem); + + memset(shmem, 0, sizeof(struct uart_rambuf_s) * 2); + return uart_ram_register(devname, shmem, slave); +} +#endif + /**************************************************************************** * Public Functions ****************************************************************************/ @@ -676,6 +693,30 @@ static bool tty_txempty(struct uart_dev_s *dev) void sim_uartinit(void) { +#ifdef CONFIG_SIM_RAM_UART0 +# ifdef CONFIG_SIM_RAM_UART0_SLAVE + sim_uartram_register("/dev/ttyVS0", true); +# else + sim_uartram_register("/dev/ttyVS0", false); +# endif +#endif + +#ifdef CONFIG_SIM_RAM_UART1 +# ifdef CONFIG_SIM_RAM_UART1_SLAVE + sim_uartram_register("/dev/ttyVS1", true); +# else + sim_uartram_register("/dev/ttyVS1", false); +# endif +#endif + +#ifdef CONFIG_SIM_RAM_UART2 +# ifdef CONFIG_SIM_RAM_UART2_SLAVE + sim_uartram_register("/dev/ttyVS2", true); +# else + sim_uartram_register("/dev/ttyVS2", false); +# endif +#endif + #ifdef USE_DEVCONSOLE /* Start the simulated UART device */