如何在嵌入式Linux一个GPIO线检测中断? [英] How to detecting interrupt on a GPIO line in Embedded Linux?

查看:427
本文介绍了如何在嵌入式Linux一个GPIO线检测中断?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有是在 PANDABOARD OMAP4 上GPIO_39每10ms生成一个中断。我已经注册了的Linux驱动程序code本的处理程序,但因为没有被检测到中断的处理程序不被调用。

There is an interrupt being generated at every 10ms on GPIO_39 in the pandaboard OMAP4. I have registered a handler for this in Linux driver code, but the handler is not being called since the interrupt is not being detected.

我确信,在硬件级(通过探测GPIO引脚),它实际上正在产生中断。这只是该软件不能够检测到它。

I made sure at the hardware level (by probing the gpio pin) that the interrupt is actually being generated. It's only that the software is not being able to detect it.

我在我的司机code以下。

I've the following in my driver code.

#define GPIO_NO     39

  iowrite16(0x3, gpio_39_address + 2); /* Configured the pin 22 to be used as gpio. */

  ret = gpio_request(GPIO_NO, "Claiming GPIO");
  if(ret < 0)
  {
    printk(KERN_ALERT "%s: Claiming GPIO_%d failed\n", __func__, GPIO_NO);
    return -1;
  }
  else
  {
    printk(KERN_INFO "%s: Claiming GPIO_%d successful\n", __func__, GPIO_NO);
  }

  ret = gpio_direction_input(GPIO_NO);  
  if(ret < 0)
  {
    printk(KERN_INFO "%s: Setting GPIO direction to input failed\n", __func__);
    return -1;
  }
  else
  {
    printk(KERN_INFO "%s: Direction of GPIO_%d set to input\n", __func__, GPIO_NO);
  }

  GPIO_IRQ = gpio_to_irq(GPIO_NO);

  if(GPIO_IRQ < 0)
  {
    printk(KERN_INFO "%s: Mapping GPIO_%d to IRQ failed\n", __func__, GPIO_NO);
    return -1;
  }
  else
  {
    printk(KERN_INFO "%s: Mapping GPIO_%d to IRQ_%d successful\n", __func__, GPIO_NO, GPIO_IRQ);
  }

  if((request_irq(GPIO_IRQ, ten_ms_int, IRQF_TRIGGER_FALLING, DEVICE_NAME, NULL)))
  {
    printk(KERN_ALERT "%s: requeseting GPIO_IRQ %d failed\n", __func__, GPIO_IRQ);
    return -1;
  }
  else
  {
    printk(KERN_INFO "%s: requesting GPIO_IRQ %d successful\n", __func__, GPIO_IRQ);
  }

irqreturn_t ten_ms_int(int irq, void *dev_id)
{
  T_UINT32 l;
  /* Enable spi channel */
  l = ioread32(spi_base + SPI_CHCONF0);
  l |= SPI_CHCONF0_FORCE;
  iowrite32(l, (spi_base +  SPI_CHCONF0));

  l = ioread32(spi_base + SPI_CHCTRL0);
  l |= SPI_CHCTRL_EN;
  iowrite32(l, (spi_base + SPI_CHCTRL0));

  /* Enable dma channel 0 */
  l = ioread32(sdma_base + SDMA_CCR(CHANNEL0));
  l |= SDMA_CCR_ENABLE;
  iowrite32(l, sdma_base + SDMA_CCR(CHANNEL0));

  /* Enable dma channel 1 */
  l = ioread32(sdma_base + SDMA_CCR(CHANNEL1));
  l |= SDMA_CCR_ENABLE;
  iowrite32(l, sdma_base + SDMA_CCR(CHANNEL1));
  //printk(KERN_INFO "%s: 10ms interrupt detected %d\n", __func__, irq); /* I know that I've to remove this printk statement */
  return IRQ_HANDLED;
}

GPIO_39属于银行GPIO2和相应的中断数为32但 gpio_to_irq的返回值()是199.这是另一个值得关注的原因。

GPIO_39 belongs to the bank GPIO2 and the corresponding interrupt number is 32. But, the return value of gpio_to_irq() is 199. This is another cause of concern.

请让我知道什么是错在code,或者如果我错过了一些东西。

Please let me know if something is wrong in the code or if I have missed something.

推荐答案

请的GPIO管脚明确检测下降沿。

Make the GPIO pin explicitly to detect falling edge.

在GPIO模块级,有必要使GPIO的 FALLING_DETECT

At the gpio module level it is necessary to enable FALLING_DETECT of gpio.

这篇关于如何在嵌入式Linux一个GPIO线检测中断?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆