|
|
#include <sys/tty.h>
int ttclose(struct tty tp); / l_close /int ttin(struct tty tp, int code); / l_input /
int ttioctl(strcut tty tp, int cmd, int arg, int mode); / l_ioctl /
int ttopen(struct tty tp); / l_open /
int ttout(struct tty tp); / l_output /
int ttread(struct tty tp); / l_read /
int ttwrite(struct tty tp); / l_write /
void ttinit(struct tty tp);int ttrdchk(struct tty tp);
int ttselect(struct tty tp, int rw);
int ttyflush(struct tty tp, int rdwrt);
int ttywait(struct tty tp);
t_proc
member, and the line discipline as the
t_line
member of the tty structure. The device
driver declares an array of tty structures as large as the
possible number of minor devices for the device.
t_canq
and t_rawq
;
set FWRITE to release the output queue,
t_outq
.
t_outq
. It returns 0 (zero) if no characters
are present.
ttrdchk returns 1 if there are characters present in the
read queues, t_rawq
or t_canq
. It returns 0
(zero) if no characters are present.
The following TTY routines are referenced by line discipline zero members. Multithreaded drivers should call these routines through the run_ld(D3oddi) function.
l_close
. It is
called by the driver's xxclose routine to remove access to
a TTY device for a user process calling
close(S) .
The following actions occur:
t_outq
to empty to the output
device.
t_canq
and t_rawq
are released.
t_state
member of the
tty structure pointed to by tp.
t_lflag
member of the
tty structure pointed to by tp.
l_input
. It is
called from a driver's xxintr routine to process and move
characters placed in t_rbuf
to the raw character queue,
t_rawq
. ttin handles signals issued from the
keyboard such as SIGINT or SIGQUIT, echoing of
input characters to the display, and mapping of input characters to
character sequences including international character mapping.
If the value of code is passed as L_BREAK to indicate a break interrupt on the line, ttin takes the following actions:
t_rawq
, t_canq
and t_outq
are
released.
The raw buffer is then tested to see if any characters require processing. ttin then does the following:
t_iflag
; ICRNL, IGNCR, INLCR, or IUCLC
is performed.
t_rawq
exceeds its
high water mark. TBLOCK is also set in
t_state
. ttin will flush the input buffers
altogether if t_rawq
exceeds the absolute high water
mark. This prevents all the ccblocks being taken by the
device if its output cannot be stopped.
t_lflag
, the characters in
t_rbuf
are checked against the Interrupt, Quit, Suspend
and Switch control characters in the array t_cc
(a member
of the tty structure pointed to by tp).
If the character is Interrupt or Quit, SIGINT or
SIGQUIT is sent to the process group and the input and
output queues are conditionally flushed. (Flushing is not performed
if NOFLSH is set in t_lflag
.)
If the character is Suspend, SIGTSTP is sent to the process group and only the input queues are conditionally flushed.
If the character is Switch, both input and output queues are conditionally flushed and xxproc is called, with command argument T_SWTCH, to inform the driver.
t_lflag
(for canonical input
processing), each character in the input buffer, t_rbuf
,
is processed in turn.
The character is checked against the Erase, Line Kill, End of File,
and End of Line characters in t_cc
.
Backspace and Space are echoed to the output queue,
t_outq
, for the Erase character if ECHOE is set
in t_lflag
.
Line Kill is echoed to the output queue for the Line Kill character
if ECHOK is set in t_lflag
If ECHO is set in t_lflag
, the character is
echoed to the output queue. (Erase is echoed as Back Space and Line
Kill as Newline.)
t_delct
is set to the number of End of Line or End of File
characters in t_rbuf
.
t_lflag
, ttin
checks whether raw input is possible. If so, its sets
t_delct
to the number of characters in t_rbuf
.
If ECHO is set in t_lflag
, the characters in
t_rbuf
are echoed to the output queue, t_outq
.
t_delct
is
non-zero.
t_rawq
.
l_ioctl
. The
driver's xxioctl routine calls
ttiocom(D3oddi)
which in turn calls ttioctl to allocate, deallocate, or
move the contents of terminal buffers. The cmd argument to
ttioctl can take the following values:
l_open
. It is
called from a driver's xxopen routine in response to a
call to
open(S)
to open a serial line. The following actions are performed:
t_lflag
and the user is
not root, EBUSY is set in u.u_error
and errno; ttopen then returns.
l_output
. A
driver's xxproc routine calls ttout to move data
to the output buffer. ttout performs the following actions:
t_outq
, to the output
buffer, t_tbuf
.
t_oflag
. A time delay on
output is indicated by the two character sequence; QESC
followed by QESC ORed with the delay in clock
ticks.
l_read
. It is
called from a driver's xxread routine in response to a
call to
read(S)
to read data from a device. ttread performs the following
actions:
t_lflag
, data in
t_rawq
is processed for Backslash (escaped characters),
Backspace, Line Kill, and End of File. The data is transferred to
the canonical input queue, t_canq
.
t_cc
are managed for handling
raw input.
u.u_count
characters from the canonical input
queue (ICANON set), or from the raw inut queue
(ICANON not set), are moved to the user address space.
t_state
.
l_write
. It
is called by a driver's xxwrite routine in response to a
call to
write(S)
to write data to a device. ttwrite performs the following
actions:
u.u_error
is set to EIO if there is no carrier
or the process group has been orphaned; ttwrite then
returns immediately.
t_outq
, exceeds the high water mark for output. If
so, call the driver's xxproc routine with
command argument set to T_OUTPUT. The process is
then put to sleep on the address of t_outq
at a priority
of TTOPRI.
If a signal is sent to the sleeping process,
control returns to the calling user process
and sets the EINTR error
in u.u_error
and errno.
t_outq
.
u.u_error
is set to EFAULT if a paging fault
occurs while attempting to copy the data from user space.
u.u_base
and u.u_count
are updated to reflect
the amount of data transferred.
The following are tty utility routines which may be called from a driver:
t_line
), terminal input control
(t_iflag
), terminal output control (t_oflag
),
and line discipline terminal control (t_lflag
) are set to
0 (zero).
t_cflag
) is set to 9600
baud (SSPEED), 8 bits (CS8), enable receiver
(CREAD), and hang up on last close (HUPCL).
t_rawq
or t_canq
(depending on
whether ICANON is set in t_lflag
) , and the
device carrier is present (CARR_ON is set in
t_state
).
Otherwise, ttrdchk returns 0 (zero).
Set the argument rw to SELREAD to disable blocking for reading; to SELWRITE to disable blocking for writing.
Do not call sleep(D3oddi) before calling ttselect.
Do not call ttselect from an interrupt routine.
t_outq
, or from the two read queues, t_canq
and
t_rawq
.
Set FREAD in the argument rdwrt to release the read queues; FWRITE to release the write queue. These two values may be ORed together to free all three queues.
Releasing the write queue causes the driver's xxproc
routine to be called with the command argument
T_WFLUSH set. If OASLP is set in
t_state
, any processes sleeping on the address of
t_outq
are woken and OASLP unset. If
TTIOW is set in t_state
, any processes sleeping
on the address of t_oflag
are woken and TTIOW
unset.
Releasing the read buffers causes the driver's xxproc
routine to be called with the command argument
T_RFLUSH set. If IASLP is set in
t_state
, any processes sleeping on the address of
t_rawq
are woken and IASLP unset.
t_outq
, or t_state
is
set to BUSY or TIMEOUT, then t_state
is ORed with TTIOW and the process is put to
sleep on the address of t_oflag
at TTOPRI. On
receiving a wakeup signal, control returns to the user process and
EINTR is set in u.u_error
and errno
in the user program.
ttioctl, ttwrite, ttselect and ttyflush all set priority level 5 internally using spltty.