drivers/serial: Always support c_oflag, c_iflag and c_lflag in termios

CONFIG_SERIAL_TERMIOS only decide whether to support c_cflag field since
many terminal application need the first three fields to work correctly.
For more information please reference:
https://www.mail-archive.com/dev@nuttx.apache.org/msg09321.html

before this change(olimexino-stm32:tiny):
   text    data     bss     dec     hex filename
  34884     328    1768   36980    9074 nuttx
after this change:
   text    data     bss     dec     hex filename
  35052     340    1768   37160    9128 nuttx
delta
   text    data     bss     dec     hex filename
    168      12       0     180      b4 nuttx

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
This commit is contained in:
Xiang Xiao
2023-03-20 00:09:45 +08:00
committed by patacongo
parent cf56e4113a
commit b63994b7f7
11 changed files with 18 additions and 73 deletions
-2
View File
@@ -545,7 +545,6 @@ static int w25_boot_program(void)
return ret; return ret;
} }
#ifdef CONFIG_SERIAL_TERMIOS
/* Drain all pending Tx output in stdout. "Booting..." message will be /* Drain all pending Tx output in stdout. "Booting..." message will be
* lost if the outgoing Tx bytes are not drained. * lost if the outgoing Tx bytes are not drained.
*/ */
@@ -557,7 +556,6 @@ static int w25_boot_program(void)
fprintf(stderr, "ERROR: tcdrain() failed: %d\n", ret); fprintf(stderr, "ERROR: tcdrain() failed: %d\n", ret);
return ret; return ret;
} }
#endif
/* Start the successfully loaded program */ /* Start the successfully loaded program */
+4 -4
View File
@@ -433,9 +433,7 @@ int wtgahrs2_initialize(FAR const char *path, int devno)
{ {
FAR struct wtgahrs2_dev_s *rtdata; FAR struct wtgahrs2_dev_s *rtdata;
FAR struct wtgahrs2_sensor_s *tmp; FAR struct wtgahrs2_sensor_s *tmp;
#ifdef CONFIG_SERIAL_TERMIOS
struct termios opt; struct termios opt;
#endif
FAR char *argv[2]; FAR char *argv[2];
char arg1[16]; char arg1[16];
int ret; int ret;
@@ -462,14 +460,16 @@ int wtgahrs2_initialize(FAR const char *path, int devno)
goto open_err; goto open_err;
} }
#ifdef CONFIG_SERIAL_TERMIOS
file_ioctl(&rtdata->file, TCGETS, &opt); file_ioctl(&rtdata->file, TCGETS, &opt);
cfmakeraw(&opt); cfmakeraw(&opt);
#ifdef CONFIG_SERIAL_TERMIOS
cfsetispeed(&opt, B115200); cfsetispeed(&opt, B115200);
cfsetospeed(&opt, B115200); cfsetospeed(&opt, B115200);
file_ioctl(&rtdata->file, TCSETS, &opt);
#endif #endif
file_ioctl(&rtdata->file, TCSETS, &opt);
/* Accelerometer register */ /* Accelerometer register */
tmp = &rtdata->dev[WTGAHRS2_ACCEL_IDX]; tmp = &rtdata->dev[WTGAHRS2_ACCEL_IDX];
+4 -3
View File
@@ -169,9 +169,10 @@ config SERIAL_TERMIOS
depends on ARCH_HAVE_SERIAL_TERMIOS depends on ARCH_HAVE_SERIAL_TERMIOS
default n default n
---help--- ---help---
Serial driver supports termios.h interfaces (tcsetattr, tcflush, etc.). If this is not defined, then the terminal hardware setting
If this is not defined, then the terminal settings (baud, parity, etc). (baud, parity, flow control) is not configurable at runtime.
are not configurable at runtime; serial streams cannot be flushed, etc.. Note: other software setting (echo, \r\n<->\n, break, tcflush)
is always supported.
config TTY_LAUNCH config TTY_LAUNCH
bool "Enable feature TTY launch program" bool "Enable feature TTY launch program"
-8
View File
@@ -73,9 +73,7 @@ struct pty_dev_s
struct file pd_src; /* Provides data to read() method (pipe output) */ struct file pd_src; /* Provides data to read() method (pipe output) */
struct file pd_sink; /* Accepts data from write() method (pipe input) */ struct file pd_sink; /* Accepts data from write() method (pipe input) */
bool pd_master; /* True: this is the master */ bool pd_master; /* True: this is the master */
#ifdef CONFIG_SERIAL_TERMIOS
tcflag_t pd_iflag; /* Terminal input modes */ tcflag_t pd_iflag; /* Terminal input modes */
#endif
tcflag_t pd_oflag; /* Terminal output modes */ tcflag_t pd_oflag; /* Terminal output modes */
struct pty_poll_s pd_poll[CONFIG_DEV_PTY_NPOLLWAITERS]; struct pty_poll_s pd_poll[CONFIG_DEV_PTY_NPOLLWAITERS];
}; };
@@ -394,18 +392,15 @@ static ssize_t pty_read(FAR struct file *filep, FAR char *buffer, size_t len)
FAR struct inode *inode; FAR struct inode *inode;
FAR struct pty_dev_s *dev; FAR struct pty_dev_s *dev;
ssize_t ntotal; ssize_t ntotal;
#ifdef CONFIG_SERIAL_TERMIOS
ssize_t i; ssize_t i;
ssize_t j; ssize_t j;
char ch; char ch;
#endif
DEBUGASSERT(filep != NULL && filep->f_inode != NULL); DEBUGASSERT(filep != NULL && filep->f_inode != NULL);
inode = filep->f_inode; inode = filep->f_inode;
dev = inode->i_private; dev = inode->i_private;
DEBUGASSERT(dev != NULL); DEBUGASSERT(dev != NULL);
#ifdef CONFIG_SERIAL_TERMIOS
/* Do input processing if any is enabled /* Do input processing if any is enabled
* *
* Specifically not handled: * Specifically not handled:
@@ -460,7 +455,6 @@ static ssize_t pty_read(FAR struct file *filep, FAR char *buffer, size_t len)
} }
} }
else else
#endif
{ {
/* NOTE: the source pipe will block if no data is available in /* NOTE: the source pipe will block if no data is available in
* the pipe. Otherwise, it will return data from the pipe. If * the pipe. Otherwise, it will return data from the pipe. If
@@ -681,7 +675,6 @@ static int pty_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
} }
break; break;
#ifdef CONFIG_SERIAL_TERMIOS
case TCGETS: case TCGETS:
{ {
FAR struct termios *termiosp = (FAR struct termios *)arg; FAR struct termios *termiosp = (FAR struct termios *)arg;
@@ -718,7 +711,6 @@ static int pty_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
ret = OK; ret = OK;
} }
break; break;
#endif
/* Get the number of bytes that are immediately available for reading /* Get the number of bytes that are immediately available for reading
* from the source pipe. * from the source pipe.
+1 -42
View File
@@ -315,7 +315,6 @@ static inline ssize_t uart_irqwrite(FAR uart_dev_t *dev,
{ {
int ch = *buffer++; int ch = *buffer++;
#ifdef CONFIG_SERIAL_TERMIOS
/* Do output post-processing */ /* Do output post-processing */
if ((dev->tc_oflag & OPOST) != 0) if ((dev->tc_oflag & OPOST) != 0)
@@ -335,15 +334,6 @@ static inline ssize_t uart_irqwrite(FAR uart_dev_t *dev,
} }
} }
#else /* !CONFIG_SERIAL_TERMIOS */
/* If this is the console, then we should replace LF with CR-LF */
if (dev->isconsole && ch == '\n')
{
uart_putc(dev, '\r');
}
#endif
/* Output the character, using the low-level direct UART interfaces */ /* Output the character, using the low-level direct UART interfaces */
uart_putc(dev, ch); uart_putc(dev, ch);
@@ -847,7 +837,6 @@ static ssize_t uart_read(FAR struct file *filep,
rxbuf->tail = tail; rxbuf->tail = tail;
#ifdef CONFIG_SERIAL_TERMIOS
/* Do input processing if any is enabled */ /* Do input processing if any is enabled */
if (dev->tc_iflag & (INLCR | IGNCR | ICRNL)) if (dev->tc_iflag & (INLCR | IGNCR | ICRNL))
@@ -879,25 +868,13 @@ static ssize_t uart_read(FAR struct file *filep,
* IUCLC - Not Posix * IUCLC - Not Posix
* IXON/OXOFF - no xon/xoff flow control. * IXON/OXOFF - no xon/xoff flow control.
*/ */
#else
if (dev->isconsole && ch == '\r')
{
ch = '\n';
}
#endif
/* Store the received character */ /* Store the received character */
*buffer++ = ch; *buffer++ = ch;
recvd++; recvd++;
if ( if (dev->tc_lflag & ECHO)
#ifdef CONFIG_SERIAL_TERMIOS
dev->tc_lflag & ECHO
#else
dev->isconsole
#endif
)
{ {
/* Check for the beginning of a VT100 escape sequence, 3 byte */ /* Check for the beginning of a VT100 escape sequence, 3 byte */
@@ -1271,7 +1248,6 @@ static ssize_t uart_write(FAR struct file *filep, FAR const char *buffer,
ch = *buffer++; ch = *buffer++;
ret = OK; ret = OK;
#ifdef CONFIG_SERIAL_TERMIOS
/* Do output post-processing */ /* Do output post-processing */
if ((dev->tc_oflag & OPOST) != 0) if ((dev->tc_oflag & OPOST) != 0)
@@ -1299,15 +1275,6 @@ static ssize_t uart_write(FAR struct file *filep, FAR const char *buffer,
*/ */
} }
#else /* !CONFIG_SERIAL_TERMIOS */
/* If this is the console, convert \n -> \r\n */
if (dev->isconsole && ch == '\n')
{
ret = uart_putxmitchar(dev, '\r', oktoblock);
}
#endif
/* Put the character into the transmit buffer */ /* Put the character into the transmit buffer */
if (ret >= 0) if (ret >= 0)
@@ -1550,7 +1517,6 @@ static int uart_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
} }
} }
#ifdef CONFIG_SERIAL_TERMIOS
/* Append any higher level TTY flags */ /* Append any higher level TTY flags */
if (ret == OK || ret == -ENOTTY) if (ret == OK || ret == -ENOTTY)
@@ -1599,7 +1565,6 @@ static int uart_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
break; break;
} }
} }
#endif
return ret; return ret;
} }
@@ -1817,7 +1782,6 @@ int uart_register(FAR const char *path, FAR uart_dev_t *dev)
dev->pid = INVALID_PROCESS_ID; dev->pid = INVALID_PROCESS_ID;
#endif #endif
#ifdef CONFIG_SERIAL_TERMIOS
/* If this UART is a serial console */ /* If this UART is a serial console */
if (dev->isconsole) if (dev->isconsole)
@@ -1838,7 +1802,6 @@ int uart_register(FAR const char *path, FAR uart_dev_t *dev)
dev->escape = 0; dev->escape = 0;
} }
#endif
/* Initialize mutex & semaphores */ /* Initialize mutex & semaphores */
@@ -2031,11 +1994,7 @@ int uart_check_special(FAR uart_dev_t *dev, const char *buf, size_t size)
{ {
size_t i; size_t i;
#ifdef CONFIG_SERIAL_TERMIOS
if ((dev->tc_lflag & ISIG) == 0) if ((dev->tc_lflag & ISIG) == 0)
#else
if (!dev->isconsole)
#endif
{ {
return 0; return 0;
} }
-2
View File
@@ -284,13 +284,11 @@ struct uart_dev_s
pid_t pid; /* Thread PID to receive signals (-1 if none) */ pid_t pid; /* Thread PID to receive signals (-1 if none) */
#endif #endif
#ifdef CONFIG_SERIAL_TERMIOS
/* Terminal control flags */ /* Terminal control flags */
tcflag_t tc_iflag; /* Input modes */ tcflag_t tc_iflag; /* Input modes */
tcflag_t tc_oflag; /* Output modes */ tcflag_t tc_oflag; /* Output modes */
tcflag_t tc_lflag; /* Local modes */ tcflag_t tc_lflag; /* Local modes */
#endif
/* Semaphores & mutex */ /* Semaphores & mutex */
+2 -2
View File
@@ -31,7 +31,7 @@
#include <termios.h> #include <termios.h>
#include <sys/ioctl.h> #include <sys/ioctl.h>
#if defined(CONFIG_SERIAL_TERMIOS) && defined(CONFIG_PSEUDOTERM) #ifdef CONFIG_PSEUDOTERM
/**************************************************************************** /****************************************************************************
* Public Function Prototypes * Public Function Prototypes
@@ -59,5 +59,5 @@ int openpty(FAR int *master, FAR int *slave, FAR char *name,
} }
#endif #endif
#endif /* CONFIG_SERIAL_TERMIOS && CONFIG_PSEUDOTERM */ #endif /* CONFIG_PSEUDOTERM */
#endif /* __INCLUDE_PTY_H */ #endif /* __INCLUDE_PTY_H */
+5 -5
View File
@@ -25,8 +25,8 @@
"basename","libgen.h","","FAR char *","FAR char *" "basename","libgen.h","","FAR char *","FAR char *"
"btowc","wchar.h","","wint_t","int" "btowc","wchar.h","","wint_t","int"
"calloc","stdlib.h","","FAR void *","size_t","size_t" "calloc","stdlib.h","","FAR void *","size_t","size_t"
"cfgetspeed","termios.h","defined(CONFIG_SERIAL_TERMIOS)","speed_t","FAR const struct termios *" "cfgetspeed","termios.h","","speed_t","FAR const struct termios *"
"cfsetspeed","termios.h","defined(CONFIG_SERIAL_TERMIOS)","int","FAR struct termios *","speed_t" "cfsetspeed","termios.h","","int","FAR struct termios *","speed_t"
"chdir","unistd.h","!defined(CONFIG_DISABLE_ENVIRON)","int","FAR const char *" "chdir","unistd.h","!defined(CONFIG_DISABLE_ENVIRON)","int","FAR const char *"
"clock","time.h","","clock_t" "clock","time.h","","clock_t"
"crc32","nuttx/crc32.h","","uint32_t","FAR const uint8_t *","size_t" "crc32","nuttx/crc32.h","","uint32_t","FAR const uint8_t *","size_t"
@@ -256,9 +256,9 @@
"swab","unistd.h","","void","FAR const void *","FAR void *","ssize_t" "swab","unistd.h","","void","FAR const void *","FAR void *","ssize_t"
"swprintf","wchar.h","","int","FAR wchar_t *","size_t","FAR const wchar_t *","..." "swprintf","wchar.h","","int","FAR wchar_t *","size_t","FAR const wchar_t *","..."
"syslog","syslog.h","","void","int","FAR const IPTR char *","..." "syslog","syslog.h","","void","int","FAR const IPTR char *","..."
"tcflush","termios.h","defined(CONFIG_SERIAL_TERMIOS)","int","int","int" "tcflush","termios.h","","int","int","int"
"tcgetattr","termios.h","defined(CONFIG_SERIAL_TERMIOS)","int","int","FAR struct termios *" "tcgetattr","termios.h","","int","int","FAR struct termios *"
"tcsetattr","termios.h","defined(CONFIG_SERIAL_TERMIOS)","int","int","int","FAR const struct termios *" "tcsetattr","termios.h","","int","int","int","FAR const struct termios *"
"telldir","dirent.h","","off_t","FAR DIR *" "telldir","dirent.h","","off_t","FAR DIR *"
"time","time.h","","time_t","FAR time_t *" "time","time.h","","time_t","FAR time_t *"
"tolower","ctype.h","","int","int" "tolower","ctype.h","","int","int"
1 __errno errno.h defined(CONFIG_BUILD_FLAT) FAR int *
25 basename libgen.h FAR char *
26 btowc wchar.h wint_t
27 calloc stdlib.h FAR void *
28 cfgetspeed termios.h defined(CONFIG_SERIAL_TERMIOS) speed_t
29 cfsetspeed termios.h defined(CONFIG_SERIAL_TERMIOS) int
30 chdir unistd.h !defined(CONFIG_DISABLE_ENVIRON) int
31 clock time.h clock_t
32 crc32 nuttx/crc32.h uint32_t
256 swab unistd.h void
257 swprintf wchar.h int
258 syslog syslog.h void
259 tcflush termios.h defined(CONFIG_SERIAL_TERMIOS) int
260 tcgetattr termios.h defined(CONFIG_SERIAL_TERMIOS) int
261 tcsetattr termios.h defined(CONFIG_SERIAL_TERMIOS) int
262 telldir dirent.h off_t
263 time time.h time_t
264 tolower ctype.h int
-3
View File
@@ -18,9 +18,6 @@
# #
############################################################################ ############################################################################
# termios.h support requires file descriptors and that CONFIG_SERIAL_TERMIOS
# is defined
# Add the termios C files to the build # Add the termios C files to the build
CSRCS += lib_cfspeed.c lib_cfmakeraw.c lib_isatty.c lib_tcflush.c CSRCS += lib_cfspeed.c lib_cfmakeraw.c lib_isatty.c lib_tcflush.c
+2
View File
@@ -50,6 +50,8 @@ void cfmakeraw(FAR struct termios *termiosp)
| INLCR | IGNCR | ICRNL | IXON); | INLCR | IGNCR | ICRNL | IXON);
termiosp->c_oflag &= ~OPOST; termiosp->c_oflag &= ~OPOST;
termiosp->c_lflag &= ~(ECHO | ECHONL | ICANON | ISIG | IEXTEN); termiosp->c_lflag &= ~(ECHO | ECHONL | ICANON | ISIG | IEXTEN);
#ifdef CONFIG_SERIAL_TERMIOS
termiosp->c_cflag &= ~(CSIZE | PARENB); termiosp->c_cflag &= ~(CSIZE | PARENB);
termiosp->c_cflag |= CS8; termiosp->c_cflag |= CS8;
#endif
} }
-2
View File
@@ -46,8 +46,6 @@
* responds wo tcgetattr() without an error -- that it, the driver supports * responds wo tcgetattr() without an error -- that it, the driver supports
* the NuttX TCGETS ioctl command. * the NuttX TCGETS ioctl command.
* *
* Of course, that can only be true if CONFIG_SERIAL_TERMIOS=y.
*
****************************************************************************/ ****************************************************************************/
int isatty(int fd) int isatty(int fd)