linux-uart

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);
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章