Listing 1. A Simple Implementation of the set_termios Call
#define RELEVANT_IFLAG(iflag)
(iflag & (IGNBRK|BRKINT|IGNPAR|PARMRK|INPCK))
static void
tiny_set_termios (struct tty_struct *tty,
struct termios *old_termios)
{
unsigned int cflag;
cflag = tty->termios->c_cflag;
/* check that they really want us to change
* something */
if (old_termios) {
if ((cflag == old_termios->c_cflag) &&
(RELEVANT_IFLAG(tty->termios->c_iflag) ==
RELEVANT_IFLAG(old_termios->c_iflag))) {
printk (KERN_DEBUG
" - nothing to change...\n");
return;
}
}
/* get the byte size */
switch (cflag & CSIZE) {
case CS5:
printk (KERN_DEBUG " - data bits = 5\n");
break;
case CS6:
printk (KERN_DEBUG " - data bits = 6\n");
break;
case CS7:
printk (KERN_DEBUG " - data bits = 7\n");
break;
default:
case CS8:
printk (KERN_DEBUG " - data bits = 8\n");
break;
}
/* determine the parity */
if (cflag & PARENB)
if (cflag & PARODD)
printk (KERN_DEBUG " - parity = odd\n");
else
printk (KERN_DEBUG " - parity = even\n");
else
printk (KERN_DEBUG " - parity = none\n");
/* figure out the stop bits requested */
if (cflag & CSTOPB)
printk (KERN_DEBUG " - stop bits = 2\n");
else
printk (KERN_DEBUG " - stop bits = 1\n");
/* figure out the flow control settings */
if (cflag & CRTSCTS)
printk (KERN_DEBUG
" - RTS/CTS is enabled\n");
else
printk (KERN_DEBUG
" - RTS/CTS is disabled\n");
/* determine software flow control */
/* if we are implementing XON/XOFF,
* set the start and stop character in the
* device */
if (I_IXOFF(tty) || I_IXON(tty)) {
unsigned char stop_char = STOP_CHAR(tty);
unsigned char start_char = START_CHAR(tty);
/* if we are implementing
* INBOUND XON/XOFF */
if (I_IXOFF(tty))
printk (KERN_DEBUG
" - INBOUND XON/XOFF "
"is enabled, "
"XON = %2x, XOFF = %2x",
start_char, stop_char);
else
printk (KERN_DEBUG
" - INBOUND XON/XOFF "
"is disabled");
/* if we are implementing
* OUTBOUND XON/XOFF */
if (I_IXON(tty))
printk (KERN_DEBUG
" - OUTBOUND XON/XOFF "
" is enabled, "
"XON = %2x, XOFF = %2x",
start_char, stop_char);
else
printk (KERN_DEBUG
" - OUTBOUND XON/XOFF "
" is disabled");
}
/* get the baud rate wanted */
printk (KERN_DEBUG
" - baud rate = %d",
tty_get_baud_rate(tty));
return;
}
Copyright © 1994 - 2018 Linux Journal. All rights reserved.