免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2393 | 回复: 4
打印 上一主题 下一主题

求助,这个驱动程序怎么不触发中断? [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2013-04-26 14:11 |只看该作者 |倒序浏览
最近我利用网上的一个并口驱动程序,增加自己需要的内容,利用并口电压来产生中断,但是出现了问题,困扰了好久得不到解决,所以放上来求大家帮助。
代码奉上:
  1. #include <linux/module.h>
  2. #include <linux/kernel.h>
  3. #include <linux/init.h>
  4. #include <linux/proc_fs.h>
  5. #include <linux/interrupt.h>

  6. #include <asm/io.h> /* outb */
  7. #define MODULE_VERSION "1.0"
  8. #define MODULE_NAME "interrupt_latency_x86"

  9. int interruptcount = 0;
  10. struct timeval tv1, tv2; /* do_gettimeofday fills these */

  11. #define SPPDATAPORT         0x378
  12. #define SPPSTATUSPORT       (SPPDATAPORT + 1)
  13. #define SPPCONTROLPORT      (SPPDATAPORT + 2)
  14. #define SSPINTERRUPTENABLE  0x10

  15. #define INTERRUPT 7

  16. static struct proc_dir_entry *interrupt_latency_file;

  17. /*
  18. * function interrupt_interrupt_latency
  19. * This function is the interrupt handler for interrupt 7. It sets the tv2
  20. * structure using do_gettimeofday. It then deasserts D7.
  21. */
  22. void interrupt_interrupt_latency(int irq, void *dev_id, struct pt_regs *regs)
  23. {
  24.   do_gettimeofday(&tv2);
  25.   outb(0x00,SPPDATAPORT); /* deassert the interrupt signal */
  26.   interruptcount++;
  27. }

  28. /*
  29. * function proc_read_interrupt_latency
  30. * The kernel executes this function when a read operation occurs on
  31. * /proc/interrupt_latency. This function sets the tv1 structure. It asserts
  32. * D7 which should immediately cause interrupt 7 to occur. The handler
  33. * records tv2 and deasserts D7. This function returns the time differential
  34. * between tv2 and tv1.
  35. */
  36. static int proc_read_interrupt_latency(char *page, char **start, off_t off,int count, int *eof, void *data)
  37. {
  38.   int len;
  39.   do_gettimeofday(&tv1);
  40.   outb(0x80,SPPDATAPORT); /* assert the interrupt signal */

  41.   len = sprintf(page, "Start %9i.%06i\nFinish  %9i.%06i\nLatency %17i\n\Count %19i\n",(int)tv1.tv_sec, (int)tv1.tv_usec,
  42.                 (int)tv2.tv_sec, (int)tv2.tv_usec, (int)(tv2.tv_usec - tv1.tv_usec),interruptcount);

  43.   return len;
  44. }

  45. /*
  46. * function init_interrupt_latency
  47. * This function creates the /proc directory entry interrupt_latency. It
  48. * also configures the parallel port then requests interrupt 7 from Linux.
  49. */
  50. static int __init init_interrupt_latency(void)
  51. {
  52.   int rv = 0;

  53.   interrupt_latency_file = create_proc_entry("interrupt_latency", 0444, NULL);
  54.   if(interrupt_latency_file == NULL){
  55.     return -ENOMEM;
  56.   }
  57.   interrupt_latency_file->data = NULL;
  58.   interrupt_latency_file->read_proc = &proc_read_interrupt_latency;
  59.   interrupt_latency_file->write_proc = NULL;


  60.   /* request interrupt from linux */
  61.   rv = request_irq(INTERRUPT, interrupt_interrupt_latency, 0, "interrupt_latency",NULL);
  62.   printk("rv value is %d",rv);
  63.   if(rv){
  64.     printk("Can't get interrupt %d\n", INTERRUPT);
  65.     /* remove the proc entry on error */
  66.     remove_proc_entry("interrupt_latency", NULL);
  67.     printk("i am in rv remove\n");
  68.   }

  69. /* enable parallel port interrupt generation */
  70.   outb(SSPINTERRUPTENABLE,SPPCONTROLPORT);

  71. /* deassert the interrupt signal */
  72.   outb(0x00,SPPDATAPORT);

  73. /* everything initialized */
  74.   printk(KERN_INFO "%s %s initialized\n",MODULE_NAME, MODULE_VERSION);
  75.   return 0;

  76. }


  77. /*
  78. * function cleanup_interrupt_latency
  79. * This function frees interrupt 7 then removes the /proc directory entry
  80. * interrupt_latency.
  81. */
  82. static void __exit cleanup_interrupt_latency(void)
  83. {
  84. /* disable parallel port interrupt reporting */
  85.   outb(0x00,SPPCONTROLPORT);

  86. /* free the interrupt */
  87.   free_irq(INTERRUPT,NULL);

  88.   remove_proc_entry("interrupt_latency", NULL);

  89.   printk(KERN_INFO "%s %s removed\n", MODULE_NAME, MODULE_VERSION);
  90. }

  91. module_init(init_interrupt_latency);
  92. module_exit(cleanup_interrupt_latency);

  93. MODULE_LICENSE("GPL");
  94. MODULE_AUTHOR("ZXL");
  95. MODULE_DESCRIPTION("interrupt_latency proc module");

  96. EXPORT_NO_SYMBOLS;
复制代码
Makefile:
  1. obj-m := interrupt_latency_x86.o

  2. KDIR := /lib/modules/2.6.33.7.2-rt30/build

  3. PWD := $(shell pwd)

  4. all:
  5.         make -C $(KDIR) M=$(PWD) modules

  6. clean:
  7.         rm -f *.o *.ko *.mod.c Modules.symvers modules.order
复制代码
编译成功后,insmod,dmesg后均正常,但是cat /proc/interrupt_latency后,就只有tv1的开始时间,没有结束时间,也就是说中断没有被触发,但是代码中已经在pin口写高地址了,不知道什么问题,求助各位高人??
PS:我是在i386的系统上运行的.

论坛徽章:
0
2 [报告]
发表于 2013-04-26 14:21 |只看该作者
求助高人啊!着急 所以在线等!

论坛徽章:
0
3 [报告]
发表于 2013-04-26 14:48 |只看该作者
如果有表笔,示波器什么的,自己可以中断口测试一下那个地方的电平,然后再判断程序可能在哪出现的原因

论坛徽章:
0
4 [报告]
发表于 2013-04-26 15:00 |只看该作者
回复 3# shuimu_1


    目前手头还没有这些工具,i386中IRQ7是打印机并口的中断,所以想用这个中端口和并口的特性来做这个测试驱动的。但是发现触发不了中断,调试好几天了。。。

论坛徽章:
0
5 [报告]
发表于 2014-05-23 07:53 |只看该作者
本帖最后由 isup 于 2014-05-23 07:53 编辑

问题解决了吗? 怎么解决的?
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP