|
这是一个简单的并口驱动,要求能够处理并口的中断,并给出一个打印信息。个人感觉没有问题,但是一给中断就死机。大家帮忙看看吧。
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/sched.h>
#include <linux/ioport.h>
#include <asm/io.h>
#define TOGNUM 2000
#define BASE 0x378
MODULE_LICENSE("GPL");
//static int count;
static int major=240;
static int irq=7;
void int_handler(int irq,void* dev_id,struct pt_regs *regs)
{
printk("<1>Get Interrupt!\n");
}
struct file_operations par_fops={
};
int init_module(void)
{
int rc;
if((major=register_chrdev(major,"parport_test",&par_fops))<0)
{
printk("Cannot register character device\n");
return 0;
}
if(check_region(BASE,4))
{
printk("Port is been using\n");
unregister_chrdev(major,"parport_test");
}
request_region(BASE,4,"parport_test");
printk("<1>Line:%d\n",__LINE__);
rc=request_irq(irq,int_handler,SA_INTERRUPT,"parport_test",NULL);
printk("<1>Line:%d\n",__LINE__);
if(rc)
return rc;
return 0;
}
void cleanup_module(void)
{
release_region(BASE,4);
free_irq(irq,NULL);
unregister_chrdev(major,"parport_test");
}
|
|