TTY Driver

From Embedded Xinu
Revision as of 20:30, 11 July 2007 by Agember (talk | contribs)
Jump to navigation Jump to search

The TTY driver is built on top of the UART driver (or another appropriate char-oriented device). The driver is responsible for sending and receiving character input between a user level application, such as the XINU Shell, and a char-oriented hardware driver. The TTY driver uses a line disciple that reads and provides input in lines. When not in raw mode, the TTY driver also cooks both input and output.

Open & Close

Open associates a TTY with an underlying char-oriented hardware driver. The underlying device should already be initialized. A TTY is allocated from the available TTY devices and its circular buffers are initialized.

Close disasociates a TTY from its underlying device. It also makes the TTY available to be allocated to other processes.


The TTY driver reads characters from an underlying device driver, normally a UART. Input is read from the underlying device in lines and buffered in the TTY's input buffer. Lines may be terminated with the line feed (LF or '\n') or carriage return (CR or '\r') characters. Read requests are not satsified until a full line has been read, or the TTY's buffer is full.

When the TTY is not in raw input mode, lines of input are cooked. Backspace (BS or '\b') and delete (DEL or ASCII character 0x7F) remove the last character from the TTY's input buffer, and decrease the secondary buffer count by one. Escape sequences and the null character (NUL or '\0') are ignored.

When the end of file (Control+D) character is read, the tty stops reading from the underlying device. Subsquent calls to ttyRead will attempt to staisfy the request from the TTY's input buffer, otherwise EOF will be returned. The TTY driver sets a flag if EOF (EOT or Control-D) or CBREAK (ETX or Control-C) are seen in the input that satisfies the read request. The flags can be checked using control(device id, TTY_IOC_EOF, NULL NULL) or control(device id, TTY_IOC_CBREAK, NULL NULL) for EOF and CBREAK, respectively.


The TTY driver does not buffer output; it writes characters to an underlying device driver. When not in RAW output mode, the TTY driver cooks line feeds (LF or '\n') and carriage returns (CR or '\r'). The ttyWrite function always ensures CRLF is written to the output buffer when any of the following escape sequences are to be written: '\r', '\n', or '\r\n'. Backspace and delete are cooked to '\b\0\b' to remove the last character output. Null characters are ignored. When in RAW mode, set using control(device id, TTC_ORAW, TRUE, NULL), no output is cooked

See also