arch/sim: add sim uart_ram support
Signed-off-by: yinshengkai <yinshengkai@xiaomi.com>
This commit is contained in:
parent
d827ee5ffc
commit
4f25c287d2
|
@ -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
|
||||
|
|
|
@ -25,7 +25,9 @@
|
|||
#include <nuttx/config.h>
|
||||
#include <nuttx/serial/serial.h>
|
||||
#include <nuttx/fs/ioctl.h>
|
||||
#include <nuttx/serial/uart_ram.h>
|
||||
#include <nuttx/wqueue.h>
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
|
@ -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 */
|
||||
|
||||
|
|
Loading…
Reference in New Issue