This is an automated email from the ASF dual-hosted git repository.
xiaoxiang781216 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git
The following commit(s) were added to refs/heads/master by this push:
new 2f890e5b0f2 drivers/serial: keep the c_cc settings in the termios
helpers
2f890e5b0f2 is described below
commit 2f890e5b0f25513ff73ab7b8072377f92b7db579
Author: yangsong8 <[email protected]>
AuthorDate: Thu Nov 12 22:39:45 2026 +0800
drivers/serial: keep the c_cc settings in the termios helpers
struct uart_termios_s now also keeps c_cc[VMIN] and c_cc[VTIME] with
CONFIG_SERIAL_TERMIOS. The new uart_termios_init() replaces
uart_termios_initcc() and sets all its fields: iflag, oflag and lflag
as given, the configured INTR and SUSP characters, VMIN 1 and VTIME 0.
serial and pty set up their terminal with it.
uart_termios_getattr() and uart_termios_setattr() copy VMIN and VTIME
as well. serial drops its own minread and timeout fields and uses the
ones in the termios state. pty now gives back the VMIN and VTIME that
were set; it still does not act on them.
Assisted-by: Kiro:claude-opus-5-5
Signed-off-by: yangsong8 <[email protected]>
---
drivers/serial/pty.c | 7 +++----
drivers/serial/serial.c | 42 ++++++++++++++---------------------------
drivers/serial/serial_termios.c | 11 ++++++++++-
include/nuttx/serial/serial.h | 23 ++++++++++++++++------
4 files changed, 44 insertions(+), 39 deletions(-)
diff --git a/drivers/serial/pty.c b/drivers/serial/pty.c
index c54895ea93c..bb7f9febae4 100644
--- a/drivers/serial/pty.c
+++ b/drivers/serial/pty.c
@@ -1272,11 +1272,10 @@ int pty_register2(int minor, bool susv1)
devpair->pp_locked = true;
devpair->pp_master.pd_devpair = devpair;
devpair->pp_master.pd_master = true;
- devpair->pp_master.pd_termios.oflag = OPOST | OCRNL;
devpair->pp_slave.pd_devpair = devpair;
- devpair->pp_slave.pd_termios.oflag = OPOST | ONLCR;
- devpair->pp_slave.pd_termios.lflag = ECHO | ICANON | ISIG;
- uart_termios_initcc(&devpair->pp_slave.pd_termios);
+ uart_termios_init(&devpair->pp_master.pd_termios, 0, OPOST | OCRNL, 0);
+ uart_termios_init(&devpair->pp_slave.pd_termios, 0, OPOST | ONLCR,
+ ECHO | ICANON | ISIG);
#if defined(CONFIG_TTY_SIGINT) || defined(CONFIG_TTY_SIGTSTP)
/* Initialize of the task that will receive SIGINT signals. */
diff --git a/drivers/serial/serial.c b/drivers/serial/serial.c
index eba0ebe93f0..b1032e0e4c4 100644
--- a/drivers/serial/serial.c
+++ b/drivers/serial/serial.c
@@ -1500,13 +1500,13 @@ static ssize_t uart_readv(FAR struct file *filep, FAR
struct uio *uio)
{
#ifdef CONFIG_SERIAL_TERMIOS
dev->minrecv = MIN(buflen - recvd,
- dev->minread - recvd);
- if (dev->timeout)
+ dev->termios.vmin - recvd);
+ if (dev->termios.vtime)
{
uart_spinunlock(dev, false, flags);
nxmutex_unlock(&dev->recv.lock);
ret = nxsem_tickwait(&dev->recvsem,
- DSEC2TICK(dev->timeout));
+ DSEC2TICK(dev->termios.vtime));
}
else
#endif
@@ -1520,7 +1520,7 @@ static ssize_t uart_readv(FAR struct file *filep, FAR
struct uio *uio)
flags = uart_spinlock(dev, false);
#ifdef CONFIG_SERIAL_TERMIOS
- dev->minrecv = dev->minread;
+ dev->minrecv = dev->termios.vmin;
#endif
}
}
@@ -2228,10 +2228,6 @@ static int uart_ioctl(FAR struct file *filep, int cmd,
unsigned long arg)
*/
termiosp->c_cc[VERASE] = ASCII_DEL;
-#ifdef CONFIG_SERIAL_TERMIOS
- termiosp->c_cc[VTIME] = dev->timeout;
- termiosp->c_cc[VMIN] = dev->minread;
-#endif
ret = 0;
}
@@ -2249,9 +2245,7 @@ static int uart_ioctl(FAR struct file *filep, int cmd,
unsigned long arg)
uart_termios_setattr(&dev->termios, termiosp);
#ifdef CONFIG_SERIAL_TERMIOS
- dev->timeout = termiosp->c_cc[VTIME];
- dev->minread = termiosp->c_cc[VMIN];
- dev->minrecv = dev->minread;
+ dev->minrecv = dev->termios.vmin;
#endif
ret = 0;
}
@@ -2570,8 +2564,6 @@ int uart_register(FAR const char *path, FAR uart_dev_t
*dev)
dev->pid = INVALID_PROCESS_ID;
#endif
- uart_termios_initcc(&dev->termios);
-
#ifdef CONFIG_TTY_FORCE_PANIC
dev->panic_count = 0;
#endif
@@ -2580,22 +2572,21 @@ int uart_register(FAR const char *path, FAR uart_dev_t
*dev)
if (dev->isconsole)
{
- /* Enable signals and echo by default */
-
- dev->termios.lflag |= ISIG | ECHO | ICANON;
-
- /* Enable \n -> \r\n translation for the console */
-
- dev->termios.oflag = OPOST | ONLCR;
-
- /* Convert CR to LF by default for console */
+ /* Convert CR to LF, enable \n -> \r\n translation, and enable
+ * signals, echo and canonical input by default for the console.
+ */
- dev->termios.iflag |= ICRNL;
+ uart_termios_init(&dev->termios, ICRNL, OPOST | ONLCR,
+ ISIG | ECHO | ICANON);
/* Clear escape counter */
dev->escape = 0;
}
+ else
+ {
+ uart_termios_init(&dev->termios, 0, 0, 0);
+ }
/* Initialize mutex & semaphores */
@@ -2606,11 +2597,6 @@ int uart_register(FAR const char *path, FAR uart_dev_t
*dev)
nxsem_init(&dev->recvsem, 0, 0);
rspin_lock_init(&dev->lock);
-#ifdef CONFIG_SERIAL_TERMIOS
- dev->timeout = 0;
- dev->minread = 1;
-#endif
-
/* Register the serial driver */
sinfo("Registering %s\n", path);
diff --git a/drivers/serial/serial_termios.c b/drivers/serial/serial_termios.c
index ac79c4a67c0..a4924a2cf3e 100644
--- a/drivers/serial/serial_termios.c
+++ b/drivers/serial/serial_termios.c
@@ -55,7 +55,12 @@ void uart_termios_getattr(FAR const struct uart_termios_s
*tc,
#ifdef CONFIG_TTY_SIGTSTP
termiosp->c_cc[VSUSP] = tc->vsusp;
#endif
- termiosp->c_cc[VMIN] = 1;
+#ifdef CONFIG_SERIAL_TERMIOS
+ termiosp->c_cc[VMIN] = tc->vmin;
+ termiosp->c_cc[VTIME] = tc->vtime;
+#else
+ termiosp->c_cc[VMIN] = 1;
+#endif
}
void uart_termios_setattr(FAR struct uart_termios_s *tc,
@@ -70,6 +75,10 @@ void uart_termios_setattr(FAR struct uart_termios_s *tc,
#ifdef CONFIG_TTY_SIGTSTP
tc->vsusp = termiosp->c_cc[VSUSP];
#endif
+#ifdef CONFIG_SERIAL_TERMIOS
+ tc->vmin = termiosp->c_cc[VMIN];
+ tc->vtime = termiosp->c_cc[VTIME];
+#endif
}
size_t uart_termios_in_copy(FAR const struct uart_termios_s *tc,
diff --git a/include/nuttx/serial/serial.h b/include/nuttx/serial/serial.h
index 37e201755e3..bdd237fb036 100644
--- a/include/nuttx/serial/serial.h
+++ b/include/nuttx/serial/serial.h
@@ -325,6 +325,10 @@ struct uart_termios_s
#ifdef CONFIG_TTY_SIGTSTP
cc_t vsusp; /* c_cc[VSUSP] */
#endif
+#ifdef CONFIG_SERIAL_TERMIOS
+ cc_t vmin; /* c_cc[VMIN] */
+ cc_t vtime; /* c_cc[VTIME] */
+#endif
};
/* This is the device structure used by the driver. The caller of
@@ -406,8 +410,6 @@ struct uart_dev_s
#ifdef CONFIG_SERIAL_TERMIOS
uint8_t minrecv; /* Minimum received bytes */
- uint8_t minread; /* c_cc[VMIN] */
- uint8_t timeout; /* c_cc[VTIME] */
#endif
FAR struct pollfd_s *fds[CONFIG_SERIAL_NPOLLWAITERS];
@@ -420,23 +422,32 @@ typedef struct uart_dev_s uart_dev_t;
****************************************************************************/
/****************************************************************************
- * Name: uart_termios_initcc
+ * Name: uart_termios_init
*
* Description:
- * Set the INTR and SUSP characters to the ones of the configuration, the
- * characters of a terminal when it starts.
+ * Initialize all fields of the state: the given iflag, oflag and lflag,
+ * the INTR and SUSP characters of the configuration, and VMIN 1 and
+ * VTIME 0.
*
****************************************************************************/
static inline_function void
-uart_termios_initcc(FAR struct uart_termios_s *tc)
+uart_termios_init(FAR struct uart_termios_s *tc, tcflag_t iflag,
+ tcflag_t oflag, tcflag_t lflag)
{
+ tc->iflag = iflag;
+ tc->oflag = oflag;
+ tc->lflag = lflag;
#ifdef CONFIG_TTY_SIGINT
tc->vintr = CONFIG_TTY_SIGINT_CHAR;
#endif
#ifdef CONFIG_TTY_SIGTSTP
tc->vsusp = CONFIG_TTY_SIGTSTP_CHAR;
#endif
+#ifdef CONFIG_SERIAL_TERMIOS
+ tc->vmin = 1;
+ tc->vtime = 0;
+#endif
}
/****************************************************************************