字符设备驱动之Buttons-中断
2011-09-14 16:14
295 查看
buttons.c
Makefile参考上个程序,测试程序不用写了,注册的中断服务程序有显示!主要把握框架,怎么写中断。
#include <linux/fs.h> #include <linux/module.h> #include <linux/errno.h> #include <linux/kernel.h> #include <linux/init.h> #include <linux/cdev.h> #include <linux/ioport.h> #include <linux/pci.h> #include <asm/uaccess.h> #include <asm/io.h> #include <asm/irq.h> #include <linux/interrupt.h> #include <asm/mach/irq.h> static int major = 0; static struct class *cls; /* gpecon 0x56000040 */ /* gpfcon 0x56000050 */ /* gpgcon 0x56000060 */ static volatile unsigned long *gpecon; static volatile unsigned long *gpedat; static volatile unsigned long *gpfcon; static volatile unsigned long *gpfdat; static volatile unsigned long *gpgcon; static volatile unsigned long *gpgdat; static irqreturn_t buttons_irq(int irq, void *dev_id)/*中断处理函数*/ { char *str = (char *)dev_id; printk("irq = %d, dev_id = %s\n", irq, dev_id); return IRQ_HANDLED; } int buttons_open(struct inode *inode, struct file *file) { return 0; } ssize_t buttons_read(struct file *inode, char __user *buf, size_t size, loff_t *offset) { return 0; } static const struct file_operations buttons_fops = { .owner = THIS_MODULE, .read = buttons_read, .open = buttons_open /* 设置引脚,申请资源 */ }; char *id = "K10"; int buttons_init(void) { major = register_chrdev(0, "buttons", &buttons_fops); /* sysfs */ cls = class_create(THIS_MODULE, "buttons_class"); class_device_create(cls, NULL, MKDEV(major, 0), NULL, "buttons"); gpecon = ioremap(0x56000040, 4096); gpedat = gpecon + 1; gpfcon = gpecon + 4; gpfdat = gpfcon + 1; gpgcon = gpecon + 8; gpgdat = gpgcon + 1; /* 注册中断 */ request_irq(IRQ_EINT0, buttons_irq, IRQF_SHARED | IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING, "K1_irq", id); /* 设置GPIO为中断引脚 * 设置触发方式 * 使能中断 */ /* 设置KSCAN0(GPE11)为输出引脚,输出0 */ *gpecon &= ~(0x3 << 22); *gpecon |= (1 << 22); *gpedat &= ~(1<<11); return 0; } void buttons_exit(void) { unregister_chrdev(major, "buttons"); class_device_destroy(cls, MKDEV(major, 0)); class_destroy(cls); iounmap(gpecon); free_irq(IRQ_EINT0, id);/*释放中断资源*/ } module_init(buttons_init); module_exit(buttons_exit); MODULE_LICENSE("GPL"); |
相关文章推荐
- 字符设备驱动之Buttons-中断上下部(tasklet)
- 字符设备驱动之Buttons-中断上下部(工作队列-workqueue)
- 07-S3C2440驱动学习(一)嵌入式linux字符设备驱动-查询+中断+引入poll机制的按键驱动程序
- 字符设备驱动之中断按键驱动
- 字符设备驱动之按键处理二(中断处理的按键驱动程序)
- 基于platform总线的中断(按键)字符设备驱动设计
- 高级字符设备驱动--中断下半部机制之workqueue(二)
- 高级字符设备驱动--中断下半部机制之tasklet(一)
- 嵌入式linux:字符设备驱动-----按键驱动(中断+poll机制)
- 高级字符设备驱动--中断下半部机制之workqueue(二)
- 初入android驱动开发之字符设备(四-中断)
- 字符设备驱动笔记——中断方式按键驱动之linux中断处理结构(五)
- 字符设备驱动之Buttons-轮询
- 字符设备驱动----中断程序
- 韦东山第12课-字符设备、中断方式查询驱动
- 字符设备驱动-----按键驱动(中断+poll机制)
- 字符设备驱动程序开发之基于中断的按键驱动加去抖动
- 字符设备驱动之Buttons-异步通知(fasync)
- 字符设备驱动之按键中断——FS2410
- 字符设备驱动笔记——中断方式按键驱动之linux异常处理结构(四)