搜索

1

主题

1

帖子

21

积分

新手上路

Rank: 1

积分
21
发表于 2014-12-8 12:36:32 13516 浏览 2 回复

Linux按键驱动程序的问题

我现在使用的是讯为itop-4412精英版,调试一个Linux按键驱动。Kernel使用的是3.0版本。我用内核模块加载的方式加载驱动,但是进入不了中断处理程序。file:///D:\Software\QQ2011\Users\550580649\Image\C2C\A32$}0IAE6M5TXK@%RT`5{L.png比如用Home键,这个对应GPX1_1,中断是XEINT9[img]file:///D:\Software\QQ2011\Users\550580649\Image\C2C\~B4B8[XZ9R]{Z8DZAQZJW(W.png[/img],驱动程序中.open函数里调用request_irq(IRQ_EINT9,  buttons_irq, IRQ_TYPE_EDGE_BOTH, "S1", NULL);触发是双边沿和下降沿触发都没法进入到buttons_irq中断处理函数。中断处理函数只是打印一句printk。我在应用层直接open这个驱动文件,然后执行while(1){sleep(1);}语句进入循环。以下是我的程序,请帮我查查哪里有错误?

驱动程序:
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/fs.h>
#include <linux/init.h>
#include <linux/delay.h>
#include <linux/irq.h>
#include <asm/uaccess.h>
#include <asm/irq.h>
#include <asm/io.h>
#include <mach/regs-gpio.h>
#include <mach/gpio.h>
#include <plat/gpio-cfg.h>
#include <plat/irqs.h>
#include <mach/irqs.h>
#include <mach/irqs-exynos4.h>
#include <linux/hardware.h>
#include <linux/device.h>


static struct class *buttondrv_class;
static struct device *buttondev;


static irqreturn_t buttons_irq(int irq, void *dev_id)
{
    printk("buttons_irq\n");
    return 0;
}

static int button_drv_open(struct inode *inode, struct file *file)
{
        request_irq(IRQ_EINT9,  buttons_irq, S5P_IRQ_TYPE_EDGE_FALLING, "K1",NULL);       
        return 0;
}

int button_drv_close(struct inode *inode, struct file *file)
{
        free_irq(IRQ_EINT9, NULL);
        return 0;
}


static struct file_operations button_drv_fops = {
    .owner   =  THIS_MODULE,  
    .open    =  button_drv_open,     
    .release  =  button_drv_close,          
};


int major;
static int button_drv_init(void)
{
        major = register_chrdev(0, "button_drv", &button_drv_fops);
        buttondrv_class = class_create(THIS_MODULE, "button_drv");
       
        buttondev = device_create(buttondrv_class, NULL, MKDEV(major, 0), NULL, "button", 0);

        return 0;
}

static void button_drv_exit(void)
{
        unregister_chrdev(major, "button_drv");
        device_destroy(buttondrv_class, MKDEV(major, 0));
        class_destroy(buttondrv_class);
        return 0;
}


module_init(button_drv_init);
module_exit(button_drv_exit);
MODULE_LICENSE("Dual BSD/GPL");


应用程序:
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>

int main(int argc, char **argv)
{
        int fd;
        fd = open("/dev/button", O_RDWR);
        if (fd < 0)
        {
                printf("can't open!\n");
        }

        while (1)
        {
                sleep(5);
        }
        return 0;
}


回复

使用道具 举报

151

主题

508

帖子

3567

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
3567
发表于 2014-12-16 19:07:02
确认一下request_irq()是不是注册成功呢,看下返回值。
回复 点赞

使用道具 举报

1

主题

357

帖子

1111

积分

QQ游客

积分
1111
发表于 2014-12-19 10:32:05
按键的驱动内核已经有了,在drivers/input/keyboard/gpio-keys.c,值需要自己在arch/arm/mach-exynos/mach-itop4412.c里面仿照我们的按键定义格式,实现自己的按键定义就可以了
回复 点赞

使用道具 举报

返回列表
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

登录或注册

官方客服

QQ:2551456065

官方QQ群

195631883

扫一扫关注迅为公众号

群号652692981

 
快速回复 返回顶部 返回列表