最近在学linux驱动开发,在做中断程序的时候不知道为什么就是进不了中断服务函数,下面贴出源码,希望各位大侠们给点帮助,不胜感激~
//s3c2440_key.c(底层驱动程序)
//#include
#include
#include
#include
#include
//#include
#include
#include
#include
#include
#include
#include
#include
#define DEVICE_NAME "s3c2440_key"
#define LED_MAJOR 240
static irqreturn_t key_isr(int irq, void *dev_id)
{
disable_irq(IRQ_EINT0); //Disable global interrupt
printk("IRQ_EINT0: Congratulation! you can go into the interrupt\n");
enable_irq(IRQ_EINT0); //Enable global interrupt
return IRQ_HANDLED;
}
static int request_irqs(void)
{
int ret;
set_irq_type(IRQ_EINT0,IRQ_TYPE_EDGE_FALLING);
ret=request_irq(IRQ_EINT0,key_isr,IRQF_SHARED,DEVICE_NAME,NULL);
if(ret)
{
printk("IRQ_EINT0: could not register interrupt\n");
return ret;
}
return 0;
}
static struct file_operations s3c2440_key_fops = {
.owner = THIS_MODULE,
};
static int __init s3c2440_key_init(void)
{
int ret;
ret = register_chrdev(LED_MAJOR, DEVICE_NAME, &s3c2440_key_fops);
if (ret < 0)
{
printk(DEVICE_NAME " can't register major number\n");
return ret;
}
s3c2410_gpio_cfgpin(S3C2410_GPF0,S3C2410_GPF0_EINT0);
printk(DEVICE_NAME " initialized\n");
return 0;
}
static void __exit s3c2440_key_exit(void)
{
//devfs_remove(DEVICE_NAME);
unregister_chrdev(LED_MAJOR, DEVICE_NAME);
}
module_init(s3c2440_key_init);
module_exit(s3c2440_key_exit);
//key_test.c(测试函数)
#include
#include
#include
#include "stdio.h"
#include "sys/types.h"
#include "sys/ioctl.h"
#include "stdlib.h"
#include "termios.h"
#include "sys/stat.h"
#include "fcntl.h"
#include "sys/time.h"
int main()
{
int fd;
fd = open("/dev/s3c2440_key",0);
if (fd < 0)
{
perror("open device key");
exit(1);
}
printf("key test show. press ctrl+c to exit \n");
while(1)
{
}
close(fd);
return 0;
}