#include <linux/gpio.h>
#include <linux/interrupt.h>
#define GPIO 7
int var;
static irqreturn_t irq_handler(int irq, void *dev_id)
{
var++;
printk("In the Interrupt handler, Count: %d\n", var);
return IRQ_HANDLED;
}
static int __init hello_init(void)
{
int errno, irq_line;
if((errno = gpio_direction_input(GPIO)) !=0)
{
printk(KERN_INFO "Can't set GPIO direction, error %i\n", errno);
gpio_free(GPIO);
return -EINVAL;
}
irq_line = gpio_to_irq(GPIO);
printk ("IRQ Line is %d \n",irq_line);
errno = request_irq( irq_line, (irq_handler_t)irq_handler, IRQF_TRIGGER_FALLING, "Interrupt123", NULL );
if(errno<0)
{
printk(KERN_INFO "Problem requesting IRQ, error %i\n", errno);
}
return 0;
}
static void __exit hello_exit(void)
{
int irq_line;
printk ("Unloading my module.\n");
irq_line = gpio_to_irq(GPIO);
free_irq(irq_line,NULL);
printk("Hello Example Exit\n");
return;
}
module_init(hello_init);
module_exit(hello_exit);
MODULE_AUTHOR("TheInventor");
MODULE_DESCRIPTION("Interrupt Module");
MODULE_LICENSE("GPL");What does dmesg look like?
I would have made the variable var look like this
“static int var;”
Also, I would have added a proc to display the current value of var.
Finally, I would have added something this to hello_init():
printk(“Entered hello_init().\n”);
None of these things are strictly necessary, but that’s how I do it. . .
Regards,
Dave Chapman
--
For more options, visit http://beagleboard.org/discuss
---
You received this message because you are subscribed to the Google Groups "BeagleBoard" group.
To unsubscribe from this group and stop receiving emails from it, send an email to beagleboard...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/beagleboard/830130c8-0310-4d3c-b0f8-d08caef6ccdf%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.