当前位置: 技术问答>linux和unix
OK6410的按键外部中断方式,申请中断号出错
来源: 互联网 发布时间:2017-04-22
本文导语: #include #include #include #include #include #include #include #include #include #include #include //包含中断函数 #define TEST_MAJOR 250 #define TEST_NAME "irq_button" struct cdev test_dev; static dev_t ndev=MKDEV(TEST_MAJOR, 0); static...
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include //包含中断函数
#define TEST_MAJOR 250
#define TEST_NAME "irq_button"
struct cdev test_dev;
static dev_t ndev=MKDEV(TEST_MAJOR, 0);
static struct class *autodev;
static struct class_device * autodev_class;
static irqreturn_t irq_function(int irq, void *dev_id){
printk(KERN_INFO"the first irq is OKn");
return IRQ_RETVAL(IRQ_HANDLED);
}
static int test_open(struct inode *inode, struct file *filp)
{
int ret;
printk(KERN_INFO"into the openn");
enable_irq(IRQ_EINT(0));
ret = request_irq(IRQ_EINT(0), irq_function, IRQF_TRIGGER_FALLING, "key1_irq", NULL); if(0 != ret)
{
printk(KERN_INFO"request the irq is errn");
return -1;
}
printk(KERN_INFO"request the irq is welln");
return 0;
}
static ssize_t test_read(struct file *filp, char __user *buf, size_t count, loff_t *f_pos)
{
return 0;
}
static ssize_t test_write(struct file *filp, const char __user *buf, size_t count, loff_t *f_pos)
{
return 0;
}
static long test_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
{
return 0;
}
struct file_operations test_fops=
{
.owner = THIS_MODULE,
.open = test_open,
.read = test_read,
.write = test_write,
.unlocked_ioctl = test_ioctl,
};
static int test_init(void)
{
int ret;
cdev_init(&test_dev, &test_fops);
//alloc_chrdev_region(&ndev, 0, 1, TEST_NAME);
register_chrdev_region(ndev, 1, TEST_NAME);
ret = cdev_add(&test_dev, ndev, 1);
autodev = class_create(THIS_MODULE,TEST_NAME);
autodev_class = device_create(autodev,NULL,ndev,NULL,TEST_NAME);
printk(KERN_INFO"irq_button enter is OKn");
return 0;
}
static void test_exit(void)
{
printk(KERN_INFO"irq_button exitn");
device_destroy(autodev,ndev); //必须先删除设备
class_destroy(autodev); //后删除class类
unregister_chrdev_region(ndev, 1);
cdev_del(&test_dev);
}
module_init(test_init);
module_exit(test_exit);
MODULE_LICENSE("GPL");
小弟想实现的功能仅仅是按键下降沿触发响应函数,打印一句话,求大虾替小弟解难
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include //包含中断函数
#define TEST_MAJOR 250
#define TEST_NAME "irq_button"
struct cdev test_dev;
static dev_t ndev=MKDEV(TEST_MAJOR, 0);
static struct class *autodev;
static struct class_device * autodev_class;
static irqreturn_t irq_function(int irq, void *dev_id){
printk(KERN_INFO"the first irq is OKn");
return IRQ_RETVAL(IRQ_HANDLED);
}
static int test_open(struct inode *inode, struct file *filp)
{
int ret;
printk(KERN_INFO"into the openn");
enable_irq(IRQ_EINT(0));
ret = request_irq(IRQ_EINT(0), irq_function, IRQF_TRIGGER_FALLING, "key1_irq", NULL); if(0 != ret)
{
printk(KERN_INFO"request the irq is errn");
return -1;
}
printk(KERN_INFO"request the irq is welln");
return 0;
}
static ssize_t test_read(struct file *filp, char __user *buf, size_t count, loff_t *f_pos)
{
return 0;
}
static ssize_t test_write(struct file *filp, const char __user *buf, size_t count, loff_t *f_pos)
{
return 0;
}
static long test_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
{
return 0;
}
struct file_operations test_fops=
{
.owner = THIS_MODULE,
.open = test_open,
.read = test_read,
.write = test_write,
.unlocked_ioctl = test_ioctl,
};
static int test_init(void)
{
int ret;
cdev_init(&test_dev, &test_fops);
//alloc_chrdev_region(&ndev, 0, 1, TEST_NAME);
register_chrdev_region(ndev, 1, TEST_NAME);
ret = cdev_add(&test_dev, ndev, 1);
autodev = class_create(THIS_MODULE,TEST_NAME);
autodev_class = device_create(autodev,NULL,ndev,NULL,TEST_NAME);
printk(KERN_INFO"irq_button enter is OKn");
return 0;
}
static void test_exit(void)
{
printk(KERN_INFO"irq_button exitn");
device_destroy(autodev,ndev); //必须先删除设备
class_destroy(autodev); //后删除class类
unregister_chrdev_region(ndev, 1);
cdev_del(&test_dev);
}
module_init(test_init);
module_exit(test_exit);
MODULE_LICENSE("GPL");
小弟想实现的功能仅仅是按键下降沿触发响应函数,打印一句话,求大虾替小弟解难
|
先把你的cat /proc/interrupts 粘贴出来下,如果是模块的话,卸载模块,如果不是就重新裁剪内核选项。
|
返回 -16 即-EBUSY 说明是 中断号busy
|
在 request_irq 的开头加代码,打印irq以及 使用dump_stack();
定位到占用这个irq的驱动,删掉即可
if(irq==你的irq)
{
dump_stack();
}
定位到占用这个irq的驱动,删掉即可