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

本文是小编为大家收集整理的关于如何在嵌入式Linux中的GPIO线上检测中断?的处理方法,想解了如何在嵌入式Linux中的GPIO线上检测中断?的问题怎么解决?如何在嵌入式Linux中的GPIO线上检测中断?问题的解决办法?那么可以参考本文帮助大家快速定位并解决问题。

问题描述

pandaboard omap4 中,在gpio_39上每10ms每10ms生成一个中断.我已经在Linux驱动程序代码中注册了此处理程序,但是由于未检测到中断,因此没有调用处理程序.

我确保在硬件级别(通过探测GPIO PIN)实际上正在生成中断.只是该软件无法检测到它.

我的驱动程序代码中有以下内容.

#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 PIN明确检测到跌落边缘.

在GPIO模块级别,必须启用 fallow_detect gpio.

本文地址:https://www.itbaoku.cn/post/359359.html