Skip to content

Commit 4f25c28

Browse files
Gary-Hobsonxiaoxiang781216
authored andcommitted
arch/sim: add sim uart_ram support
Signed-off-by: yinshengkai <yinshengkai@xiaomi.com>
1 parent d827ee5 commit 4f25c28

File tree

2 files changed

+90
-0
lines changed

2 files changed

+90
-0
lines changed

arch/sim/Kconfig

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -625,6 +625,55 @@ config SIM_UART3_NAME
625625
A UART port must also exist on the host system
626626
with the exact same name specified here.
627627

628+
config SIM_RAM_UART
629+
bool "SIM RAM UART Device"
630+
depends on RAM_UART
631+
default n
632+
---help---
633+
SIM RAM UART. It emulates a UART device but using a RAM memory
634+
instead a physical peripheral.
635+
636+
if SIM_RAM_UART
637+
config SIM_RAM_UART0
638+
bool "SIM RAM UART Device 0"
639+
default n
640+
---help---
641+
sim ram uart device 0
642+
643+
config SIM_RAM_UART0_SLAVE
644+
bool "SIM_RAM_UART0 is slave"
645+
depends on SIM_RAM_UART0
646+
default n
647+
---help---
648+
The sim ram uart0 is slave
649+
650+
config SIM_RAM_UART1
651+
bool "SIM RAM UART Device 1"
652+
default n
653+
---help---
654+
sim ram uart device 1
655+
656+
config SIM_RAM_UART1_SLAVE
657+
bool "SIM_RAM_UART1 is slave"
658+
depends on SIM_RAM_UART1
659+
default n
660+
---help---
661+
The sim ram uart1 is slave
662+
663+
config SIM_RAM_UART2
664+
bool "SIM RAM UART Device 2"
665+
default n
666+
---help---
667+
sim ram uart device 2
668+
669+
config SIM_RAM_UART2_SLAVE
670+
bool "SIM_RAM_UART2 is slave"
671+
depends on SIM_RAM_UART2
672+
default n
673+
---help---
674+
The sim ram uart2 is slave
675+
endif
676+
628677
endmenu
629678

630679
config SIM_USB_DEV

arch/sim/src/sim/sim_uart.c

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@
2525
#include <nuttx/config.h>
2626
#include <nuttx/serial/serial.h>
2727
#include <nuttx/fs/ioctl.h>
28+
#include <nuttx/serial/uart_ram.h>
2829
#include <nuttx/wqueue.h>
30+
#include <string.h>
2931
#include <sys/types.h>
3032
#include <fcntl.h>
3133
#include <errno.h>
@@ -666,6 +668,21 @@ static bool tty_txempty(struct uart_dev_s *dev)
666668
}
667669
#endif
668670

671+
#ifdef CONFIG_SIM_RAM_UART
672+
static int sim_uartram_register(FAR const char *devname, bool slave)
673+
{
674+
char name[NAME_MAX];
675+
FAR struct uart_rambuf_s *shmem;
676+
677+
strlcpy(name, strrchr(devname, '/') + 1, NAME_MAX);
678+
shmem = host_allocshmem(name, sizeof(struct uart_rambuf_s) * 2, !slave);
679+
DEBUGASSERT(shmem);
680+
681+
memset(shmem, 0, sizeof(struct uart_rambuf_s) * 2);
682+
return uart_ram_register(devname, shmem, slave);
683+
}
684+
#endif
685+
669686
/****************************************************************************
670687
* Public Functions
671688
****************************************************************************/
@@ -676,6 +693,30 @@ static bool tty_txempty(struct uart_dev_s *dev)
676693

677694
void sim_uartinit(void)
678695
{
696+
#ifdef CONFIG_SIM_RAM_UART0
697+
# ifdef CONFIG_SIM_RAM_UART0_SLAVE
698+
sim_uartram_register("/dev/ttyVS0", true);
699+
# else
700+
sim_uartram_register("/dev/ttyVS0", false);
701+
# endif
702+
#endif
703+
704+
#ifdef CONFIG_SIM_RAM_UART1
705+
# ifdef CONFIG_SIM_RAM_UART1_SLAVE
706+
sim_uartram_register("/dev/ttyVS1", true);
707+
# else
708+
sim_uartram_register("/dev/ttyVS1", false);
709+
# endif
710+
#endif
711+
712+
#ifdef CONFIG_SIM_RAM_UART2
713+
# ifdef CONFIG_SIM_RAM_UART2_SLAVE
714+
sim_uartram_register("/dev/ttyVS2", true);
715+
# else
716+
sim_uartram_register("/dev/ttyVS2", false);
717+
# endif
718+
#endif
719+
679720
#ifdef USE_DEVCONSOLE
680721
/* Start the simulated UART device */
681722

0 commit comments

Comments
 (0)