📄 button7.c
字号:
#include <linux/module.h>#include <linux/init.h>#include <linux/kernel.h>#include <linux/sched.h>#include <linux/timer.h>#include <linux/interrupt.h>#include <asm/irq.h>#include <asm/hardware.h>#include <asm/uaccess.h>#include <asm/arch/irqs.h>#include <asm/io.h>#include <asm/semaphore.h> #include <linux/major.h>#include <linux/vmalloc.h>#include <linux/fs.h>#define key7_MAJOR 138 #define NOKEY 0#define KEY7 '7'static struct semaphore key_sem;static char key = NOKEY;devfs_handle_t devfs_key7;static void key7_clearirq(void){ SRCPND &= (~0x00000020); INTPND = INTPND; EINTPEND &= (~0x00000080); }static void key7_irq_isr(int irq, void *dev_id, struct pt_regs *regs){ key7_clearirq(); key=KEY7; up(&key_sem);}static ssize_t key7_read(struct inode *inode, char *buf, unsigned long count){ down_interruptible(&key_sem); put_user(key,buf); key=NOKEY; return 1;}int key7_open(struct inode *inode, struct file *file){// key7_clearirq();// enable_irq(IRQ_EINT7); sema_init(&key_sem,0); return 0;}void key7_release(struct inode *inode, struct file *filp){// key7_cleanirq();// disable_irq(IRQ_EINT7); printk("release ok!\n"); return;}struct file_operations key7_fops = { read:key7_read, open:key7_open, release:key7_release,};static int __init key7_init(void){ static int rc; unsigned long gpfup; set_external_irq(IRQ_EINT7,EXT_FALLING_EDGE, GPIO_PULLUP_DIS); gpfup = ioremap(0x56000058,8); (*(volatile unsigned long *)gpfup) &= 0x7f; disable_irq(IRQ_EINT7); enable_irq(IRQ_EINT7); rc = request_irq(IRQ_EINT7, key7_irq_isr, SA_INTERRUPT, "key7", NULL); if (rc) { printk("<1>key7irq 1 irq not registered. Error: %d\n", rc); } printk("*********key7 init ok!***********\n"); /* Register myirq as character device */ devfs_key7 = devfs_register(NULL,"key7",DEVFS_FL_DEFAULT,key7_MAJOR, 0, S_IFCHR |S_IRUSR |S_IWUSR |S_IRGRP |S_IWGRP, &key7_fops, NULL); /* if ((rc = register_chrdev(keyirq_MAJOR, "key7", &key7_fops)) < 0) { printk("keyirq: can't get major %d\n",keyirq_MAJOR); return; } */ return 0;}static void __exit key7_exit(void){ disable_irq(IRQ_EINT7); free_irq(IRQ_EINT7, key7_irq_isr); devfs_unregister(devfs_key7);}module_init(key7_init);module_exit(key7_exit);//__initcall(key7_init);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -