- 论坛徽章:
- 0
|
最近我利用网上的一个并口驱动程序,增加自己需要的内容,利用并口电压来产生中断,但是出现了问题,困扰了好久得不到解决,所以放上来求大家帮助。
代码奉上:- #include <linux/module.h>
- #include <linux/kernel.h>
- #include <linux/init.h>
- #include <linux/proc_fs.h>
- #include <linux/interrupt.h>
- #include <asm/io.h> /* outb */
- #define MODULE_VERSION "1.0"
- #define MODULE_NAME "interrupt_latency_x86"
- int interruptcount = 0;
- struct timeval tv1, tv2; /* do_gettimeofday fills these */
- #define SPPDATAPORT 0x378
- #define SPPSTATUSPORT (SPPDATAPORT + 1)
- #define SPPCONTROLPORT (SPPDATAPORT + 2)
- #define SSPINTERRUPTENABLE 0x10
- #define INTERRUPT 7
- static struct proc_dir_entry *interrupt_latency_file;
- /*
- * function interrupt_interrupt_latency
- * This function is the interrupt handler for interrupt 7. It sets the tv2
- * structure using do_gettimeofday. It then deasserts D7.
- */
- void interrupt_interrupt_latency(int irq, void *dev_id, struct pt_regs *regs)
- {
- do_gettimeofday(&tv2);
- outb(0x00,SPPDATAPORT); /* deassert the interrupt signal */
- interruptcount++;
- }
- /*
- * function proc_read_interrupt_latency
- * The kernel executes this function when a read operation occurs on
- * /proc/interrupt_latency. This function sets the tv1 structure. It asserts
- * D7 which should immediately cause interrupt 7 to occur. The handler
- * records tv2 and deasserts D7. This function returns the time differential
- * between tv2 and tv1.
- */
- static int proc_read_interrupt_latency(char *page, char **start, off_t off,int count, int *eof, void *data)
- {
- int len;
- do_gettimeofday(&tv1);
- outb(0x80,SPPDATAPORT); /* assert the interrupt signal */
- len = sprintf(page, "Start %9i.%06i\nFinish %9i.%06i\nLatency %17i\n\Count %19i\n",(int)tv1.tv_sec, (int)tv1.tv_usec,
- (int)tv2.tv_sec, (int)tv2.tv_usec, (int)(tv2.tv_usec - tv1.tv_usec),interruptcount);
- return len;
- }
- /*
- * function init_interrupt_latency
- * This function creates the /proc directory entry interrupt_latency. It
- * also configures the parallel port then requests interrupt 7 from Linux.
- */
- static int __init init_interrupt_latency(void)
- {
- int rv = 0;
- interrupt_latency_file = create_proc_entry("interrupt_latency", 0444, NULL);
- if(interrupt_latency_file == NULL){
- return -ENOMEM;
- }
- interrupt_latency_file->data = NULL;
- interrupt_latency_file->read_proc = &proc_read_interrupt_latency;
- interrupt_latency_file->write_proc = NULL;
-
- /* request interrupt from linux */
- rv = request_irq(INTERRUPT, interrupt_interrupt_latency, 0, "interrupt_latency",NULL);
- printk("rv value is %d",rv);
- if(rv){
- printk("Can't get interrupt %d\n", INTERRUPT);
- /* remove the proc entry on error */
- remove_proc_entry("interrupt_latency", NULL);
- printk("i am in rv remove\n");
- }
- /* enable parallel port interrupt generation */
- outb(SSPINTERRUPTENABLE,SPPCONTROLPORT);
- /* deassert the interrupt signal */
- outb(0x00,SPPDATAPORT);
- /* everything initialized */
- printk(KERN_INFO "%s %s initialized\n",MODULE_NAME, MODULE_VERSION);
- return 0;
- }
- /*
- * function cleanup_interrupt_latency
- * This function frees interrupt 7 then removes the /proc directory entry
- * interrupt_latency.
- */
- static void __exit cleanup_interrupt_latency(void)
- {
- /* disable parallel port interrupt reporting */
- outb(0x00,SPPCONTROLPORT);
- /* free the interrupt */
- free_irq(INTERRUPT,NULL);
- remove_proc_entry("interrupt_latency", NULL);
- printk(KERN_INFO "%s %s removed\n", MODULE_NAME, MODULE_VERSION);
- }
- module_init(init_interrupt_latency);
- module_exit(cleanup_interrupt_latency);
- MODULE_LICENSE("GPL");
- MODULE_AUTHOR("ZXL");
- MODULE_DESCRIPTION("interrupt_latency proc module");
- EXPORT_NO_SYMBOLS;
复制代码 Makefile:- obj-m := interrupt_latency_x86.o
- KDIR := /lib/modules/2.6.33.7.2-rt30/build
- PWD := $(shell pwd)
- all:
- make -C $(KDIR) M=$(PWD) modules
- clean:
- rm -f *.o *.ko *.mod.c Modules.symvers modules.order
复制代码 编译成功后,insmod,dmesg后均正常,但是cat /proc/interrupt_latency后,就只有tv1的开始时间,没有结束时间,也就是说中断没有被触发,但是代码中已经在pin口写高地址了,不知道什么问题,求助各位高人??
PS:我是在i386的系统上运行的. |
|