Chinaunix首页 | 论坛 | 博客
  • 博客访问: 360481
  • 博文数量: 79
  • 博客积分: 1270
  • 博客等级: 中尉
  • 技术积分: 1370
  • 用 户 组: 普通用户
  • 注册时间: 2011-04-12 08:48
个人简介

freedom~~~~~~~~~~

文章分类

全部博文(79)

文章存档

2014年(10)

2013年(2)

2012年(13)

2011年(54)

分类: LINUX

2012-02-19 14:28:43

key.c

  1. #include <linux/kernel.h>
  2. #include <linux/fs.h>
  3. #include <linux/init.h>
  4. #include <linux/delay.h>
  5. #include <linux/poll.h>
  6. #include <linux/irq.h>
  7. #include <asm/irq.h>
  8. #include <linux/interrupt.h>
  9. #include <asm/uaccess.h>
  10. #include <mach/regs-gpio.h>
  11. #include <mach/hardware.h>
  12. #include <linux/platform_device.h>
  13. #include <linux/cdev.h>
  14. #include <linux/miscdevice.h>
  15. #include <linux/sched.h>
  16. #include <linux/gpio.h>
  17. #include <linux/mm.h>
  18. #include <linux/ioport.h>
  19. #include <linux/io.h>

  20. struct irq_type
  21. {
  22.     int irq;
  23.     char *name;
  24.     int number;
  25. };

  26.     unsigned int *addr;
  27. static struct irq_type key_irq[] =
  28. {
  29.     {IRQ_EINT8,"key0",0},
  30.     {IRQ_EINT11,"key1",1},
  31.     {IRQ_EINT13,"key2",2},
  32.     {IRQ_EINT14,"key3",3},
  33.     {IRQ_EINT15,"key4",4},
  34.     {IRQ_EINT19,"key5",5},
  35. };

  36. static irqreturn_t key_handler(int irq,void *dev_id)
  37. {
  38.     unsigned int data = ioread32(addr);
  39.     printk("<1> the read data is %d",data);
  40.     struct irq_type *nirq = (struct irq_type *)(dev_id);
  41.     switch(nirq->number)
  42.     {
  43.         case 0:
  44.             printk("<1> the key 0 ");
  45.             break;
  46.         case 1:
  47.             printk("<1> the key 1 ");
  48.             break;
  49.         case 2:
  50.             printk("<1> the key 2 ");
  51.             break;
  52.         case 3:
  53.             printk("<1> the key 3 ");
  54.             break;
  55.         case 4:
  56.             printk("<1> the key 4 ");
  57.             break;
  58.         case 5:
  59.             printk("<1> the key 5 ");
  60.             break;

  61.     }

  62.     return 0;
  63. }


  64. int my_key_init(void)
  65. {
  66.     addr = ioremap(0x56000064,4);
  67.     int i;
  68.     int ret;
  69.     for(i = 0;i < 6 ;i ++)
  70.     {
  71.         ret = request_irq(key_irq[i].irq,key_handler,IRQ_TYPE_EDGE_BOTH,key_irq[i].name,(void *)&(key_irq[i]));    
  72.         if(ret)
  73.             goto out;
  74.         printk("<1>request irq %d",i);
  75.     }
  76.     
  77.     return 0;
  78. out:
  79.     printk("<1>this is out of key_init!!!!!!!!!!");
  80.     //free_irq();
  81.     return -1;
  82. }

  83. void my_key_exit()
  84. {
  85.     printk("<1> exit of the module!!!!!!!!!!!!!!!!");
  86. }


  87. MODULE_AUTHOR("more&high");
  88. MODULE_LICENSE("Dual BSD/GPL");
  89. module_init(my_key_init);
  90. module_exit(my_key_exit);
Makefile
  1. obj-m:=key.o
  2. KERNELDIR:=/work/coding/linux-2.6.32.10
  3. PWD:=$(shell pwd)
  4. modules:
  5. $(MAKE) -C $(KERNELDIR) M=$(PWD) ARCH=arm CROSS_COMPILE=arm-linux-
  6. #$(MAKE) -C $(KERNELDIR) M=$(PWD) ARCH=i386 CROSS_COMPILE=
  7. clean:
  8. rm *.o *mod.o *.order *.mod.c *symvers -f

结果
  1. the read data is 47327
  2. the key 2
  3. the read data is 47359
  4. the key 2
  5. the read data is 47351
  6. the key 1
  7. the read data is 47359
  8. the key 1
  9. the read data is 47358
  10. the key 0
  11. the read data is 47359

阅读(1715) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~