Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

[Linux] difference between a serial driver and tty driver

1,235 views
Skip to first unread message

Andy Falanga

unread,
Apr 19, 2016, 9:48:31 PM4/19/16
to
I have been given a task to write a serial driver for a UART. This is my first. I've read chapter 18 of LDD3 and it was quite informative. I then got the examples for this book from https://github.com/martinezjavier/ldd3 in order to study them.

It is interesting in to note that in the directory, ldd3/tty, there are sources for two drivers: tiny_serial.ko and tiny_tty.ko. I'm guessing that something has changed since LDD3 was written. This interesting slide-set-made-pdf http://free-electrons.com/doc/serial-drivers.pdf and the file Documentation/serial/driver from the source tree, lead me to believe that I may be more interested in writing a "serial" driver instead of a "tty" driver.

Can someone here enlighten me? What is the difference? Where can I find better descriptive documentation, as opposed to a slide set intended for a lecture and reference documentation, from which I can learn more?

Thanks,
Andy

Joe Pfeiffer

unread,
Apr 19, 2016, 11:05:59 PM4/19/16
to
That slide set is actually pretty good (especially page 2, showing the
TTY driver serial_core sitting on top of a serial driver).

A tty is the abstraction for serial IO presented to a program that runs
on a terminal (or in a terminal window -- the program doesn't normally
know the difference). It understands presenting a bunch of characters
to the program; it understands using backspace keys to erase characters
before the program sees them. It might be running on top of a real
serial device, or it might be running on top of something like
characters being fed to a terminal window under X.

A serial device is a driver for a real hardware device like a UART. It
understands things like bit rates, parity, modem control lines, and
interrupts. It will pass its data to a tty device.

I haven't done anything with serial drivers since long before the
development of serial_core, so I'm sure someone out there can correct
the details here. But that's the gist of it.

Gordon Burditt

unread,
Apr 20, 2016, 2:09:32 AM4/20/16
to
> I have been given a task to write a serial driver for a UART. This is my f=
> irst. I've read chapter 18 of LDD3 and it was quite informative. I then g=
> ot the examples for this book from https://github.com/martinezjavier/ldd3 i=
> n order to study them.

I'm not familiar with this software specifically, or Linux in general,
but I have dealt with terminal drivers in general. Lots of what you are
asking about goes back at least to UNIX v7 and some of it to UNIX v6.

> It is interesting in to note that in the directory, ldd3/tty, there are sou=
> rces for two drivers: tiny_serial.ko and tiny_tty.ko. I'm guessing that so=
> mething has changed since LDD3 was written. This interesting slide-set-mad=
> e-pdf http://free-electrons.com/doc/serial-drivers.pdf and the file Documen=
> tation/serial/driver from the source tree, lead me to believe that I may be=
> more interested in writing a "serial" driver instead of a "tty" driver.

A tty driver handles a lot of common code used on serial ports,
built-in modems, PC consoles (including the PC keyboard),
pseudo-terminals (ptys) and sometimes parallel ports connected to
printers. It does not talk directly to hardware. Lots, but not
all, of the arguments to "stty" are handled by the tty driver,
including:

- editing characters (such as deleting the last character typed
(typically ^H or DEL), re-drawing the line (typically ^R), erasing
the input line (typically ^U), etc.
- characters that generate signals, such as SIGINTR (typically ^C on
a PC keyboard) and various job control characters.
- translation to and from CR to LF to CRLF line endings
- gathering the input into lines.
- tab expansion, if any
- Does most of the buffering of characters.
and some of these parameters are passed through to the hardware driver:
- flow control, if any, may be passed through to the hardware driver.
- passes through settings for hardware modes (e.g. speed) to
the hardware driver.

Some tty drivers have additions to the standard line discipline,
which can implement some packet-oriented protocols such as PPP and
SLIP, and perhaps talk over the network to a box that has multiple
serial ports attached.

A hardware driver (e.g. serial port, uart, console video & keyboard) handles:
- Actually getting characters to and from the hardware and
passes these to/from the tty driver.
- Usually contains the interrupt service routines for the
hardware.
- Actually makes such settings as input and/or output speed,
number of bits per character, odd/even/no/space/mark parity,
number of stop bits (1/1.5/2), take effect. What can be set
often depends on the controls available in hardware.
- Allows setting and reading modem control lines, if the hardware
has them.
- Note that ptys have no hardware, but a pty driver passes
characters between the "master" and "slave" sides of a pty,
processing them through the tty driver.
- In the case of a PC console, contains a terminal emulator that
translates a stream of characters (including control characters
and escape sequences) to the memory-mapped video memory, and
translates keyboard make/break codes to character codes.

Ttys that operate over a network are generally implemented using
a daemon process and a pty.

Terminal windows that operate on a GUI (e.g. xterm) are generally
implemented using a process (e.g. child of sshd) and a pty.

> Can someone here enlighten me? What is the difference? Where can I find b=
> etter descriptive documentation, as opposed to a slide set intended for a l=

Andy Falanga

unread,
Apr 22, 2016, 3:07:00 PM4/22/16
to
On Tuesday, April 19, 2016 at 9:05:59 PM UTC-6, Joe Pfeiffer wrote:
Thank you Joe. This is quite informative. I think I'm getting a better picture. This seems to confirm what I was beginning to think.

rahulr...@gmail.com

unread,
Jun 24, 2017, 11:55:11 PM6/24/17
to
Hi Andy,
Did you get a chance to run tiny tty and serial driver from ldd3 book/code.
I tried to run tty driver, by following command but it hit crash-
minicom -D /dev/ttty0
Also later i tried to write using echo/cat, but nothing worked.

Please let me know how to run these drivers.


Thanks~
0 new messages