1、中断处理流程
中断专题:11. 基于ARM Cortex-A9中断详解 (qq.com)
2、中断注册函数
3、tq2440写的一个按键中断程序
有一个编译报错:
make -C /home/aston/040-linux-tq2440/linux-tq2440/ M=/home/aston/040-linux-tq2440/key_driver modules CROSS_COMPILE=arm-linux- ARCH=arm make[1]: Entering directory `/home/aston/040-linux-tq2440/linux-tq2440' CC [M] /home/aston/040-linux-tq2440/key_driver/key.o /home/aston/040-linux-tq2440/key_driver/key.c:58: error: expected identifier or '(' before 'do' /home/aston/040-linux-tq2440/key_driver/key.c:58: error: expected identifier or '(' before 'while' /home/aston/040-linux-tq2440/key_driver/key.c:65: warning: function declaration isn't a prototype /home/aston/040-linux-tq2440/key_driver/key.c: In function '__inittest': /home/aston/040-linux-tq2440/key_driver/key.c:70: error: 'key_init' undeclared (first use in this function) /home/aston/040-linux-tq2440/key_driver/key.c:70: error: (Each undeclared identifier is reported only once /home/aston/040-linux-tq2440/key_driver/key.c:70: error: for each function it appears in.) make[2]: *** [/home/aston/040-linux-tq2440/key_driver/key.o] Error 1 make[1]: *** [_module_/home/aston/040-linux-tq2440/key_driver] Error 2 make[1]: Leaving directory `/home/aston/040-linux-tq2440/linux-tq2440' make: *** [all] Error 2 root@ubuntu:/home/aston/040-linux-tq2440/key_driver#
对应的key.c
#include <linux/module.h> #include <linux/init.h> #include <linux/cdev.h> #include <linux/fs.h> #include <linux/io.h> #include <linux/interrupt.h> #include <linux/miscdevice.h> /**************引入中断框架**************/ #define GPFCON 0X56000050 irqreturn_t key_int(int irq, void *dev_id) { /*1、检查是否发生了中断 **2、清除中断 **3、打印按键值 */ printk("key down/n"); return 0; } void key_hw_init(void) { unsigned int *gpio_config; unsigned short data; gpio_config=ioremap(GPFCON,4); data=readw(gpio_config);//读了4节,读出来再写进去 data &= ~0b11; data |=0x10; writew(data,gpio_config);//将引脚配置成中断 } /************************************/ int key_open(struct inode *node, struct file *filp) { return 0; } struct file_operations key_fops={ .open=key_open, }; struct miscdevice key_miscdev = { .minor = 200, .name = "key", .fops = &key_fops, }; static int button_init() { misc_register(&key_miscdev);//按键下降沿触发中断 key_hw_init(); request_irq(IRQ_EINT0,key_int, IRQF_TRIGGER_FALLING,"key",0); } static void button_exit() { misc_deregister(&key_miscdev); //free_irq(IRQ_EINT0, 0); } MODULE_LICENSE("GPL"); module_init(button_init);//为甚改成key_init就报错 module_exit(button_exit);
只要把button_init button_exit都改成key_init编译就立马报错。为什么???
Makefile
obj-m:=key.o KDIR:= /home/aston/040-linux-tq2440/linux-tq2440/ all: make -C $(KDIR) M=$(PWD) modules CROSS_COMPILE=arm-linux- ARCH=arm clean: rm -rf *.ko *.o *.mod.o *.mod.c *.symvers *.bak *.order
原创文章,作者:254126420,如若转载,请注明出处:https://blog.ytso.com/270469.html