> 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=