TTY(4)
NAME
tty − general-purpose terminal I/O device driver (type tty)
SYNOPSIS
#include <slu.h>
#include <tty.h>
read(device buffer, length)
write(device, buffer, length)
open(device, name)
close(device)
control(device, function, arg1, arg2)
init(device)
DESCRIPTION
The tty device driver provides input and output for a full-duplex ascii terminal device. On most Xinu systems, device CONSOLE is of type tty.
Currently implemented on a Digital Equipment Corporation serial line unit (SLU) like that on the DLV11 and MXV11, the driver expects one interrupt per character on both input and output.
The tty driver operates in one of three modes, with switching between the modes determined dynamically. In raw mode, it passes incoming characters to the reading process without further processing. In cbreak mode, the driver honors XON-XOFF flow control, character echo, and mapping between carriage return and line feed. In cooked mode the driver behaves like cbreak mode, but also handles line editing with backspace and line kill keys. Characters are processed according to the driver mode when they arrive, and are placed in a queue from which upper-half routines extract them. Echoing, presentation of control characters, and editing are controlled by several fields in the driver control structure, and may be changed dynamically.
The upper-half routines behave as follows:
read(device,buffer,length)
Reads up to one line into the user’s buffer, stopping on an END-OF-FILE or NEWLINE character, or after length characters have been supplied. As a special case, if length is zero, the driver reads whatever characters are available in the input buffer (possibly zero). In cooked mode, read blocks until a line has been typed.
write(device,buffer,length)
Writes length characters from the user’s buffer, mapping CARRIAGE RETURN to NEWLINE as specified by field ocrlf of the driver control structure. Write may block if the output exceeds the currently available buffer space.
getc(device)
Reads a single character and returns it as the function value.
putc(device,char)
Writes character char.
open(device,name)
Returns OK if character string name is null, and SYSERR otherwise, taking no action except generating a return value.
close(device)
Returns OK without taking any action.
init(device)
Initializes the driver. Note: for historical reasons, device CONSOLE is initialized to cooked mode with echo, visual control character printing, and line editing enabled, while other devices are initialized to raw mode.
control(device,function)
Controls the driver and provides non-transfer operations. The valid functions are:
TCSETBRK − set the line into the “break” state.
TCRSTBRK − reset the line, turning off “break” state.
TCNEXTC − lookahead one character without reading it.
TCMODER − change the driver to raw mode.
TCMODEC − change the driver to cooked mode.
TCMODEK − change the driver to cbreak mode.
TCECHO − turn on character echo.
TCNOECHO − turn off character echo.
TCICHARS − return a count of characters in the input buffer.
DIAGNOSTICS
Character errors are reported by turning on the high-order bit of the character.
NOTES
The version 6 driver used buffer counts as exact requests; version 7 is line oriented. Error reporting should be improved.
December 01, 1986 — Xinu Programmer’s Manual