Input modes
Each device can be in a raw or edited input mode.
Raw input mode
In raw mode, io-char performs no editing on received characters. This reduces the processing done on each character to a minimum and provides the highest performance interface for reading data.
Fullscreen programs and serial communications programs are examples of applications that use a character device in raw mode.
In raw mode, the hardware-handling code receives each character into the raw input buffer. When an application requests data from the device, it can specify under what conditions an input request is to be satisfied. Until the conditions are satisfied, the driver won't process the incoming data (beyond storing it), and the driver won't return any data to the application. The normal case of a simple read by an application would block until at least one character was available.
In the case where multiple conditions are specified, the read will be satisfied when any one of them is satisfied.
- MIN
- The qualifier MIN is useful when an application
has knowledge of the number of characters it expects to receive.
Any protocol that knows the character count for a frame of data can use MIN to wait for the entire frame to arrive. This significantly reduces IPC and process scheduling. MIN is often used in conjunction with TIME or TIMEOUT. MIN is part of the POSIX standard.
- TIME
- The qualifier TIME is useful when an application is receiving streaming data and wishes to be notified when the data stops or pauses. The pause time is specified in 1/10ths of a second. TIME is part of the POSIX standard.
- TIMEOUT
- The qualifier TIMEOUT is useful when an application has
knowledge of how long it should wait for data before timing out.
The timeout is specified in 1/10ths of a second.
Any protocol that knows the character count for a frame of data it expects to receive can use TIMEOUT. This in combination with the baud rate allows a reasonable guess to be made when data should be available. It acts as a deadman timer to detect dropped characters. It can also be used in interactive programs with user input to time out a read if no response is available within a given time.
TIMEOUT is a QNX OS extension and is not part of the POSIX standard.
- FORWARD
- The qualifier FORWARD is useful when a protocol
is delimited by a special framing character. For example,
the PPP protocol used for TCP/IP over a serial
link starts and ends its packets with a framing character.
When used in conjunction with TIMEOUT, the
FORWARD character can greatly improve the
efficiency of a protocol implementation. The protocol
process will receive complete frames, rather than character
by character. In the case of a dropped framing character,
TIMEOUT or TIME can be used to quickly recover.
This minimizes the amount of IPC work for the OS and results in a much lower processor utilization for a given TCP/IP data rate. It's interesting to note that PPP doesn't contain a character count for its frames. Without the data-forwarding character, an implementation might be forced to read the data one character at a time.
FORWARD is a QNX OS extension and is not part of the POSIX standard.
The ability to
push
the processing for application notification into the service-providing components of the OS reduces the frequency with which user-level processing must occur. This minimizes the IPC work to be done in the system and frees CPU cycles for application processing. In addition, if the application implementing the protocol is executing on a different network node than the communications port, the number of network transactions is also minimized.For intelligent, multiport serial cards, the data-forwarding character recognition can also be implemented within the intelligent serial card itself, thereby significantly reducing the number of times the card must interrupt the host processor for interrupt servicing.
Edited input mode
In edited mode, io-char performs line-editing
operations on each received character. Only when a line is
completely entered
—typically when a carriage
return (CR) is received—will the line of data be made
available to application processes. This mode of operation
is often referred to as canonical or sometimes
cooked
mode.
Most non-full-screen applications run in edited mode, because this allows them to deal with the data a line at a time rather than have to examine each character received, scanning for an end-of-line character. In this mode, the raw input buffer receives each character through the hardware handling code. Unlike raw mode where the driver only processes data when the input request satisfies the conditions, the driver processes each byte as it arrives.
When the driver runs, code in io-char will examine the character and apply it to the canonical buffer in which it's building a line. When a line is complete and an application requests input, the line will be transferred from the canonical buffer to the application—the transfer is direct from the canonical buffer to the application buffer without any intervening copies.
The editing code correctly handles multiple pending input lines in the canonical buffer and allows partial lines to be read. This can happen, for example, if an application asked only for 1 character when a 10-character line was available. In this case, the next read will continue where the last one left off.
- LEFT
- Move the cursor one character to the left.
- RIGHT
- Move the cursor one character to the right.
- HOME
- Move the cursor to the beginning of the line.
- END
- Move the cursor to the end of the line.
- ERASE
- Erase the character to the left of the cursor.
- DEL
- Erase the character at the current cursor position.
- KILL
- Erase the entire input line.
- UP
- Erase the current line and recall a previous line.
- DOWN
- Erase the current line and recall the next line.
- INS
- Toggle between insert mode and typeover mode (every new line starts in insert mode).
Line-editing characters vary from terminal to terminal. The console always starts out with a full set of editing keys defined.
stty term=ansi </dev/ser1