关于beaglebone的IO中断
多人问我关于beaglebone的IO中断问题,现简略的记录如下:
这是用来测试的按键驱动,主要就是这个init函数了,注意其中调用的几个函数!
void key_init(void)
{
int result;
//omap_cfg_reg(GPIO_TO_PIN(1,22));
/* Allocating GPIOs and setting direction */
result = gpio_request(KEY0, "key");//usr1
if (result != 0)
printk("KEY0 request failed!\n");
result = gpio_direction_input(KEY0);
if (result != 0)
printk("KEY0 direction failed!\n");
irq_set_irq_type(OMAP_GPIO_IRQ(KEY0),IRQ_TYPE_EDGE_FALLING);//IRQ_TYPE_EDGE_RISING
enable_irq(gpio_to_irq(KEY0));
if(result = request_irq(OMAP_GPIO_IRQ(KEY0), &key_interrupt,0, "key_int", NULL))
{
printk(KERN_INFO"[FALLED: Cannot register Key Interrupt!]\n");
}
}
有个朋友告诉我前面的不需要多调用一次
irq_set_irq_type(OMAP_GPIO_IRQ(KEY0),IRQ_TYPE_EDGE_FALLING);来设置中断方式;
可以直接
request_irq(OMAP_GPIO_IRQ(KEY0),&key_interrupt,IRQF_TRIGGER_FALLING,"key_int",NULL);来设置中断方式!
|