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
+4 -3
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"
-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_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.
+1 -42
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;
}