Difference between revisions of "TTY Driver"

From Embedded Xinu
Jump to navigation Jump to search
Line 8: Line 8:
  
 
== Read ==
 
== Read ==
The TTY driver reads input in lines. Input is buffered in a secondary buffer and cooked (if not in RAW mode) until the secondary buffer is full or a carriage return (CR or '\r') or line feed (LF or '\n') is encountered. When pressing the 'Enter' key on the keyboard, xinu-console is configured to send '\n' to the backend.
+
The TTY driver reads characters from an underlying device, normally a [[UART Driver|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 <code>'\r'</code>) 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 <code>'\b'</code>) 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 <code>'\0'</code>) are ignored.
  
When not in RAW input mode, the TTY driver cooks backspace (BS or '\b') and delete (DEL or ASCII character 0x7F). BS and DEL remove the last character from the secondary buffer, and decrease the secondary buffer count by one. When in RAW mode, set using "control(device id, TTC_IRAW, TRUE, NULL)," and BS and DEL are ignored.
+
When the end of file (Control+D) character is read, the tty stops reading from the underlying device. Subsquent calls to <code>ttyRead</code> will attempt to staisfy the request from the TTY's input buffer, otherwise <code>EOF</code> 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 <code>control(''device id'', TTY_IOC_EOF, NULL NULL)</code> or <code>control(''device id'', TTY_IOC_CBREAK, NULL NULL)</code> for EOF and CBREAK, respectively.
 
 
The TTY driver sets a flag if EOF (EOT or Control-D) or CBREAK (ETX or Control-C) are seen in the input ready from the secondary buffer. The flags can be checked using "control(device id, TTC_EOF, NULL NULL)" or "control(device id, TTC_CBREAK, NULL NULL)" for EOF and CBREAK, respectively. When not in RAW mode the EOT character is converted to the EOF constant (-2) defined in XINU.
 
 
 
''This section needs updating''
 
  
 
== Write ==
 
== Write ==

Revision as of 20:26, 11 July 2007

Clockimportant.png This article or section needs to be updated.
Parts of this article or section have been identified as no longer being up to date.
Please update the article to reflect recent changes, and remove this template when finished.

TtyDriver.png

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.

Read

The TTY driver reads characters from an underlying device, 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.

Write

When not in RAW output mode, the TTY driver cooks line feeds (also known as LF, \n, or ASCII character 0x0A) and carriage returns (also known as CR, \r, or ASCII character 0x0D). 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. When in RAW mode, set using "control(device id, TTC_ORAW, TRUE, NULL)", CR and LF are not cooked.

This section needs updating

See also