You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by xi...@apache.org on 2024/09/28 05:53:12 UTC
(nuttx) branch master updated (0fb1dc2b93 -> 065046b2a2)
This is an automated email from the ASF dual-hosted git repository.
xiaoxiang pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git
from 0fb1dc2b93 drivers/pipes: using rmutex to protect pipe and avoid deadlock
new b6225676f4 xtensa: hostfs: handle nonblock open for iss
new 065046b2a2 serial: use hostfs read/write on stdio as uart
The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
arch/xtensa/Kconfig | 8 +
arch/xtensa/include/simcall.h | 5 +
arch/xtensa/src/common/xtensa_hostfs.c | 5 +
drivers/drivers_initialize.c | 5 +
drivers/serial/Kconfig | 27 ++
drivers/serial/Make.defs | 4 +
drivers/serial/uart_hostfs.c | 302 +++++++++++++++++++++
.../userfs.h => include/nuttx/serial/uart_hostfs.h | 17 +-
8 files changed, 366 insertions(+), 7 deletions(-)
create mode 100644 drivers/serial/uart_hostfs.c
copy fs/userfs/userfs.h => include/nuttx/serial/uart_hostfs.h (84%)
(nuttx) 01/02: xtensa: hostfs: handle nonblock open for iss
Posted by xi...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit b6225676f4e49cecf88d28be73976a2d69503b19
Author: chenxiaoyi <ch...@xiaomi.com>
AuthorDate: Fri May 10 14:33:13 2024 +0800
xtensa: hostfs: handle nonblock open for iss
Signed-off-by: chenxiaoyi <ch...@xiaomi.com>
---
arch/xtensa/Kconfig | 8 ++++++++
arch/xtensa/include/simcall.h | 5 +++++
arch/xtensa/src/common/xtensa_hostfs.c | 5 +++++
3 files changed, 18 insertions(+)
diff --git a/arch/xtensa/Kconfig b/arch/xtensa/Kconfig
index c411757a2b..a2f5b16d6c 100644
--- a/arch/xtensa/Kconfig
+++ b/arch/xtensa/Kconfig
@@ -279,6 +279,14 @@ config XTENSA_SEMIHOSTING_HOSTFS
This doesn't support some directory operations like readdir because
of the limitations of semihosting mechanism.
+config XTENSA_TARGET_ISS
+ bool "Target machine is Instruction Set Simulator"
+ default n
+ ---help---
+ This setting determines whether the target is Cadence Instruction
+ Set Simulator, which might have some sepecial characteristics such
+ as how to open a file nonblock.
+
if XTENSA_SEMIHOSTING_HOSTFS
config XTENSA_SEMIHOSTING_HOSTFS_CACHE_COHERENCE
diff --git a/arch/xtensa/include/simcall.h b/arch/xtensa/include/simcall.h
index da38490449..fa5397c904 100644
--- a/arch/xtensa/include/simcall.h
+++ b/arch/xtensa/include/simcall.h
@@ -63,6 +63,11 @@
#define SIMCALL_O_RDWR 0x0002
#define SIMCALL_O_ACCMODE 0x0003
#define SIMCALL_O_APPEND 0x0400
+#ifdef CONFIG_XTENSA_TARGET_ISS
+# define SIMCALL_O_NONBLOCK 0x0080
+#else
+# define SIMCALL_O_NONBLOCK 0x0800
+#endif
#define SIMCALL_O_CREAT 0x0040
#define SIMCALL_O_TRUNC 0x0200
#define SIMCALL_O_EXCL 0x0080
diff --git a/arch/xtensa/src/common/xtensa_hostfs.c b/arch/xtensa/src/common/xtensa_hostfs.c
index eb0a1dfdca..171aeae0dc 100644
--- a/arch/xtensa/src/common/xtensa_hostfs.c
+++ b/arch/xtensa/src/common/xtensa_hostfs.c
@@ -97,6 +97,11 @@ int host_open(const char *pathname, int flags, int mode)
simcall_flags |= SIMCALL_O_EXCL;
}
+ if ((flags & O_NONBLOCK) != 0)
+ {
+ simcall_flags |= SIMCALL_O_NONBLOCK;
+ }
+
#ifdef CONFIG_XTENSA_SEMIHOSTING_HOSTFS_CACHE_COHERENCE
up_clean_dcache(pathname, pathname + strlen(pathname) + 1);
#endif
(nuttx) 02/02: serial: use hostfs read/write on stdio as uart
Posted by xi...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit 065046b2a244d4a5a7a513c26a51dc6152fc6502
Author: chenxiaoyi <ch...@xiaomi.com>
AuthorDate: Wed May 22 15:58:24 2024 +0800
serial: use hostfs read/write on stdio as uart
This is used to implement serial console on instruction set simulator (ISS).
Signed-off-by: chenxiaoyi <ch...@xiaomi.com>
---
drivers/drivers_initialize.c | 5 +
drivers/serial/Kconfig | 27 ++++
drivers/serial/Make.defs | 4 +
drivers/serial/uart_hostfs.c | 302 +++++++++++++++++++++++++++++++++++++
include/nuttx/serial/uart_hostfs.h | 40 +++++
5 files changed, 378 insertions(+)
diff --git a/drivers/drivers_initialize.c b/drivers/drivers_initialize.c
index 8431d0c6c5..1bcef10a1d 100644
--- a/drivers/drivers_initialize.c
+++ b/drivers/drivers_initialize.c
@@ -43,6 +43,7 @@
#include <nuttx/segger/rtt.h>
#include <nuttx/sensors/sensor.h>
#include <nuttx/serial/pty.h>
+#include <nuttx/serial/uart_hostfs.h>
#include <nuttx/serial/uart_ram.h>
#include <nuttx/syslog/syslog.h>
#include <nuttx/syslog/syslog_console.h>
@@ -180,6 +181,10 @@ void drivers_initialize(void)
syslog_console_init();
#endif
+#ifdef CONFIG_UART_HOSTFS
+ uart_hostfs_init();
+#endif
+
#ifdef CONFIG_PSEUDOTERM_SUSV1
/* Register the master pseudo-terminal multiplexor device */
diff --git a/drivers/serial/Kconfig b/drivers/serial/Kconfig
index 66f1ba6230..2cc09c5154 100644
--- a/drivers/serial/Kconfig
+++ b/drivers/serial/Kconfig
@@ -53,6 +53,33 @@ config SERIAL_GDBSTUB_PATH
---help---
The path to the serial device that will be used for GDB stub.
+config UART_HOSTFS
+ bool "Use hostfs read/write on UART_HOSTFS_DEVPATH as uart console"
+ depends on FS_HOSTFS
+ default n
+ select SERIAL_RXDMA
+ select SERIAL_TXDMA
+
+config UART_HOSTFS_DEVPATH
+ string "The host device node that will be used by"
+ depends on UART_HOSTFS
+ default "/dev/tty"
+
+config UART_HOSTFS_RXBUFSIZE
+ int "Uart hostfs receive buffer size"
+ default 256
+ depends on UART_HOSTFS
+
+config UART_HOSTFS_TXBUFSIZE
+ int "Uart hostfs transmit buffer size"
+ default 256
+ depends on UART_HOSTFS
+
+config UART_HOSTFS_DELAY_USEC
+ int "Uart hostfs polling interval in microseconds"
+ default 1000
+ depends on UART_HOSTFS
+
menuconfig UART_PL011
bool "PL011 Chip support"
default n
diff --git a/drivers/serial/Make.defs b/drivers/serial/Make.defs
index 7a8f9cfb74..5be882d039 100644
--- a/drivers/serial/Make.defs
+++ b/drivers/serial/Make.defs
@@ -48,6 +48,10 @@ ifeq ($(CONFIG_RPMSG_UART),y)
CSRCS += uart_rpmsg.c
endif
+ifeq ($(CONFIG_UART_HOSTFS),y)
+ CSRCS += uart_hostfs.c
+endif
+
# Pseudo-terminal support
ifeq ($(CONFIG_PSEUDOTERM),y)
diff --git a/drivers/serial/uart_hostfs.c b/drivers/serial/uart_hostfs.c
new file mode 100644
index 0000000000..32a459c9c9
--- /dev/null
+++ b/drivers/serial/uart_hostfs.c
@@ -0,0 +1,302 @@
+/****************************************************************************
+ * drivers/serial/uart_hostfs.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership. The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/clock.h>
+#include <nuttx/fs/hostfs.h>
+#include <nuttx/serial/serial.h>
+#include <nuttx/wdog.h>
+
+#include <debug.h>
+#include <fcntl.h>
+#include <unistd.h>
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define UART_WDOG_DELAY USEC2TICK(CONFIG_UART_HOSTFS_DELAY_USEC)
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+struct uart_hostfs_priv_s
+{
+ int fd;
+ bool rxint;
+ struct wdog_s wdog;
+};
+
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+static int uart_hostfs_setup(FAR struct uart_dev_s *dev);
+static void uart_hostfs_shutdown(FAR struct uart_dev_s *dev);
+static int uart_hostfs_attach(FAR struct uart_dev_s *dev);
+static void uart_hostfs_detach(FAR struct uart_dev_s *dev);
+static int uart_hostfs_ioctl(FAR struct file *filep, int cmd,
+ unsigned long arg);
+static void uart_hostfs_rxint(FAR struct uart_dev_s *dev, bool enable);
+static bool uart_hostfs_rxavailable(FAR struct uart_dev_s *dev);
+#ifdef CONFIG_SERIAL_IFLOWCONTROL
+static bool uart_hostfs_rxflowcontrol(FAR struct uart_dev_s *dev,
+ unsigned int nbuffered, bool upper);
+#endif
+static void uart_hostfs_dmatxavail(FAR struct uart_dev_s *dev);
+static void uart_hostfs_dmasend(FAR struct uart_dev_s *dev);
+static void uart_hostfs_dmarxfree(FAR struct uart_dev_s *dev);
+static void uart_hostfs_dmareceive(FAR struct uart_dev_s *dev);
+static void uart_hostfs_send(FAR struct uart_dev_s *dev, int ch);
+static void uart_hostfs_txint(FAR struct uart_dev_s *dev, bool enable);
+static bool uart_hostfs_txready(FAR struct uart_dev_s *dev);
+static bool uart_hostfs_txempty(FAR struct uart_dev_s *dev);
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static const struct uart_ops_s g_uart_hostfs_ops =
+{
+ .setup = uart_hostfs_setup,
+ .shutdown = uart_hostfs_shutdown,
+ .attach = uart_hostfs_attach,
+ .detach = uart_hostfs_detach,
+ .ioctl = uart_hostfs_ioctl,
+ .rxint = uart_hostfs_rxint,
+ .rxavailable = uart_hostfs_rxavailable,
+#ifdef CONFIG_SERIAL_IFLOWCONTROL
+ .rxflowcontrol = uart_hostfs_rxflowcontrol,
+#endif
+ .dmatxavail = uart_hostfs_dmatxavail,
+ .dmasend = uart_hostfs_dmasend,
+ .dmarxfree = uart_hostfs_dmarxfree,
+ .dmareceive = uart_hostfs_dmareceive,
+ .send = uart_hostfs_send,
+ .txint = uart_hostfs_txint,
+ .txready = uart_hostfs_txready,
+ .txempty = uart_hostfs_txempty,
+};
+
+static char g_uart_hostfs_rxbuf[CONFIG_UART_HOSTFS_RXBUFSIZE];
+static char g_uart_hostfs_txbuf[CONFIG_UART_HOSTFS_TXBUFSIZE];
+
+static struct uart_hostfs_priv_s g_uart_hostfs_priv;
+
+static struct uart_dev_s g_uart_hostfs_dev =
+{
+ .ops = &g_uart_hostfs_ops,
+ .priv = &g_uart_hostfs_priv,
+ .xmit =
+ {
+ .size = CONFIG_UART_HOSTFS_TXBUFSIZE,
+ .buffer = g_uart_hostfs_txbuf,
+ },
+ .recv =
+ {
+ .size = CONFIG_UART_HOSTFS_RXBUFSIZE,
+ .buffer = g_uart_hostfs_rxbuf,
+ },
+};
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+static int uart_hostfs_setup(FAR struct uart_dev_s *dev)
+{
+ FAR struct uart_hostfs_priv_s *priv = dev->priv;
+
+ priv->fd = host_open(CONFIG_UART_HOSTFS_DEVPATH, O_RDWR | O_NONBLOCK,
+ 0666);
+ return priv->fd;
+}
+
+static void uart_hostfs_shutdown(FAR struct uart_dev_s *dev)
+{
+ FAR struct uart_hostfs_priv_s *priv = dev->priv;
+
+ if (priv->fd > 0)
+ {
+ host_close(priv->fd);
+ priv->fd = -1;
+ }
+}
+
+static int uart_hostfs_attach(FAR struct uart_dev_s *dev)
+{
+ return OK;
+}
+
+static void uart_hostfs_detach(FAR struct uart_dev_s *dev)
+{
+}
+
+static int uart_hostfs_ioctl(FAR struct file *filep, int cmd,
+ unsigned long arg)
+{
+ return -ENOTTY;
+}
+
+static void uart_hostfs_wdog(wdparm_t arg)
+{
+ FAR struct uart_dev_s *dev = (FAR struct uart_dev_s *)arg;
+ FAR struct uart_hostfs_priv_s *priv = dev->priv;
+
+ if (priv->rxint)
+ {
+ uart_dmarxfree(dev);
+ }
+
+ wd_start(&priv->wdog, UART_WDOG_DELAY, uart_hostfs_wdog, (wdparm_t)dev);
+}
+
+static void uart_hostfs_rxint(FAR struct uart_dev_s *dev, bool enable)
+{
+ FAR struct uart_hostfs_priv_s *priv = dev->priv;
+
+ priv->rxint = enable;
+ if (enable)
+ {
+ wd_start(&priv->wdog, 0, uart_hostfs_wdog, (wdparm_t)dev);
+ }
+ else
+ {
+ wd_cancel(&priv->wdog);
+ }
+}
+
+static bool uart_hostfs_rxavailable(FAR struct uart_dev_s *dev)
+{
+ return true;
+}
+
+#ifdef CONFIG_SERIAL_IFLOWCONTROL
+static bool uart_hostfs_rxflowcontrol(FAR struct uart_dev_s *dev,
+ unsigned int nbuffered, bool upper)
+{
+ FAR struct uart_buffer_s *rxbuf = &dev->recv;
+
+ return nbuffered == rxbuf->size;
+}
+#endif
+
+static void uart_hostfs_dmatxavail(FAR struct uart_dev_s *dev)
+{
+ uart_xmitchars_dma(dev);
+}
+
+static void uart_hostfs_dmasend(FAR struct uart_dev_s *dev)
+{
+ FAR struct uart_hostfs_priv_s *priv = dev->priv;
+ FAR struct uart_dmaxfer_s *xfer = &dev->dmatx;
+ int ret;
+
+ xfer->nbytes = 0;
+ ret = host_write(priv->fd, xfer->buffer, xfer->length);
+ if (ret > 0)
+ {
+ xfer->nbytes = ret;
+
+ if (ret == xfer->length && xfer->nlength > 0)
+ {
+ ret = host_write(priv->fd, xfer->nbuffer, xfer->nlength);
+ if (ret > 0)
+ {
+ xfer->nbytes += ret;
+ }
+ }
+ }
+
+ uart_xmitchars_done(dev);
+}
+
+static void uart_hostfs_dmarxfree(FAR struct uart_dev_s *dev)
+{
+ uart_recvchars_dma(dev);
+}
+
+static void uart_hostfs_dmareceive(FAR struct uart_dev_s *dev)
+{
+ FAR struct uart_hostfs_priv_s *priv = dev->priv;
+ FAR struct uart_dmaxfer_s *xfer = &dev->dmarx;
+ ssize_t ret;
+
+ xfer->nbytes = 0;
+ ret = host_read(priv->fd, xfer->buffer, xfer->length);
+ if (ret > 0)
+ {
+ xfer->nbytes = ret;
+
+ if (ret == xfer->length && xfer->nlength > 0)
+ {
+ ret = host_read(priv->fd, xfer->nbuffer, xfer->nlength);
+ if (ret > 0)
+ {
+ xfer->nbytes += ret;
+ }
+ }
+ }
+
+ uart_recvchars_done(dev);
+}
+
+static void uart_hostfs_send(FAR struct uart_dev_s *dev, int ch)
+{
+ FAR struct uart_hostfs_priv_s *priv = dev->priv;
+ char c = ch;
+
+ host_write(priv->fd, &c, 1);
+}
+
+static void uart_hostfs_txint(FAR struct uart_dev_s *dev, bool enable)
+{
+}
+
+static bool uart_hostfs_txready(FAR struct uart_dev_s *dev)
+{
+ return true;
+}
+
+static bool uart_hostfs_txempty(FAR struct uart_dev_s *dev)
+{
+ return true;
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+void uart_hostfs_init(void)
+{
+ uart_register("/dev/console", &g_uart_hostfs_dev);
+}
+
+int up_putc(int ch)
+{
+ FAR struct uart_dev_s *dev = &g_uart_hostfs_dev;
+
+ uart_hostfs_send(dev, ch);
+ return ch;
+}
diff --git a/include/nuttx/serial/uart_hostfs.h b/include/nuttx/serial/uart_hostfs.h
new file mode 100644
index 0000000000..e0e1555f72
--- /dev/null
+++ b/include/nuttx/serial/uart_hostfs.h
@@ -0,0 +1,40 @@
+/****************************************************************************
+ * include/nuttx/serial/uart_hostfs.h
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership. The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+#ifndef __INCLUDE_NUTTX_SERIAL_UART_HOSTFS_H
+#define __INCLUDE_NUTTX_SERIAL_UART_HOSTFS_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+/****************************************************************************
+ * Public Function Prototypes
+ ****************************************************************************/
+
+#ifdef CONFIG_UART_HOSTFS
+
+void uart_hostfs_init(void);
+
+#endif
+
+#endif /* __INCLUDE_NUTTX_SERIAL_UART_HOSTFS_H */