本文共 1475 字,大约阅读时间需要 4 分钟。
drivers/tty tty_write()->(ld->ops->write)//调用线路规程的ld->ops的write(n_tty_write) console_init()->tty_ldisc_begin()->tty_register_ldisc(N_TTY, &tty_ldisc_N_TTY) tty_ldiscs[disc] = new_ldisc;//设置ld->ops tty_open()->tty_init_dev()->initialize_tty_struct()->tty_ldisc_init(tty)-> get_ldops(disc)-> ldops = tty_ldiscs[disc]//open的时候获取ld->ops n_tty_write()->(tty->ops->write(tty, b, nr))调用tty->ops->write(uart_write) uart_register_driver()->tty_set_operations(normal, &uart_ops)//设置tty->ops-> write normal->driver_state = drv;//uart_driver保存在了tty_driver的driver_state uart_write()->uart_start()->__uart_start()->(port->ops->start_tx(port)) tty_open()->tty_init_dev()->initialize_tty_struct() tty->ops = driver->ops; tty_open()->(tty->ops->open(tty, filp))//由于上述,该open为uart_open uart_open()-> tty->driver_data = state;//uart_state保存在了tty_struct的driver_data driver和device匹配: uart_register_driver()->tty_register_driver()->list_add(&driver->tty_drivers, &tty_drivers)/ tty_open()-> tty = tty_open_current_tty(device, filp);//获取tty_struct tty_open()->tty_lookup_driver(device, filp, &noctty, &index)->get_tty_driver( device, index)//获取tty_driver static void __uart_start(struct tty_struct *tty) { struct uart_state *state = tty->driver_data;//上面设置了uart_state放到driver_data中 struct uart_port *port = state->uart_port; if (port->ops->wake_peer) port->ops->wake_peer(port); if (!uart_circ_empty(&state->xmit) && state->xmit.buf && !tty->stopped && !tty->hw_stopped) port->ops->start_tx(port); }转载地址:http://ydsqb.baihongyu.com/