dw8250_set_ldisc 函数
时间: 2024-01-10 11:01:32 浏览: 27
dw8250_set_ldisc 函数是 Linux 内核串行驱动程序中的一个函数,用于设置串行端口的行规程和字符规程。
函数原型:
void dw8250_set_ldisc(struct uart_port *port);
参数说明:
- port:指向串口设备结构体的指针。
函数功能:
dw8250_set_ldisc 函数通过调用 tty_set_ldisc 函数设置串口端口的行规程和字符规程。在设置行规程和字符规程之前,该函数会先判断当前串口是否已经打开。如果串口已经打开,那么会通过 tty_set_ldisc 函数重新设置行规程和字符规程。如果串口未打开,则不进行任何操作。
函数实现:
函数实现的具体细节可以参考 Linux 内核源代码中的 drivers/tty/serial/dw8250.c 文件。以下是该文件中 dw8250_set_ldisc 函数的代码实现:
void dw8250_set_ldisc(struct uart_port *port)
{
if (port->state != NULL && port->state->port.tty != NULL) {
tty_set_ldisc(port->state->port.tty, N_TTY);
}
}
相关问题
tty_ldisc_ref_wait函数
在 Linux 内核中,tty_ldisc_ref_wait 函数用于等待 tty line discipline 的引用计数变为零。
以下是 tty_ldisc_ref_wait 函数的原型:
```c
void tty_ldisc_ref_wait(struct tty_ldisc *ld)
```
该函数的参数是一个 tty_ldisc 结构体,表示要等待的 tty line discipline。
函数的实现如下:
```c
void tty_ldisc_ref_wait(struct tty_ldisc *ld)
{
wait_event(ld->w_wait, !atomic_read(&ld->refcount));
}
```
该函数使用 wait_event 宏等待 tty line discipline 的引用计数变为零。wait_event 宏会阻塞当前进程,直到第一个参数中的条件为真。
在本例中,第一个参数是 ld->w_wait,表示等待队列头。第二个参数是 !atomic_read(&ld->refcount),表示等待 tty line discipline 的引用计数变为零。
当 tty line discipline 的引用计数变为零时,其他进程将会调用 tty_ldisc_put 函数来释放该 tty line discipline 的引用,从而唤醒等待在 ld->w_wait 上的进程。
显示linux5.4源码中tcgetattr系统函数的源码
在 Linux 5.4 源码中,`tcgetattr()` 系统调用的源代码可以在 `drivers/tty/tty_io.c` 文件中找到。以下是该函数的源代码:
```
/**
* tcgetattr - get current terminal attributes
* @fd: file descriptor for the terminal
* @termiosp: pointer to output (current terminal attributes)
*
* Get the current terminal attributes in *termiosp.
*/
int tcgetattr(int fd, struct termios *termiosp)
{
struct tty_struct *tty;
int err = 0;
tty = get_current_tty();
if (!tty)
return -ENOTTY;
mutex_lock(&tty->termios_mutex);
if (tty->ldisc->ops->tiocmget &&
!try_module_get(tty->ldisc->owner)) {
struct serial_icounter_struct icount;
err = tty->ldisc->ops->tiocmget(tty, &icount);
if (!err) {
termios_lock();
*termiosp = tty->termios;
termios_unlock();
termiosp->c_ispeed = tty_get_baud_rate(tty);
termiosp->c_ospeed = termiosp->c_ispeed;
/* These values are not returned by the driver */
termiosp->c_cc[VINTR] = tty->termios.c_cc[VINTR];
termiosp->c_cc[VQUIT] = tty->termios.c_cc[VQUIT];
termiosp->c_cc[VMIN] = tty->termios.c_cc[VMIN];
termiosp->c_cc[VTIME] = tty->termios.c_cc[VTIME];
termiosp->c_cc[VEOF] = tty->termios.c_cc[VEOF];
termiosp->c_cc[VEOL] = tty->termios.c_cc[VEOL];
termiosp->c_cc[VEOL2] = tty->termios.c_cc[VEOL2];
termiosp->c_cc[VSWTC] = tty->termios.c_cc[VSWTC];
termiosp->c_cc[VSTART] = tty->termios.c_cc[VSTART];
termiosp->c_cc[VSTOP] = tty->termios.c_cc[VSTOP];
termiosp->c_cc[VSUSP] = tty->termios.c_cc[VSUSP];
if (tty->ops->get_icount)
memcpy(&termiosp->c_icount,
&tty->info->tty_icount,
sizeof(struct serial_icounter_struct));
else
memset(&termiosp->c_icount, 0,
sizeof(struct serial_icounter_struct));
}
module_put(tty->ldisc->owner);
} else {
termios_lock();
*termiosp = tty->termios;
termios_unlock();
termiosp->c_ispeed = tty_get_baud_rate(tty);
termiosp->c_ospeed = termiosp->c_ispeed;
}
mutex_unlock(&tty->termios_mutex);
return err;
}
```
该函数首先通过 `get_current_tty()` 函数获取当前进程的终端设备,然后获取该终端设备的属性,并将其存储在 `termiosp` 指针所指向的结构体中。函数返回值为 0 表示成功,否则表示失败。