|
AquilaOS documentation
How it works, and its code
|
Serial ports as terminals: /dev/ttyS0 and up (character device 4, 64 and up). More...
#include <core/system.h>#include <dev/dev.h>#include <dev/tty.h>#include <dev/uart.h>#include <fs/posix.h>#include <ds/queue.h>#include <ds/ringbuf.h>#include <sys/sched.h>Go to the source code of this file.
Macros | |
| #define | UART_BUF 64 |
| #define | UART_RING 4096 |
| #define | UART_MAX 192 |
Functions | |
| void | uart_receive_handler (struct uart *u, size_t size) |
| Takes characters a UART received, and gives them to its terminal. | |
| void | uart_transmit_handler (struct uart *u, size_t size) |
| Sends characters that the terminal output to its UART. | |
| ssize_t | uart_master_write (struct tty *tty, size_t size, void *buf) |
| Takes the terminal's output, and sends it to the UART at once: the UART drivers don't use a "transmitter empty" interrupt. | |
| static void | uart_input_flush (struct tty *tty) |
| Drops the input waiting to be read (tcflush()). | |
| ssize_t | uart_slave_write (struct tty *tty, size_t size, void *buf) |
| Takes the terminal's input, after its line editing, for the readers of the UART's device. | |
| static struct uart * | uart_get (devid_t minor) |
| Returns the UART of a minor (they start at 64), or NULL if there's none. | |
| ssize_t | uart_read (struct devid *dd, off_t offset, struct iobuf *io) |
| Reads a UART's terminal. | |
| ssize_t | uart_write (struct devid *dd, off_t offset, struct iobuf *io) |
| Writes to a UART's terminal. | |
| static int | uart_file_eof (struct file *file) |
| Returns whether a read that found no data is at the end of the file (the terminal says, from its mode). | |
| static uint64_t | uart_read_timeout (struct file *file) |
| Returns how long a read may wait for data, from the terminal's mode (VTIME), or 0 for no limit. | |
| static int | uart_can_read (struct file *file, size_t size) |
| Returns whether a read wouldn't have to wait. | |
| int | uart_ioctl (struct devid *dd, int request, void *argp) |
| Handles a UART terminal's ioctl()s, which are the terminal's. | |
| static int | uart_setup (struct uart *u, struct vnode *vnode) |
| Sets a UART up the first time it is opened: its rings, its terminal, and the UART itself. | |
| int | uart_file_open (struct file *file) |
| Opens a UART's device, setting the UART up the first time. | |
| int | uart_register (int id, struct uart *u) |
| Registers a UART, as /dev/ttyS<id>. | |
Variables | |
| static struct uart * | devices [192] = {0} |
| struct dev | uart |
Serial ports as terminals: /dev/ttyS0 and up (character device 4, 64 and up).
A UART driver (8250, PL011) registers its UARTs here, and this layer makes each one a terminal: it connects the UART to the terminal layer (generic.c), which does the line editing, with a ring each way. What the UART receives goes to the terminal; what the terminal outputs goes to the UART. A UART is set up the first time it is opened.
Definition in file uart.c.
| #define UART_BUF 64 |
Definition at line 21 of file uart.c.
Referenced by uart_receive_handler().
| #define UART_MAX 192 |
Definition at line 115 of file uart.c.
Referenced by uart_get().
| #define UART_RING 4096 |
Definition at line 25 of file uart.c.
Referenced by uart_setup().
Returns whether a read wouldn't have to wait.
Definition at line 195 of file uart.c.
References DEV_MINOR, uart::in, uart::tty, tty_can_read(), uart_can_read(), and uart_get().
Referenced by uart_can_read().
|
static |
Returns whether a read that found no data is at the end of the file (the terminal says, from its mode).
Definition at line 180 of file uart.c.
References DEV_MINOR, uart::tty, tty_eof(), uart_file_eof(), and uart_get().
Referenced by uart_file_eof().
| int uart_file_open | ( | struct file * | file | ) |
Opens a UART's device, setting the UART up the first time.
| file | the file being opened |
Definition at line 251 of file uart.c.
References DEV_MINOR, uart::read_queue, uart::tty, tty_open(), uart_file_open(), uart_get(), uart_setup(), and uart::write_queue.
Referenced by uart_file_open().
Returns the UART of a minor (they start at 64), or NULL if there's none.
Without virtual terminals, minor 1 (/dev/console) is the first UART too.
Definition at line 120 of file uart.c.
References devices, NULL, uart_get(), and UART_MAX.
Referenced by uart_can_read(), uart_file_eof(), uart_file_open(), uart_get(), uart_ioctl(), uart_read(), uart_read_timeout(), and uart_write().
|
static |
Drops the input waiting to be read (tcflush()).
Definition at line 91 of file uart.c.
References uart::in, tty::p, and uart_input_flush().
Referenced by uart_input_flush(), and uart_setup().
| int uart_ioctl | ( | struct devid * | dd, |
| int | request, | ||
| void * | argp ) |
Handles a UART terminal's ioctl()s, which are the terminal's.
| dd | the device's number |
| request | the request |
| argp | its argument |
Definition at line 209 of file uart.c.
References devid::minor, uart::tty, tty_ioctl(), uart_get(), and uart_ioctl().
Referenced by uart_ioctl().
Takes the terminal's output, and sends it to the UART at once: the UART drivers don't use a "transmitter empty" interrupt.
| tty | the terminal |
| size | the output's size, in bytes |
| buf | the output |
Definition at line 82 of file uart.c.
References uart::out, tty::p, uart_master_write(), and uart_transmit_handler().
Referenced by uart_master_write(), and uart_setup().
Reads a UART's terminal.
A process of a background group gets SIGTTIN instead.
| dd | the device's number |
| offset | not used: a terminal has no offset |
| io | where to put what is read |
Definition at line 143 of file uart.c.
References uart::in, devid::minor, iobuf::resid, uart::tty, tty_background(), uart_get(), and uart_read().
Referenced by uart_read().
Returns how long a read may wait for data, from the terminal's mode (VTIME), or 0 for no limit.
Definition at line 188 of file uart.c.
References DEV_MINOR, uart::tty, tty_read_timeout(), uart_get(), and uart_read_timeout().
Referenced by uart_read_timeout().
Takes characters a UART received, and gives them to its terminal.
The UART's driver calls it from its interrupt handler.
| u | the UART |
| size | how many characters to take from it |
Definition at line 35 of file uart.c.
References MIN, uart::read_queue, uart::receive, uart::tty, tty_master_write(), UART_BUF, uart_receive_handler(), and waitq_wakeup().
Referenced by pl011_irq(), uart_8250_irq(), and uart_receive_handler().
| int uart_register | ( | int | id, |
| struct uart * | u ) |
Registers a UART, as /dev/ttyS<id>.
| id | its number (below 192), or -1 for the first free one |
| u | the UART |
Definition at line 278 of file uart.c.
References devices, uart::name, printk(), and uart_register().
Referenced by pl011_init(), uart_8250_attach(), and uart_register().
Sets a UART up the first time it is opened: its rings, its terminal, and the UART itself.
Returns 0 or a negative errno.
Definition at line 218 of file uart.c.
References curproc, uart::in, uart::init, tty::input_flush, NULL, uart::out, vnode::ref, uart::tty, tty_new(), uart_input_flush(), uart_master_write(), UART_RING, uart_setup(), uart_slave_write(), tty::vnode, and uart::vnode.
Referenced by uart_file_open(), and uart_setup().
Takes the terminal's input, after its line editing, for the readers of the UART's device.
| tty | the terminal |
| size | the input's size, in bytes |
| buf | the input |
Definition at line 109 of file uart.c.
References uart::in, tty::p, and uart_slave_write().
Referenced by uart_setup(), and uart_slave_write().
Sends characters that the terminal output to its UART.
| u | the UART |
| size | how many characters to send, at most |
Definition at line 59 of file uart.c.
References MIN, uart::out, uart::transmit, uart_transmit_handler(), waitq_wakeup(), and uart::write_queue.
Referenced by uart_8250_irq(), uart_master_write(), and uart_transmit_handler().
Writes to a UART's terminal.
With TOSTOP set, a process of a background group gets SIGTTOU instead.
| dd | the device's number |
| offset | not used: a terminal has no offset |
| io | what to write |
Definition at line 163 of file uart.c.
References devid::minor, tty::tios, uart::tty, tty_background(), tty_slave_write(), tty_write_iobuf(), uart_get(), and uart_write().
Referenced by uart_write().
|
static |
Definition at line 26 of file uart.c.
Referenced by uart_get(), and uart_register().
| struct dev uart |