主题 : LED驱动问题 复制链接 | 浏览器收藏 | 打印
级别: 新手上路
UID: 62716
精华: 0
发帖: 4
金钱: 20 两
威望: 4 点
综合积分: 8 分
注册时间: 2012-02-06
最后登录: 2012-07-17
楼主  发表于: 2012-07-10 00:49

 LED驱动问题

我移植了2.6.36的内核,使用MINI2440_LED驱动,发现led例子程序不能控制led;
在驱动中的ioctl函数里面加了打印语句后发现,ioctl得到的arg参数不是应用程序调用ioctl时传入的参数,一直是一个固定的数,但是不知道从何而来,不知道有哪位能指点一下。

函数代码如下:
驱动程序中:
static int sbc2440_led_ioctl(
    struct inode *inode,
    struct file *file,
    unsigned int cmd,
    unsigned long arg)
{
    printk("control receive command %d, %8x\n", cmd, arg);
    switch(cmd) {
    case 0:
    case 1:
        if (arg > 4) {
            return -EINVAL;
        }
        s3c2410_gpio_setpin(led_table[arg], !cmd);
        return 0;
    default:
        return -EINVAL;
    }
}

应用程序的调用如下:
printf("ioctrl led_state = %d, led_no = %d, led_state address %8x\n", led_state, led_no, (unsigned long)(&led_no));
    if( led_no < 4)
        ioctl(fd_led, led_no, led_state);

应用程序运行后打印出来的信息如下:
ioctrl led_state = 1, led_no = 0, led_state address be838d30
control receive command 1, c019c1a4

级别: 新手上路
UID: 62716
精华: 0
发帖: 4
金钱: 20 两
威望: 4 点
综合积分: 8 分
注册时间: 2012-02-06
最后登录: 2012-07-17
1楼  发表于: 2012-07-10 01:18
找到原因了,2.6.36的ioctl函数参数中去掉了inode参数,因此实际上只有3个参数了;驱动里面还是四个参数,所以参数的传递出错了;

static int sbc2440_led_ioctl(
    struct inode *inode,
    struct file *file,
    unsigned int cmd,
    unsigned long arg)

修改成
static int sbc2440_led_ioctl(
    struct file *file,
    unsigned int cmd,
    unsigned long arg)

后就正常了