Chapter 2 Linux terminal device driver

Source: Internet
Author: User

This article is excerpted from (occasionally minor changes) "Linux device driver development details" (edited by Song Baohua; People's post and telecommunications press.
-- Living Park

 

Chapter 2 Linux terminal device driver

14.1 terminal Devices

In Linux, a terminal is a portable device. Including serial port terminals, pseudo terminals, and console terminals.

14.2 terminal device driver structure

The tty layer in the Linux Kernel includes the tty core, tty line, and tty driver.

Operation: allocate the tty driver alloc_tty_driver (); register the tty driver tty_register_driver (); cancel the tty driver tty_unregister_driver (); register the tty device tty_register_device (); cancel the tty device disconnect (); set tty driver operation tty_set_operations ().

14.3 terminal device driver initialization and release

14.3.1 module loading and uninstalling Functions

Tty-driven modules usually need to allocate and initialize the tty_driver struct and apply for necessary hardware resources. The opposite is true for uninstalling a function.

14.3.2 Open and Close Functions

The tty driver must be set to an open () member. Otherwise,-ENODEV will be returned to the user who calls open.

A device-related struct can be defined in the driver and assigned to the driver_data member of tty_struct in the open () function.

14.4 data sending and receiving

Because of the speed and tty hardware buffer capacity, not all characters required by the Write Program can be sent when calling the write function, therefore, the write function should return the number of bytes that can be sent to the hardware so that the user program can check whether all data is actually written.

14.5 tty line settings

14.5.1 line Setting user space Interface

To call the termios library function of a user space, you must reference the termios. h header file.

Operation: Set and obtain Operation Modes
Tcgetattr (), tcsetattr (); get and set the input/output baud rate
Cfgetospeed (), cfgetispeed (), cfsetospeed (), cfsetispeed (); line control tcdrain (), tcflush (), tcflow (), tcsedbreak ().

Most termios library functions are converted to ioctl () Calls on tty device nodes.

14.5.2 tty-driven set_termios Function

Most termios user space functions are converted to ioctl () calls to the driver node by the database, while most of the commands in tty ioctl are converted to the set_termios () function call. The set_termios () function needs to complete the actual hardware settings based on the user's settings for termios.

14.5.3 tty-driven tiocmget and tiocmset Functions

For TIOCMGET, TIOCMSET, TIOCMBIC, and TIOCMBIS
The call of Io control commands will be converted by the TTY core into calls to the TTY drive tiocmget () function and tiocmset () function.

14.5.4 tty-driven ioctl function

When you call IOCTL on a tty device node, the ioctl () function in tty_opetations is called by the TTY core.

14.6 UART Device Driver

The Linux kernel implements the universal tty driver layer for UART devices. The serial port core layer provides the following three structures.

1. uart_driver

Contains the driver name, device name, device number, and other information of the serial port device. Register/cancel uart_driver
Uart_register_driver (), uart_unregister_driver ().

2. uart_port

Describes the I/O port or I/O memory address, FIFO size, and port TYPE OF A UART port. Add/Remove a port uart_add_one_port () and uart_remove_one_port ().

3. uart_ops

Defines a series of UART operations, including sending, receiving, and line settings.

14.7 S3C2410
UART driver instance

14.7.1 serial port Hardware Description of S3C2410

There are three independent UART controllers in S3C2410, each of which can work in interrupt mode or DMA mode, that is to say, the UART Controller can generate an interrupt or DMA request when the CPU and UART Controller transmit data. Each UART integrated by S3C2410 has a 16-byte FIFO, and supports a maximum baud rate of 230.4 kbit/s.

14.7.2 Data Structure driven by S3C2410 serial port

Defines the struct s3c24xx_uart_port.

14.7.3 initialization and release of the S3C2410 serial driver

14.7.4 S3C2410 serial port data transmission and receiving

The membership function of startup () of the uart_ops struct driven by the S3C2410 serial port is s3c24xx_serial_startup () used to start the port, apply for sending and receiving of the port, and enable sending and receiving of the port. The opposite is s3c24xx_serial_shutdown.

Which of the following is the most closely related to data sending and receiving? s3c24xx_serial_rx_chars () and s3c24xx_serial_tx_chars ().

14.7.5 S3C2410 Serial Line settings

The set_termios () member function of the uart_ops struct driven by the S3C2410 serial port is used to change the parameter settings of the port.


 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.