miscdevice:什么时候调查被调用?

时间:2015-03-01 17:46:38

标签: linux mouse linux-device-driver

我正在尝试编写一个简单的鼠标驱动程序(作为项目的一部分,将我的手机用作Linux的鼠标)。如果我理解正确: 1)我应该在模块的init()中使用misc_register() 2)file_operations'将定期调用poll()来确定鼠标是否应该移动? 3)open()和read()被调用以确定它应该如何移动?

我误解了什么吗?还有另一个步骤来确保调用poll()吗?

struct file_operations mousey_fops = {
    ...
    poll:   mousey_poll
};

static struct miscdevice mousey = {
    minor:MISC_DYNAMIC_MINOR, 
    ...
    fops:&mousey_fops
};

...

int mousey_init(void){
    // This gets executed, result == 0
    printk (KERN_ALERT "mousey_init called\n");
    result = misc_register(&mousey);
    ...
}

...

... mousey_poll(...){
    // this never gets executed
    printk (KERN_ALERT "mousey_poll called\n");
    return POLLIN | POLLRDNORM;
}

完整代码就在这里,以防万一: https://github.com/jeremydeanlakey/linuxdriverexperiment/blob/master/mousey.c

0 个答案:

没有答案