How to detecting interrupt on a GPIO line in Embedded Linux?

Sagar Jain :

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.

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.

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 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.

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

Sagar Jain :

Make the GPIO pin explicitly to detect falling edge.

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

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

how to know the Interrupt/GPIO number for a specific pin in linux

how to manage or resolve log of SPI interrupt in embedded linux

Detecting low memory situations in Embedded Linux

How is an Interrupt handled in Linux?

How to interrupt a GPIO RPi loop at any time with TKinter button

How to interrupt userspace application in Linux

How to wake up an Android Embedded Board from Suspend by using a GPIO

How do Linux GPIO numbers get their values?

IAR Embedded Workbench for ARM - How to define Interrupt Service Routine?

How to interrupt python interpreter embedded in C++ application

Linux Gpio V2 request line ioctl failing

How to interrupt GPIO button triggered long running process with another event on Raspberry Pi?

Use Python Asyncio to wait for GPIO interrupt

Interrupt in Microblaze on AXI_GPIO (XILINX FPGA)

GPIO extra interrupt in STM32

Windows 10 IoT GPIO interrupt frequency

Python how to read an anonymous linux file for a GPIO event

How can I find defination of GPIO in linux, especially for beaglebone black?

How to correctly share peripherals/GPIO between threads/cores using Rust embedded with embassy on RP2040

How to enable GPIO interrupt on STM32F4DISCOVERY user button from STM32CubeMX

How to pass to a new line after detecting a number in a string in php?

GPIO sample code for Linux

Detecting a horizontal line in an image

Detecting type of line breaks

Detecting Line feeds with Python

NAPI interrupt disabling and handling shared interrupt line

How to benchmark memory in an embedded linux device?

How can I identify an embedded Linux distribution?

How to locate and use fonts in Qt for Embedded Linux?