Serial Console

The serial console is implemented in os/drivers/console/serial_console.c.

Implements a serial console that takes output from a higher-level component, like, printk or a tty and passes it to a serial line. It also takes input from the serial line and passes it to the virtual terminal subsystem. The latter will change in the future.

Initialization

This driver is initialized by calling

void serial_console_init(void)

Initialize the console frontend.

^ Back to top.

Allocating a Serial Console

A new instance of the serial console is allocated by calling

console_t *serial_console_alloc(void)

Allocate and return a new instance of a serial console.

Allocating a serial console in turn allocates a new console datastructure (console_t) and a new serial line data structure (serial_line_t). The provided console operations are stored in the console data structure. The serial line is stored as the private driver data of the console.

Returns:

A pointer to the newly allocated console.

^ Back to top.

Console Operations

This console implements the console operations (console_operations_t)

Open

Implements the operation console_operations_t.open:

static int __serial_con_open(console_t *con)

Open the serial console con.

^ Back to top.

Write

Implements the operation console_operations_t.write:

static void __serial_con_write(console_t *con, const char *string, unsigned int count)

Write count characters of a string to the console con.

Output printable characters but also handle (some) control characters, e.g., newline, backspace, form feed.

^ Back to top.

Helper Functions

This console uses helper functions to wrap some of the tasks handled by the write operation:

static void __serial_con_backspace(console_t *con)

Handle a backspace on the console con.

static void __serial_con_form_feed(console_t *con)

Perform a form feed on the console con.

static void __serial_con_newline(console_t *con)

Perform a carriage return, newline on the console con.

static void __serial_con_putc(console_t *con, const char *c)

Write a character c to the console con.

Serial Input

For serial input an input handler is registered to the input subsystem that processes EV_SERIAL events, re-maps some characters and passes them to the VT subsystem:

static void __serial_input_handler(input_event_type_t type, uint16_t code, uint32_t value)

Handle input via the serial port.

Receive serial input via the input subsystem. Re-map some of the input characters to match the expectations of tomOSii.

Pass the mapped input to the vt subsystem – similar to the keyboard input, though this gets remapped in the vt subsystem.

Note

This way, the active VT receives serial input, whenever a serial console is available. This has to be separated, once true serial TTYs are implemented.

Note

This will change in the future. For now, this is a sensible place to handle/forward the serial input.