“tty” driver

Use the include file cyg/io/ttyio.h for this driver.

This driver is built on top of the simple serial driver and is typically used for a device that interfaces with humans such as a terminal. It provides some minimal formatting of data on output and allows for line-oriented editing on input.

Runtime configuration

typedef struct {
 cyg_uint32 tty_out_flags;
 cyg_uint32 tty_in_flags;
} cyg_tty_info_t;
	

The field ‘tty_out_flags’ is used to control what happens to data as it is send to the serial port. It contains a bitmap comprised of the bits as defined by the CYG_TTY_OUT_FLAGS_xxx values below.

#define CYG_TTY_OUT_FLAGS_CRLF 0x0001 // Map "\n" => "\n\r" on output
 	

If this bit is set in "tty_out_flags", any occurrence of the character "\n" will be replaced by the sequence "\n\r" before sending to the device.

The field ‘tty_in_flags’ is used to control how data is handles as it comes from the serial port. It contains a bitmap comprised of the bits as defined by the CYG_TTY_IN_FLAGS_xxx values below.

#define CYG_TTY_IN_FLAGS_CR 0x0001 // Map "\r" => "\n" on input
	

If this bit is set in ‘tty_in_flags’, the character ‘\r’ (“return” or “enter” on most keyboards) will be mapped to ‘\n’.

#define CYG_TTY_IN_FLAGS_CRLF 0x0002 // Map "\n\r" => "\n" on input
	

If this bit is set in ‘tty_in_flags’, the character sequence ‘\n\r’ (often sent by DOS/Windows based terminals) will be mapped to ‘\n’.

#define CYG_TTY_IN_FLAGS_BINARY 0x0004 // No input processing
	

If this bit is set in ‘tty_in_flags’, the input will not be manipulated in any way before being placed in the user’s buffer.

#define CYG_TTY_IN_FLAGS_ECHO 0x0008 // Echo characters as processed
	

If this bit is set in ‘tty_in_flags’, characters will be echoed back to the serial port as they are processed.

API details

 cyg_io_read(handle, buf, len)
	

This function is used to read data from the device. In the default case, data is read until an end-of-line character (‘\n’ or ‘\r’) is read. Additionally, the characters are echoed back to the [terminal] device. Minimal editing of the input is also supported.

	
 cyg_io_write(handle, buf, len)
	

This function is used to send data to the device. In the default case, the end-of-line character ‘\n’ is replaced by the sequence ‘\n\r’.

 cyg_io_get_config(handle, key, buf, len)
	

This function is used to get information about the channel’s configuration at runtime.

Key:

CYG_IO_GET_CONFIG_TTY_INFO

Buf type:

cyg_tty_info_t

Function:

This function retrieves the current state of the driver.

The key must be “CYG_IO_GET_CONFIG_TTY_INFO” which returns the control flags for the channel. The buffer ‘buf’ must be of type ‘cyg_tty_info_t’ and the length should match.

Serial driver keys (see above) may also be specified in which case the call is passed directly to the serial driver.

 cyg_io_set_config(handle, key, buf, len)
	

This function is used to modify the channel’s configuration at runtime.

Key:

CYG_IO_SET_CONFIG_TTY_INFO

Buf type:

cyg_tty_info_t

Function:

This function changes the current state of the driver.

The key must be CYG_IO_SET_CONFIG_TTY_INFO which returns the control flags for the channel. The buffer ‘buf’ must be of type cyg_tty_info_t and the length should match.

Serial driver keys (see above) may also be specified in which case the call is passed directly to the serial driver.