static ssize_t key_read(struct file *filp, char *buf, size_t count, loff_t *ppos) { unsigned int ret,temp; unsigned long flag; retry: if(g_key_dev->head != g_key_dev->tail) { local_irq_save(flag); //进入临界区,关闭中断 ret = g_key_dev->buf[g_key_dev->tail]; //读取尾部指针所指内容 g_key_dev->tail = INC_BUF_POINTOR(g_key_dev->tail, MAX_KEY_BUF); local_irq_restore(flag); //退出临界区 //printk(KERN_NOTICE "driver key_read,key no:%d\n",ret); temp = copy_to_user(buf, &ret, sizeof(unsigned int)); //printk(KERN_NOTICE "copy to user return %d\n", temp); return (sizeof(unsigned int)); } else { //printk(KERN_NOTICE "A\n"); if(filp->f_flags & O_NONBLOCK) { return -EAGAIN; } //printk("E:test %d\n",s3c2410_gpio_getpin(g_tkey_info[0].gpio_port)); interruptible_sleep_on(&(g_key_dev->wq)); //将该等待队列设置为可中断睡眠 goto retry; } // return 0; }
Linux驱动之按键中断(3)
内容版权声明:除非注明,否则皆为本站原创文章。