天嵌 ARM开发社区

 找回密码
 注册
查看: 2407|回复: 4

请教!在驱动程序中注册中断时,如何确定该中断的中断编号?

[复制链接]
vanbreaker 发表于 2012-2-15 21:30:21 | 显示全部楼层 |阅读模式
想写个按键的驱动,但是不知道怎么确定对应的外部中断的中断编号,看了下天嵌的按键驱动,不知道那个外部中断边和的宏定义在哪里……应该是在前面包含的头文件中,但是找了半天也找不到对应的头文件放在哪个地方,所以顺便问下有什么可以在VIM下直接查看头文件的方法么。。还是只能导入到SOURCE INSIGHT里面去再找。。。谢谢!
vcfwinkey 发表于 2012-2-15 22:16:27 | 显示全部楼层
注册中断可用request_irq这个函数,中断编号可以在arch/arm/mach-s3c2410/include/mach/irqs.h文件里找到
另外建议你还是把内核文件导入到source insight里吧,更加方便
danshi126 发表于 2012-2-15 22:56:26 | 显示全部楼层
贴个我写的wgbb 吧,,仅供参考:


#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/fs.h>
#include <linux/init.h>
#include <linux/delay.h>
#include <asm/irq.h>
#include <linux/interrupt.h>
#include <linux/irq.h>
#include <asm/uaccess.h>
#include <asm/arch/regs-gpio.h>
#include <asm/hardware.h>

struct pin_desc {
        char pin;
        char val;
};

struct pin_desc pin[4] = {
        {S3C2410_GPF0,0x01},
        {S3C2410_GPF1,0x02},
        {S3C2410_GPF2,0x03},
        {S3C2410_GPF4,0x04},
};

static unsigned int val = 0;
static unsigned int event = 0;
static DECLARE_WAIT_QUEUE_HEAD(key_wait);

static irqreturn_t key_int(int irq, void *dev_id)                                //中断服务函数
{
        unsigned int temp;
        struct pin_desc *pinval = NULL;
        pinval = (struct pin_desc *)dev_id;
        temp = s3c2410_gpio_getpin(pinval->pin);
        if(!temp)
        {
                val = pinval->val;
        }
        event = 1;
        wake_up_interruptible(&key_wait);
        return IRQ_RETVAL(IRQ_HANDLED);
}


static int key_open(struct inode *inode,struct file *file)
{
        request_irq(IRQ_EINT0,key_int,IRQT_BOTHEDGE,"key0",&pin[0]);                //注册中断
        request_irq(IRQ_EINT1,key_int,IRQT_BOTHEDGE,"key1",&pin[1]);
        request_irq(IRQ_EINT2,key_int,IRQT_BOTHEDGE,"key2",&pin[2]);
        request_irq(IRQ_EINT4,key_int,IRQT_BOTHEDGE,"key3",&pin[3]);
        return 0;
}


static  ssize_t key_read(struct file *file,char __user *userbuf,size_t count,loff_t *off)
{
        wait_event_interruptible(key_wait,event);                                       
        event = 0;       
        copy_to_user(userbuf,&val,sizeof(val));                                       
        return 0;
}


static int key_close(struct inode *inode,struct file *file)                //释放中断
{
        free_irq(IRQ_EINT0,&pin[0]);
        free_irq(IRQ_EINT1,&pin[1]);
        free_irq(IRQ_EINT2,&pin[2]);
        free_irq(IRQ_EINT4,&pin[3]);
        return 0;
}


static struct file_operations key_intterupt = {
        .owner = THIS_MODULE,
        .open  = key_open,
        .read  = key_read,
        .release = key_close,
};


static int key_init(void)
{
        register_chrdev(251,"key_int",&key_intterupt);
        return 0;
}
static void key_exit(void)
{
        unregister_chrdev(251,"key_int");
}

module_init(key_init);
module_exit(key_exit);
MODULE_LICENSE("GPL");
 楼主| vanbreaker 发表于 2012-2-16 12:25:36 | 显示全部楼层
vcfwinkey 发表于 2012-2-15 22:16
注册中断可用request_irq这个函数,中断编号可以在arch/arm/mach-s3c2410/include/mach/irqs.h文件里找到
...

谢谢,按你给的路径找到了!SOURCE INSIGHT还没用过,现在试试!
 楼主| vanbreaker 发表于 2012-2-16 12:26:57 | 显示全部楼层
danshi126 发表于 2012-2-15 22:56
贴个我写的wgbb 吧,,仅供参考:

暂时还不需要源代码!等我遇到了问题再来参考下你的吧,呵呵!谢过!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

关闭

i.MX8系列ARM cortex A53 M4 工控板上一条 /1 下一条

Archiver|手机版|小黑屋|天嵌 嵌入式开发社区 ( 粤ICP备11094220号 )

GMT+8, 2024-5-19 21:51 , Processed in 1.046875 second(s), 18 queries .

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

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