1
0
Fork 0
forked from nuttx/nuttx-update

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

View file

@ -545,7 +545,6 @@ static int w25_boot_program(void)
return ret;
}
#ifdef CONFIG_SERIAL_TERMIOS
/* Drain all pending Tx output in stdout. "Booting..." message will be
* 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);
return ret;
}
#endif
/* Start the successfully loaded program */

View file

@ -433,9 +433,7 @@ int wtgahrs2_initialize(FAR const char *path, int devno)
{
FAR struct wtgahrs2_dev_s *rtdata;
FAR struct wtgahrs2_sensor_s *tmp;
#ifdef CONFIG_SERIAL_TERMIOS
struct termios opt;
#endif
FAR char *argv[2];
char arg1[16];
int ret;
@ -462,14 +460,16 @@ int wtgahrs2_initialize(FAR const char *path, int devno)
goto open_err;
}
#ifdef CONFIG_SERIAL_TERMIOS
file_ioctl(&rtdata->file, TCGETS, &opt);
cfmakeraw(&opt);
#ifdef CONFIG_SERIAL_TERMIOS
cfsetispeed(&opt, B115200);
cfsetospeed(&opt, B115200);
file_ioctl(&rtdata->file, TCSETS, &opt);
#endif
file_ioctl(&rtdata->file, TCSETS, &opt);
/* Accelerometer register */
tmp = &rtdata->dev[WTGAHRS2_ACCEL_IDX];

View file

@ -169,9 +169,10 @@ config SERIAL_TERMIOS
depends on ARCH_HAVE_SERIAL_TERMIOS
default n
---help---
Serial driver supports termios.h interfaces (tcsetattr, tcflush, etc.).
If this is not defined, then the terminal settings (baud, parity, etc).
are not configurable at runtime; serial streams cannot be flushed, etc..
If this is not defined, then the terminal hardware setting
(baud, parity, flow control) is not configurable at runtime.
Note: other software setting (echo, \r\n<->\n, break, tcflush)
is always supported.
config TTY_LAUNCH
bool "Enable feature TTY launch program"

View file

@ -73,9 +73,7 @@ struct pty_dev_s
struct file pd_src; /* Provides data to read() method (pipe output) */
struct file pd_sink; /* Accepts data from write() method (pipe input) */
bool pd_master; /* True: this is the master */
#ifdef CONFIG_SERIAL_TERMIOS
tcflag_t pd_iflag; /* Terminal input modes */
#endif
tcflag_t pd_oflag; /* Terminal output modes */
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 pty_dev_s *dev;
ssize_t ntotal;
#ifdef CONFIG_SERIAL_TERMIOS
ssize_t i;
ssize_t j;
char ch;
#endif
DEBUGASSERT(filep != NULL && filep->f_inode != NULL);
inode = filep->f_inode;
dev = inode->i_private;
DEBUGASSERT(dev != NULL);
#ifdef CONFIG_SERIAL_TERMIOS
/* Do input processing if any is enabled
*
* Specifically not handled:
@ -460,7 +455,6 @@ static ssize_t pty_read(FAR struct file *filep, FAR char *buffer, size_t len)
}
}
else
#endif
{
/* NOTE: the source pipe will block if no data is available in
* 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;
#ifdef CONFIG_SERIAL_TERMIOS
case TCGETS:
{
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;
}
break;
#endif
/* Get the number of bytes that are immediately available for reading
* from the source pipe.

View file

@ -315,7 +315,6 @@ static inline ssize_t uart_irqwrite(FAR uart_dev_t *dev,
{
int ch = *buffer++;
#ifdef CONFIG_SERIAL_TERMIOS
/* Do output post-processing */
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 */
uart_putc(dev, ch);
@ -847,7 +837,6 @@ static ssize_t uart_read(FAR struct file *filep,
rxbuf->tail = tail;
#ifdef CONFIG_SERIAL_TERMIOS
/* Do input processing if any is enabled */
if (dev->tc_iflag & (INLCR | IGNCR | ICRNL))
@ -879,25 +868,13 @@ static ssize_t uart_read(FAR struct file *filep,
* IUCLC - Not Posix
* IXON/OXOFF - no xon/xoff flow control.
*/
#else
if (dev->isconsole && ch == '\r')
{
ch = '\n';
}
#endif
/* Store the received character */
*buffer++ = ch;
recvd++;
if (
#ifdef CONFIG_SERIAL_TERMIOS
dev->tc_lflag & ECHO
#else
dev->isconsole
#endif
)
if (dev->tc_lflag & ECHO)
{
/* 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++;
ret = OK;
#ifdef CONFIG_SERIAL_TERMIOS
/* Do output post-processing */
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 */
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 */
if (ret == OK || ret == -ENOTTY)
@ -1599,7 +1565,6 @@ static int uart_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
break;
}
}
#endif
return ret;
}
@ -1817,7 +1782,6 @@ int uart_register(FAR const char *path, FAR uart_dev_t *dev)
dev->pid = INVALID_PROCESS_ID;
#endif
#ifdef CONFIG_SERIAL_TERMIOS
/* If this UART is a serial console */
if (dev->isconsole)
@ -1838,7 +1802,6 @@ int uart_register(FAR const char *path, FAR uart_dev_t *dev)
dev->escape = 0;
}
#endif
/* 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;
#ifdef CONFIG_SERIAL_TERMIOS
if ((dev->tc_lflag & ISIG) == 0)
#else
if (!dev->isconsole)
#endif
{
return 0;
}

View file

@ -284,13 +284,11 @@ struct uart_dev_s
pid_t pid; /* Thread PID to receive signals (-1 if none) */
#endif
#ifdef CONFIG_SERIAL_TERMIOS
/* Terminal control flags */
tcflag_t tc_iflag; /* Input modes */
tcflag_t tc_oflag; /* Output modes */
tcflag_t tc_lflag; /* Local modes */
#endif
/* Semaphores & mutex */

View file

@ -31,7 +31,7 @@
#include <termios.h>
#include <sys/ioctl.h>
#if defined(CONFIG_SERIAL_TERMIOS) && defined(CONFIG_PSEUDOTERM)
#ifdef CONFIG_PSEUDOTERM
/****************************************************************************
* Public Function Prototypes
@ -59,5 +59,5 @@ int openpty(FAR int *master, FAR int *slave, FAR char *name,
}
#endif
#endif /* CONFIG_SERIAL_TERMIOS && CONFIG_PSEUDOTERM */
#endif /* CONFIG_PSEUDOTERM */
#endif /* __INCLUDE_PTY_H */

View file

@ -25,8 +25,8 @@
"basename","libgen.h","","FAR char *","FAR char *"
"btowc","wchar.h","","wint_t","int"
"calloc","stdlib.h","","FAR void *","size_t","size_t"
"cfgetspeed","termios.h","defined(CONFIG_SERIAL_TERMIOS)","speed_t","FAR const struct termios *"
"cfsetspeed","termios.h","defined(CONFIG_SERIAL_TERMIOS)","int","FAR struct termios *","speed_t"
"cfgetspeed","termios.h","","speed_t","FAR const struct termios *"
"cfsetspeed","termios.h","","int","FAR struct termios *","speed_t"
"chdir","unistd.h","!defined(CONFIG_DISABLE_ENVIRON)","int","FAR const char *"
"clock","time.h","","clock_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"
"swprintf","wchar.h","","int","FAR wchar_t *","size_t","FAR const wchar_t *","..."
"syslog","syslog.h","","void","int","FAR const IPTR char *","..."
"tcflush","termios.h","defined(CONFIG_SERIAL_TERMIOS)","int","int","int"
"tcgetattr","termios.h","defined(CONFIG_SERIAL_TERMIOS)","int","int","FAR struct termios *"
"tcsetattr","termios.h","defined(CONFIG_SERIAL_TERMIOS)","int","int","int","FAR const struct termios *"
"tcflush","termios.h","","int","int","int"
"tcgetattr","termios.h","","int","int","FAR struct termios *"
"tcsetattr","termios.h","","int","int","int","FAR const struct termios *"
"telldir","dirent.h","","off_t","FAR DIR *"
"time","time.h","","time_t","FAR time_t *"
"tolower","ctype.h","","int","int"

Can't render this file because it has a wrong number of fields in line 2.

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
CSRCS += lib_cfspeed.c lib_cfmakeraw.c lib_isatty.c lib_tcflush.c

View file

@ -50,6 +50,8 @@ void cfmakeraw(FAR struct termios *termiosp)
| INLCR | IGNCR | ICRNL | IXON);
termiosp->c_oflag &= ~OPOST;
termiosp->c_lflag &= ~(ECHO | ECHONL | ICANON | ISIG | IEXTEN);
#ifdef CONFIG_SERIAL_TERMIOS
termiosp->c_cflag &= ~(CSIZE | PARENB);
termiosp->c_cflag |= CS8;
#endif
}

View file

@ -46,8 +46,6 @@
* responds wo tcgetattr() without an error -- that it, the driver supports
* the NuttX TCGETS ioctl command.
*
* Of course, that can only be true if CONFIG_SERIAL_TERMIOS=y.
*
****************************************************************************/
int isatty(int fd)