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 ();
1 Static voidS3c24xx_serial_start_tx (structUart_port *Port)2 {3 structS3c24xx_uart_port *ourport =To_ourport (port);4 Dump_stack (); // back to the Moon5 Static intA =1;//Temp6 if(Port->line = =3) {7 //PRINTK ("485_start_tx\n");8 9 if(a) {TenS3c_gpio_cfgpin (S3C64XX_GPK (5), S3C_GPIO_SFN (1)); OneA=0; A } -Gpio_set_value (S3C64XX_GPK (5),1); - } the if(!tx_enabled (port)) { - if(Port->flags &Upf_cons_flow) - s3c24xx_serial_rx_disable (port); - +ENABLE_IRQ (ourport->TX_IRQ); -tx_enabled (port) =1; + } A}
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/0x1c) from[<c0237670>] (s3c24xx_serial_start_tx+0x14/0xb4)4 5[<c0237670>] (s3c24xx_serial_start_tx+0x14/0xb4) from[<c023374c>] (uart_start+0x64/0x68)6[<c023374c>] (uart_start+0x64/0x68) from[<c0234cb4>] (uart_write+0xc0/0xe4)7[<c0234cb4>] (uart_write+0xc0/0xe4) from[<c021dd84>] (do_output_char+0x16c/0x1d8)8[<c021dd84>] (do_output_char+0x16c/0x1d8) from[<c021de28>] (process_output+0x38/0x54)9[<c021de28>] (process_output+0x38/0x54) from[<c021e978>] (n_tty_write+0x204/0x444)Ten[<c021e978>] (n_tty_write+0x204/0x444) from[<c021b808>] (tty_write+0x14c/0x244) One[<c021b808>] (tty_write+0x14c/0x244) from[<c021b958>] (redirected_tty_write+0x58/0x68) A[<c021b958>] (redirected_tty_write+0x58/0x68) from[<c00e5ca4>] (vfs_write+0XBC/0x150) - - //system call Interface procedure the[<c00e5ca4>] (vfs_write+0XBC/0x150) from[<c00e5e14>] (sys_write+0x44/0x74) -[<c00e5e14>] (sys_write+0x44/0x74) from[<c002fb40>] (ret_fast_syscall+0x0/0x30)
Through the analysis, we know it's consistent with the above process.
18.tty Driver Framework