S3C6410按键驱动--中断方式

  1. #include <linux/module.h>  
  2. #include <linux/kernel.h>  
  3. #include <linux/fs.h>  
  4. #include <linux/init.h>  
  5. #include <linux/delay.h>  
  6. #include <asm/uaccess.h>  
  7. #include <asm/irq.h>  
  8. #include <asm/io.h>  
  9. #include <mach/regs-gpio.h>  
  10. #include <mach/hardware.h>  
  11. #include <linux/interrupt.h>  
  12. #include <linux/sched.h>  
  13. #include <linux/device.h>//新版内核  
  14.   
  15. #include <linux/gpio.h>  
  16. #include <plat/gpio-cfg.h>  
  17.   
  18.   
  19. static struct class *key_irq_class;  
  20. static struct class_device  *key_class_irq;  
  21. volatile unsigned long  *gpncon=NULL;  
  22. volatile unsigned long  *gpndat=NULL;  
  23.   
  24. static DECLARE_WAIT_QUEUE_HEAD(button_waitq);  
  25.   
  26. /* 中断事件标志, 中断服务程序将它置1,third_drv_read将它清0 */  
  27. static volatile int ev_press = 0;  
  28. struct key_desc{  
  29.     unsigned int pin;  
  30.     unsigned int key_val;  
  31.     };  
  32. /*键值:按下时,0x01,0x02,0x03,0x04,0x05,0x06*/  
  33. /*键值:松开时,0x81,0x82,0x83,0x84,0x85,0x86*/  
  34. static unsigned char key_num;  
  35. struct key_desc keys_desc[6]={  
  36.     {1,0x01},  
  37.     {2,0x02},  
  38.     {3,0x03},  
  39.     {4,0x04},  
  40.     {5,0x05},  
  41.     {6,0x06},  
  42. };  
  43.   
  44. static irqreturn_t key_irq(int irq, void *dev_id)  
  45. {  
  46.     struct key_desc *pin=(struct key_desc*)dev_id;  
  47.     unsigned int pinval;  
  48.     pinval=gpio_get_value(S3C64XX_GPN(pin->pin));  
  49.     if(pinval)  
  50.         {  
  51.             key_num=0x80|pin->key_val;  
  52.         }  
  53.     else  
  54.         {  
  55.             key_num=pin->key_val;  
  56.         }  
  57.     //printk("*********************");  
  58.     //printk("key_num= %x\n",key_num);  
  59.     //printk("*********************");  
  60.     //ev_press=1;/*表示中断发生了*/  
  61.     wake_up_interruptible(&button_waitq);/*唤醒休眠的进程*/  
  62.     return IRQ_HANDLED;  
  63. }  
  64.   
  65. static int key_drv_open(struct inode  * inode, struct file * file)  
  66. {  
  67.     request_irq(IRQ_EINT(1),key_irq,IRQF_TRIGGER_RISING|IRQF_TRIGGER_FALLING,"S1",&keys_desc[0]);  
  68.     request_irq(IRQ_EINT(2),key_irq,IRQF_TRIGGER_RISING|IRQF_TRIGGER_FALLING,"S2",&keys_desc[1]);  
  69.     request_irq(IRQ_EINT(3),key_irq,IRQF_TRIGGER_RISING|IRQF_TRIGGER_FALLING,"S3",&keys_desc[2]);  
  70.     request_irq(IRQ_EINT(4),key_irq,IRQF_TRIGGER_RISING|IRQF_TRIGGER_FALLING,"S4",&keys_desc[3]);  
  71.     request_irq(IRQ_EINT(5),key_irq,IRQF_TRIGGER_RISING|IRQF_TRIGGER_FALLING,"S5",&keys_desc[4]);  
  72.     request_irq(IRQ_EINT(6),key_irq,IRQF_TRIGGER_RISING|IRQF_TRIGGER_FALLING,"S6",&keys_desc[5]);  
  73.     return 0;  
  74. }  
  75. static ssize_t key_drv_write(struct inode * file, const char __user *buf, size_t count, loff_t *ppos)  
  76. {  
  77.   
  78.     return 0;  
  79. }  
  80. ssize_t key_drv_read (struct file *file, char __user *buf, size_t size, loff_t *ppos)  
  81. {  
  82.     //返回四个引脚的电平  
  83.     if(size != 1)  
  84.         return -EINVAL;  
  85.     /*如果没有按键动作发生就休眠*/  
  86.     wait_event_interruptible(button_waitq, ev_press);  
  87.     /*如果有按键动作,返回键值*/  
  88.     copy_to_user(buf,&key_num,1);  
  89.     ev_press=0;  
  90.     return 1;  
  91. }  
  92. int key_drv_release(struct inode * inode, struct file * file)  
  93. {  
  94.     free_irq(IRQ_EINT(1),&keys_desc[0]);  
  95.     free_irq(IRQ_EINT(2),&keys_desc[1]);  
  96.     free_irq(IRQ_EINT(3),&keys_desc[2]);  
  97.     free_irq(IRQ_EINT(4),&keys_desc[3]);  
  98.     free_irq(IRQ_EINT(5),&keys_desc[4]);  
  99.     free_irq(IRQ_EINT(6),&keys_desc[5]);  
  100.       
  101.     return 0;  
  102. }  
  103. static struct file_operations key_drv_openration ={  
  104.     .owner = THIS_MODULE,  
  105.     .open = key_drv_open,  
  106.     .write =key_drv_write,  
  107.     .read=key_drv_read,  
  108.     .release=key_drv_release,  
  109. };  
  110. int major;  
  111. static int key_drv_init(void)  
  112. {  
  113.     major=register_chrdev(0,"key_irq",&key_drv_openration);  
  114.       
  115.     key_irq_class = class_create(THIS_MODULE, "key_irq");  
  116.         //自动创建设备节点  
  117.     /* 新版的内核不能用class_device_create 要用device_create*/  
  118.     key_class_irq = device_create(key_irq_class, NULL, MKDEV(major, 0), NULL, "key"); /* /dev/xyz */  
  119.           
  120.     gpncon = (volatile unsigned long*)ioremap(0x7F008830,16);  
  121.     gpndat=gpncon+1;//指针的操作是按照指针指向的长度为单位?  
  122.                         /*本例中使用的是unsigned long类型刚好是4个字节*/  
  123.   
  124.     return 0;  
  125. }  
  126. static void key_drv_exit(void)  
  127. {  
  128.     unregister_chrdev(major,"key_irq");  
  129.     device_unregister(key_class_irq);  
  130.     class_destroy(key_irq_class);  
  131.   
  132.     iounmap(gpncon);  
  133.     return 0;  
  134. }  
  135.   
  136. module_init(key_drv_init);  
  137. module_exit(key_drv_exit);  
  138. MODULE_LICENSE("GPL");  

测试程序:

[cpp]  view plain copy
  1. #include<sys/types.h>  
  2. #include<sys/stat.h>  
  3. #include<fcntl.h>  
  4. #include<stdio.h>  
  5.   
  6. int main(int argc,char **argv)  
  7. {  
  8.     int fd;  
  9.     unsigned char key_val;  
  10.     int cnt;  
  11.     fd=open("/dev/key",O_RDWR);  
  12.     if(fd < 0)  
  13.         {  
  14.             printf("can not open!!!\n");  
  15.             return 0;  
  16.         }  
  17.     while(1)  
  18.         {  
  19.             read(fd,&key_val,1);  
  20.             printf("key_val = 0x%x\n", key_val);  
  21.         }  
  22.     return 0;  
  23. }  
测试结果:

[root@Pillar /driver/key/key_IRQ]#./main &
[root@Pillar /driver/key/key_IRQ]#*********************key_num= 81
*********************key_val = 0x81
*********************key_num= 82
*********************key_val = 0x82
*********************key_num= 3
******************************************key_num= 3
******************************************key_num= 83
*********************key_val = 0x3

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
S3C6410 是一款由三星公司推出的嵌入式微处理器,广泛应用于各种移动设备中。该处理器的驱动程序用于与操作系统进行通信,确保设备和操作系统能够正常协同工作。 在 S3C6410 处理器上安装 Windows 7 64 位操作系统后,需要相应的驱动程序来识别和管理处理器上的硬件设备。驱动程序通常是由设备制造商开发并提供的,以确保设备能够与操作系统相互匹配,实现最佳的兼容性和性能。 要获取适用于 S3C6410 处理器的 Windows 7 64 位驱动程序,您可以按照以下步骤操作: 1. 确定您的设备型号和规格。搜索三星官方网站或其他可靠的驱动下载网站,以查找适用于 S3C6410 处理器的 Windows 7 64 位驱动程序。 2. 在驱动程序下载页面中,选择与您的操作系统和设备型号相匹配的驱动程序版本。 3. 下载驱动程序并保存在计算机的任意位置。 4. 双击驱动程序安装文件,按照提示进行安装。在安装过程中可能需要提供管理员权限。 5. 安装完成后,重新启动计算机以使驱动程序生效。 请注意,驱动程序的安装可能因设备型号和供应商而有所不同。在任何情况下,请确保从官方渠道下载驱动程序以确保其正版和可信赖。 总结:安装 S3C6410 处理器的 Windows 7 64 位驱动程序是为了设备和操作系统之间的兼容性和协同工作。通过按照设备型号,在官方网站或其他可靠的驱动下载网站搜索并下载适用的驱动程序,然后按照提示进行安装和配置,即可实现设备和操作系统的正常工作。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值