我试图在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;
}
答案 0 :(得分:2)
您的终端设备已启用ECHO。您可以使用stty
命令将其关闭(并控制其他标志):
stty -F /dev/ttty0 -echo
或使用适当的终端仿真程序,例如picocom
或minicom
。