gpt4 book ai didi

linux - tty_flip_buffer_push() 将数据发回给自己

转载 作者:太空宇宙 更新时间:2023-11-04 09:38:18 26 4
gpt4 key购买 nike

我正在尝试在 LDD3 中运行 tiny_tty。当我使用“cat/dev/ttty0”从它读取时,没有输出并且命令被阻止。

检查跟踪,我注意到 tty_insert_flip_char() 和 tty_flip_buffer_push() 都被调用了。但是,数据不是由 tty 核心发送给用户的。相反,它被发送回 tiny_tty 驱动程序的 tiny_write() 回调函数。那里有什么问题?

内核版本为 2.6.32-61-generic。

这是痕迹

tiny_open()
tiny_timer() tty_flip_buffer_push()
tiny_write - 48

这是代码

static void tiny_timer(unsigned long timer_data)
{
struct tiny_serial *tiny = (struct tiny_serial *)timer_data;
struct tty_struct *tty_st_p;
struct tty_port *port;
int i;
char data[1] = {TINY_DATA_CHARACTER};
int data_size = 1;

if (!tiny)
return;

tty_st_p = tiny->tty_tse_p;

if (!tty_buffer_request_room(tty_st_p, 1))
tty_flip_buffer_push(tty_st_p);

tty_insert_flip_char(tty_st_p, 'H', TTY_NORMAL);

tty_flip_buffer_push(tty_st_p);
printk(KERN_INFO "tiny_timer() tty_flip_buffer_push()\n");

/* resubmit the timer again */
tiny->timer->expires = jiffies + DELAY_TIME;
add_timer(tiny->timer);
}

static int tiny_open(struct tty_struct *tty_st_p, struct file *file)
{
struct tiny_serial *tiny;
struct timer_list *timer;
int index;

/* initialize the pointer in case something fails */
tty_st_p->driver_data = NULL;

/* get the serial object associated with this tty pointer */
index = tty_st_p->index;
tiny = tiny_table[index];

if (tiny == NULL) {
/* first time accessing this device, let's create it */
tiny = kmalloc(sizeof(*tiny), GFP_KERNEL);
if (!tiny)
return -ENOMEM;

sema_init(&tiny->sem, 1);
tiny->open_count = 0;
tiny->timer = NULL;

tiny_table[index] = tiny;
}

down(&tiny->sem);

/* save our structure within the tty structure */
tty_st_p->driver_data = tiny;
tiny->tty_tse_p = tty_st_p;

++tiny->open_count;
if (tiny->open_count == 1) {
/* this is the first time this port is opened */
/* do any hardware initialization needed here */

/* create our timer and submit it */
if (!tiny->timer) {
timer = kmalloc(sizeof(*timer), GFP_KERNEL);
if (!timer) {
up(&tiny->sem);
return -ENOMEM;
}
tiny->timer = timer;
init_timer(tiny->timer);
}

tiny->timer->data = (unsigned long )tiny;
tiny->timer->expires = jiffies + DELAY_TIME;
tiny->timer->function = tiny_timer;
printk(KERN_INFO, "tiny_open()\n");
add_timer(tiny->timer);
}

up(&tiny->sem);

return 0;
}

static int tiny_write(struct tty_struct *tty_st_p,
const unsigned char *buffer, int count)
{
struct tiny_serial *tiny = tty_st_p->driver_data;
int i;
int retval = -EINVAL;

if (!tiny)
return -ENODEV;

down(&tiny->sem);

if (!tiny->open_count)
/* port was not opened */
goto exit;

/* fake sending the data out a hardware port by
* writing it to the kernel debug log.
*/
printk(KERN_DEBUG "%s - ", __FUNCTION__);
for (i = 0; i < count; ++i)
printk("%02x ", buffer[i]);
printk("\n");
retval = count;

exit:
up(&tiny->sem);
return retval;
}

最佳答案

您的终端设备启用了 ECHO。您可以使用 stty 命令关闭它(并控制其他标志):

stty -F /dev/ttty0 -echo

或使用适当的终端仿真程序,如 picocomminicom

关于linux - tty_flip_buffer_push() 将数据发回给自己,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24234117/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com