注册 登录
电子工程世界-论坛 返回首页 EEWORLD首页 频道 EE大学堂 下载中心 Datasheet 专题
1067941083的个人空间 https://home.eeworld.com.cn/space-uid-184279.html [收藏] [复制] [分享] [RSS]
日志

2440中断按键检测

已有 1134 次阅读2011-4-9 00:34

最近在学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;
}
评论 (0 个评论)

facelist doodle 涂鸦板

您需要登录后才可以评论 登录 | 注册

热门文章