TTY Driver Framework
First, the concept of TTY analysis
In a Linux system, a terminal is a type of character device, which consists of many types, usually using a TTY for short-range end devices.
1.1 Serial terminal (/dev/ttys*)
The serial port terminal is the end device which uses the computer serial port connection. Linux considers each serial port to be a character device. The device name corresponding to these serial ports is/DEV/TTYSAC0;/DEV/TTYSAC1 ...
1.2 Virtual terminal (/dev/tty*)
When the user logs in, the virtual terminal is used. With Ctcl+alt+[f1-f6], we can switch to Tty1, Tty2, Tty3, and so on. Tty1–tty6 is called a virtual terminal, while Tty0 is an alias for the virtual terminal that is currently being used.
1.3 Console Terminal (/dev/console)
In a Linux system, the output device of a computer is often referred to as the console terminal, which refers to the device to which the PRINTK information is exported. /dev/console is a virtual device that needs to be mapped to a real TTY, such as a kernel boot parameter "CONSOLE=TTYSAC0" to map the console to a serial port 0
Second, TTY architecture analysis
The Linux TTY subsystem includes: TTY core, TTY line procedures, and TTY drivers. The TTY core is an abstraction of the entire TTY device, providing a unified interface to the user, the TTY line protocol is the format of the transmitted data, and the TTY driver is the hardware driver for the TTY device.
The following figure is parsed from a function call:
2.1 Kernel Code Analysis
Locate the following path to the kernel code:
There's a samsung.c file inside the linux-ok6410\drivers\tty\serial. Search the serial port send function S3c24xx_serial_start_tx and add back the printing function inside: dump_stack ();
1Staticvoid S3c24xx_serial_start_tx (struct Uart_port *Port2{3struct S3c24xx_uart_port *ourport =To_ourport (port);4Dump_stack ();//Back to the Moon5Staticint a =1;//Temp6if (Port->line = =3) {7//PRINTK ("485_start_tx\n");89If(a) {Ten S3c_gpio_cfgpin (S3C64XX_GPK (5), S3C_GPIO_SFN (1));A=0;12}Gpio_set_value (S3C64XX_GPK (5),1); 14 }15 if (! Tx_enabled (port) {16 if (Port->flags & Upf_cons_flow) 17 s3c24xx_serial_rx_disable (port); Span style= "color: #008080;" >18 19 Enable_irq (Ourport->TX_IRQ); 20 tx_enabled (port) = ;}22}
Compile the kernel code and place the image file in the board to download: the serial port can print out the callback Function procedure, but because my priority level problem cannot print out, therefore runs the command: DMESG
You can see the following code:
1//Dump_stack (); Call procedure2 [<c0035ca8>] (unwind_backtrace+0x0/0XFC)from [<c049c7c0>] (dump_stack+0x18/0x1c)3 [<c049c7c0>] (dump_stack+0x18/0x1cfrom [<c0237670>] (s3c24xx_serial_start_tx+0x14/0xb4)45 [<c0237670>] (s3c24xx_serial_start_tx+0x14/0XB4)from [<c023374c>] (uart_start+0x64/0x68)6 [<c023374c>] (uart_start+0x64/0x68from [<c0234cb4>] (uart_write+0xc0/0xe4)7 [<c0234cb4>] (uart_write+0xc0/0xe4from [<c021dd84>] (do_output_char+0x16c/0x1d8)8 [<c021dd84>] (do_output_char+0x16c/0X1D8)from [<c021de28>] (process_output+0x38/0x54)9 [<c021de28>] (process_output+0x38/0x54from [<c021e978>] (n_tty_write+0x204/0x444)ten [<c021e978>] (n_tty_write+0x204/0x444)from [<c021b808>] (tty_write+0x14c/0x244)[<c021b808>] (tty_write+0x14c/0x244)from [<c021b958>] (redirected_tty_write+0x58/0x68)[<c021b958>] (redirected_tty_write+0x58/0x68from [<c00e5ca4>] (vfs_write+0xbc/0x150) 13 14 // system call Interface procedure 15 [<c00e5ca4>] (vfs_write+0xbc/0x150) from [<c00e5e14>] (sys_write+0x44/0x74) 16 [<c00e5e14>] (sys_write+0x44/0x74) from [<c002fb40>] (ret_fast_syscall+0x0/ 0x30)
Through the analysis, we know it's consistent with the above process.
TTY Driver Framework