Find the answer to your Linux question:
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 11
Hi, I wrote an interrupt program for keyboard. Full code is here int.c #include<linux/kernel.h> #include<linux/interrupt.h> #include<linux/module.h> #include<linux/sched.h> #include<linux/irq.h> irqreturn_t my_isr(int,void*,struct pt_regs*); static int count=0; unsigned long int x=10; static int ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Nov 2011
    Posts
    68

    Interrupt Driver


    Hi,
    I wrote an interrupt program for keyboard. Full code is here
    int.c

    #include<linux/kernel.h>
    #include<linux/interrupt.h>
    #include<linux/module.h>
    #include<linux/sched.h>
    #include<linux/irq.h>

    irqreturn_t my_isr(int,void*,struct pt_regs*);
    static int count=0;
    unsigned long int x=10;
    static int my_init(void)
    {
    printk("In init module\n");
    if(request_irq(1,my_isr,SA_SHIRQ,"myinterrupt",&x) )
    {
    printk("error");
    return -EBUSY;
    }
    return 0;
    }

    irqreturn_t my_isr(int irq,void *dev_id,struct pt_regs *regs)
    {
    printk("In isr %d\n",++count);
    //printk("Dev id %d\n",*(unsigned long*)dev_id);
    return 0;
    }

    static void my_clean(void)
    {
    printk("In cleanup module");
    free_irq(1,&x);
    }

    MODULE_LICENSE("GPL");
    module_init(my_init);
    module_exit(my_clean);
    ----------------------------------------------------------------------------------------------------------
    I would like to know how to check whether this code is working or not for keyboard interrupt??

    i compiled with gcc then i got following errors.

    error: ‘SA_SHIRQ’ undeclared
    warning: passing argument 2 of ‘request_irq’ from incompatible pointer type
    expected ‘irq_handler_t’ but argument is of type ‘enum irqreturn_t (*)(int, void *, struct pt_regs *)’

    which header file i should include??

    Thanks

  2. #2
    Just Joined!
    Join Date
    Jan 2012
    Posts
    6
    SA_SHIRQ is defined as IRQF_SHARED, which is defined in interrupt.h (you already have). So try using that instead.

  3. #3
    Just Joined!
    Join Date
    Nov 2011
    Posts
    68
    Thanks for your reply. Now its compiling and got in to interrupt handler. But i want to write interrupt driver for gpio pins. How will i do that? simply want to change the interrupt no in the above code??

  4. $spacer_open
    $spacer_close
  5. #4
    Just Joined!
    Join Date
    Jan 2012
    Posts
    6
    Initialization
    --------------
    Set your gpio pin value: 0 or 1
    Set your pin type, such as input or output
    Set your interrupt type, such as trigger on rising edge, low level, high level, ...
    If these are not set, they will take default values
    Initialize your interrupt using: request_irq()


    Opening Driver
    --------------
    When the driver is opened, enable your interrupt


    Interrupt Handler
    -----------------
    Disable interrupt
    Clear interrupt
    Perform the work (best done by scheduling it to be done after exiting interrupt handler)
    Enable interrupt


    Close Driver
    ------------
    Disable interrupt


    Exit
    ----
    Call free_irq()


    I hope this helps you. Since the calls to handle pin and interrupt settings are not linux calls, hopefully you have macros available from your chip manufacturer.

  6. #5
    Just Joined!
    Join Date
    Nov 2011
    Posts
    68
    Hi,
    I did as you said but the problem is i want to compile it with 2.6.10 linux kernel(DM355 leopard board) ..when i compiled the following errors are getting

    make -C /opt/mv_pro_4.0.1/montavista/pro/devkit/lsp/ti-davinci SUBDIRS=/shn/ex-int/int modules
    make[1]: Entering directory `/opt/mv_pro_4.0.1/montavista/pro/devkit/lsp/ti-davinci'
    CC [M] /shn/ex-int/int/inter.o

    error: `IRQT_TRIGGER_MASK' undeclared (first use in this function)
    error: `IRQF_SHARED' undeclared (first use in this function)

    I have included interrupt.h then also it showing like this. i think interrupt.h in 2.6.38-8- generic is diffferent bcz when i compiled with this kernel it was working. i copied the header file from 2.6.38-8-generic to 2.6.10 then it was showing errors in header file.. What should i do??

    Thanks

  7. #6
    Just Joined!
    Join Date
    Jan 2012
    Posts
    6
    I'm not sure, you are using a very old kernel that I am not familiar with. You might want to just define these yourself. Here they are from 2.6.27:

    #define IRQF_SHARED 0x00000080

    #define IRQF_TRIGGER_NONE 0x00000000
    #define IRQF_TRIGGER_RISING 0x00000001
    #define IRQF_TRIGGER_FALLING 0x00000002
    #define IRQF_TRIGGER_HIGH 0x00000004
    #define IRQF_TRIGGER_LOW 0x00000008
    #define IRQF_TRIGGER_MASK (IRQF_TRIGGER_HIGH | IRQF_TRIGGER_LOW | \
    IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING)

    But then I am not sure what behavior would occur.

    Sorry I can't be more help.

  8. #7
    Just Joined!
    Join Date
    Nov 2011
    Posts
    68
    Thanks a lot dilinux..Now while compiling no errors are showing but if we give insmod the following things are happening..

    # insmod inter.ko
    In init module
    enable_irq(51) unbalanced from bf01e0a0
    #
    Last edited by steffi; 01-18-2012 at 03:19 AM.

  9. #8
    Just Joined!
    Join Date
    Jan 2012
    Posts
    6
    I believe the "unbalanced" message is harmless. It just indicates that when you called disable_irq(), there were no devices already using the irq. The kernel code thinks there is an unbalanced match between enable_irq() and disable_irq().

  10. #9
    Just Joined!
    Join Date
    Nov 2011
    Posts
    68
    k..but why it is not going inside the interrupt handler and not printing the printk message?? How should i check it is going inside the handler or not?? I checked cat/proc/interrupts of leopard board then the interrupt which i have requested is registered there and i made the pin as high then also its not going inside the handler.
    Last edited by steffi; 01-19-2012 at 10:34 AM.

  11. #10
    Just Joined!
    Join Date
    Jan 2012
    Posts
    6
    You might want to re-post your full code. I do not see where you are registering your device. If it gets created, you should see it under: /sys/devices

Page 1 of 2 1 2 LastLast

Posting Permissions

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