专题1-按键驱动程序设计-第2课-Linux中断处理
2022/6/27 5:20:17
本文主要是介绍专题1-按键驱动程序设计-第2课-Linux中断处理,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
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
这篇关于专题1-按键驱动程序设计-第2课-Linux中断处理的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-12-18git仓库有更新,jenkins 自动触发拉代码怎么配置的?-icode9专业技术文章分享
- 2024-12-18Jenkins webhook 方式怎么配置指定的分支?-icode9专业技术文章分享
- 2024-12-13Linux C++项目实战入门教程
- 2024-12-13Linux C++编程项目实战入门教程
- 2024-12-11Linux部署Scrapy教程:新手入门指南
- 2024-12-11怎么将在本地创建的 Maven 仓库迁移到 Linux 服务器上?-icode9专业技术文章分享
- 2024-12-10Linux常用命令
- 2024-12-06谁看谁服! Linux 创始人对于进程和线程的理解是…
- 2024-12-04操作系统教程:新手入门及初级技巧详解
- 2024-12-04操作系统入门:新手必学指南