Chinaunix

标题: 【关于linux驱动的问题】 [打印本页]

作者: chenmi0201    时间: 2009-02-27 11:48
标题: 【关于linux驱动的问题】
在学习点灯驱动程序中遇到一下一问题,请各位大虾给予解惑:
  驱动程序中的入口点:
....
static struct file_operations matrix4_leds_fops = {
    owner:    THIS_MODULE,
    ioctl:  leds_ioctl,
};
static int leds_ioctl(struct inode *inode, struct file   *file,   unsigned int cmd, unsigned long arg)
{......      //实现
    }
....

而在上层控制程序中有:
int main(int argc, char **argv)
{
    int on;
    int led_no;
    int fd;
    .....
    fd = open("/dev/leds", 0);
    ...
    ioctl(fd, on, led_no);      //疑惑????
    ....
}

请问上层测试程序ioctl(fd, on, led_no)和驱动中的ioctl函数是怎样调用的啊?他们的参数的个数以及参数的类型好像不一致?那么是怎样匹配的呢?
  请各位大虾给以解答!提前谢了.
作者: dreamice    时间: 2009-02-27 12:18
标题: 回复 #1 chenmi0201 的帖子
上层函数把参数传到驱动层,驱动根据上层传递的参数,来决定具体的操作。
你可以看一下LDD3的ioctl的驱动实例,就明白了
作者: Godbach    时间: 2009-02-27 14:15
对,看一下LDD3中讲解scull 字符设备的ioctl方法就明白了。




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2