Re: facing a problem with irq handler,please help me

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



 i used free_irq in clean_up module. i think i must put the code again.

here's modified code:
-------------------------------------------------------------------------------------------------------


#include <linux/module.h>
#include <linux/fs.h>
#include <linux/ioport.h>
#include <linux/uaccess.h>
#include <linux/cdev.h>
#include <linux/errno.h>
#include <linux/interrupt.h>
#include <linux/sched.h>
#include <asm/io.h>
#include <asm/delay.h>

//#include<platforms/4xx/xparameters/xparameters.h>
#define HELLO_MAJOR 234
#define BASEPORT 0x3F8
#define PORT 0xa801
#define PARALLEL_PORT_INTERRUPT 7
#define CASE1 1
#define CASE2 2
//#define CMOS_BANK_INDEX_PORT 0x72
//#define NUM_CMOS_BANKS 1

static int debug_enable = 0;
static unsigned int counter = 0;
static char string [128];
//static int data;
//static int interruptcount = 0;

module_param(debug_enable, int, 0);
MODULE_PARM_DESC(debug_enable, "Enable module debug mode.");

/


struct file_operations hello_fops;

struct hello_dev {
  unsigned short current_pointer;
  unsigned int size;             
  int bank_number;               
  struct cdev cdev;              
  char name[10];             
  /* ... */                      
                                  
} *hello_devp;

static int hello_open(struct inode *inode, struct file *file)
{

   
    struct hello_dev *hello_open_ptr;
    printk("Ank$: Hello_open successful\n");
    hello_open_ptr=container_of(inode->i_cdev,struct hello_dev,cdev);
    file->private_data=hello_open_ptr;
    hello_open_ptr->size=0xff*8;
    hello_open_ptr->current_pointer=1;
    
   
    return 0;
}


static int hello_release(struct inode *inode, struct file *file)
{

    printk("Ank$: Hello_release successful\n");
    hello_devp->current_pointer=0;
    return 0;
}


static ssize_t hello_read(struct file *file, char *buf, size_t count,loff_t *ptr)
{

    printk("Ank$: hello_read Executing \n");
   
 
   copy_to_user(buf,hello_devp,1);
    if(*ptr==0)
    {
    *ptr=*ptr+1;
    return 1;
    }
    else
        return 0;

}


static ssize_t hello_write(struct file *file, const char *buf,size_t count, loff_t * ppos)
{

    int err;
    printk("Ank$: hello_write accepting bytes\n");
    err = copy_from_user(string,buf,count);
    if (err != 0)
        return -EFAULT;
    counter += count;
    printk("Ank$: count%d\n",count);
    return count;

   // return 0;
}



static irqreturn_t irq_handler (int irqn,void  *hello_devp1)
{
        //struct hello_dev *dev=hello_devp;
       hello_devp->bank_number=0614;
         // printk("the bank mis %d",hello_devp->bank_number);
       return IRQ_HANDLED;


}
int interrupt_g(int irqn,struct hello_dev *hello_devp)
{
int ret;

printk("Ank$: Generation of Interrupt starts\n");
    ret = request_irq(irqn,irq_handler,IRQF_SHARED,"hello",hello_devp);
    printk("Anks:RET:%d\n",ret);
    enable_irq(7);

    printk("Anks:RET:%d\n",ret);
    outb_p(0x10, BASEPORT + 2);    /*enable reporting*/

    printk("Ank$: ret=%d\n",ret);


   
    printk("Generating interrupt now on all output pins (intr/ACK = pin 10)\n");
        //generate interrupt
    outb_p(0, BASEPORT);
    outb_p(255, BASEPORT);
    outb_p(0, BASEPORT+2);
    printk("Interrupt generated. You should see the handler-message\n");   

return ret;

}

static int hello_ioctl(struct inode *inode, struct file *file,unsigned int cmd, unsigned long arg)
{

    return 0;
}

unsigned long start,len;
int status;

static int __init hello_init(void)
{
    int ret=-1,i=1,ret1=0;
   start = 0xa800;
//    start=0x001f;
    len   = 0x90;
   

    //printk("Hello Example Init - debug mode is %s\n", debug_enable ? "enabled" : "disabled");
    ret1 = register_chrdev(HELLO_MAJOR,"hello1",&hello_fops);
        if (ret1 < 0) {
            printk("Ank$: Error registering hello device\n");
            goto hello_fail1;
        }
    printk("Ank$: Hello module registered successfully!\n");


    /* Init processing here... */

    /* Memory allocation to the structure of the device driver*/

    hello_devp=kmalloc(sizeof(struct hello_dev ),GFP_KERNEL);
        if(!hello_devp)
    {
        printk("Bad memory Allocation Ank$\n");
    }
    else
    {
        printk("Ank$: Memory allocation successful\n");
    }

    /* Request for input output region */   

    status= check_region (start,len);
//    status=0;
    if(status==0)
    {
    printk("Ank$: Port Available\n");
    request_region(start,len,"hello");
    }
    else
    printk("Ank$: Port Unavailable%d\n",status);
    cdev_init(&(hello_devp->cdev),&hello_fops);
    hello_devp->cdev.owner=THIS_MODULE;
   
    /* connects major number to minor number*/
    if (cdev_add(&hello_devp->cdev, (HELLO_MAJOR + i), 1))
    {
      printk("Ank$: Bad cdev\n");
      return 1;
    }
    else
    {
     printk("Ank$:cdev successful\n");
    }

    i=interrupt_g(7,hello_devp);

   return 0;


hello_fail1:
    return ret;
}


static void __exit hello_exit(void)
{
//    free_irq(6,NULL);
//    disable_irq(7);
    printk("Hello Example Exit\n");
    if(status==0)
    {
    release_region(start,len);
    printk("Ank$: Released region successfuland the number is %d\n",hello_devp->bank_number);
    }
    unregister_chrdev(HELLO_MAJOR,"hello1");
    disable_irq(7);
    free_irq(7,hello_devp);
}




struct file_operations hello_fops = {
    owner:   THIS_MODULE,
    read:    hello_read,
    write:   hello_write,
    ioctl:   hello_ioctl,
    open:    hello_open,
    release: hello_release,
};


module_init(hello_init);
module_exit(hello_exit);

MODULE_LICENSE("GPL");
-------------------------------------------------------------------------------------------------------
On Fri, Oct 2, 2009 at 3:22 PM, Jason Nymble <jason.nymble@xxxxxxxxx> wrote:

On 02 Oct 2009, at 11:44 AM, Harinderjit Singh Sandhu wrote:

nw i got the follwing result when i inserted this module:
----------------------------------------------------------------------
Oct  2 14:46:47 AnkurAggarwal kernel: Ank$: Hello module registered successfully!
Oct  2 14:46:47 AnkurAggarwal kernel: Ank$: Memory allocation successful
Oct  2 14:46:47 AnkurAggarwal kernel: Ank$: Port Available
Oct  2 14:46:47 AnkurAggarwal kernel: Ank$:cdev successful
Oct  2 14:46:47 AnkurAggarwal kernel: Ank$: Generation of Interrupt starts
Oct  2 14:46:47 AnkurAggarwal kernel: Anks:ret:-16
Oct  2 14:46:47 AnkurAggarwal kernel: Press a key...
Oct  2 14:46:47 AnkurAggarwal kernel: >>> PARALLEL PORT INT HANDLED
Oct  2 14:46:47 AnkurAggarwal kernel: Ank$: ret=-16
Oct  2 14:46:47 AnkurAggarwal kernel: Generating interrupt now on all output pins (intr/ACK = pin 10)
Oct  2 14:46:47 AnkurAggarwal kernel: Interrupt generated. You should see the handler-message
-----------------------------------------------------------------------------------------------------------------------
can any body help me understand peculiar behavior.??? 
the return value for request_irq() is negative but still it shows the handler message. what could be the  problem ???

Did you remember free_irq in the module exit code? Its possible the second time you load the module it cannot acquire the interrupt because it was never released the first time (just guessing here). If thats the case, you must add free_irq and you may have to reboot.


--
To unsubscribe from this list: send an email with
"unsubscribe kernelnewbies" to ecartis@xxxxxxxxxxxx
Please read the FAQ at http://kernelnewbies.org/FAQ




--
---------------------
Harinderjit Singh

[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux