Find the answer to your Linux question:
Results 1 to 5 of 5
Hi, I'm trying to create a kernel module (v2.6.35) using an interrupt. I played around with the code from the LKMPG, but no interrupt seems to be fired. Code: #include ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Jun 2012
    Posts
    2

    Kernel Module Interrupt


    Hi,

    I'm trying to create a kernel module (v2.6.35) using an interrupt. I played around with the code from the LKMPG, but no interrupt seems to be fired.
    Code:
    #include <linux/kernel.h>
    #include <linux/module.h>
    #include <linux/interrupt.h>
    
    MODULE_LICENSE("GPL");
    
    static irqreturn_t irq_handler(int irq, void *dev_id)
    {
        printk(KERN_INFO "[%d] interrupt\n", irq);
        
        return IRQ_HANDLED;
    }
    
    int init_module()
    {
        printk(KERN_INFO "init module: interrupt\n");
    
        return request_irq(13, irq_handler, 0, "SPI1 interrupt", NULL);
    }
    
    void cleanup_module()
    {
        free_irq(13, NULL);
    }
    Before wondering wheter or not irq with number 13 are even fired, I would like to know if the code shown above is any good. That is when an interrupt occurs the 'irq_handler' function is called.

    Thanks in advance!

  2. #2
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, in Chicago, or in a galaxy far, far away.
    Posts
    11,444
    So, how are you triggering the interrupt? In any case, I'm not sure that running a printk statement inside an interrupt handler is a good thing. Normally you would set some variable and then schedule some other module function with the kernel that will check the variable and do what is needed when called, such as I/O.

    Finally, what is the source of your learning about Linux kernel module and driver development?
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

  3. #3
    Just Joined!
    Join Date
    Jun 2012
    Posts
    2
    I'm not in control of the triggering. Someone else made some wiring between two boards. I got the code from the LKMPG 2.6 (can't share a link). I removed the part where scheduling was done which i guess was the right thing ;P.

    I'm now looking at some code from linux/drivers/spi. Looks like I can learn a lot there.

  4. #4
    Just Joined!
    Join Date
    Jun 2012
    Posts
    3
    check with /proc/interrupts after inserting your module - does your interrupt updated in the 13th line ? If not there is some problem with the code ?
    If it is present - then there is some problem with hardware it is not triggering interrupt

  5. #5
    Just Joined!
    Join Date
    Jun 2012
    Posts
    6

    insert kprobe

    you can also use kprobe whether the interrupt handler is called when the interrupt occurs.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •