Unable to access interrupt libraries for gpio in Linux for Colibri iMX6ULL WB

I have two problems.

I need to use gpio interrupts on the Colibir IMX6ULL WB. I can enable the interrupt on a GPIO pin using the standard “echo” instructions and the interrupt appears in the /proc/interrupts list and the interrupt counter advances as expected. I now need to process the interrupt in C. There should be a reference to “request_irq” in the follwoing library, but there isnt.

linux/sched.h

Also I need to synchronize data between the interrupt and the user program. I can do this with spinlocks or atomic variables. But there is no reference to the libraries

asm/atomic.h asm/spinlock.h.

Simply i want to count the interrupts, but when the user programs reads the count, I want to reset the counter , but dont want any interrupts to be lost. I could do this with “atomic_inc” from the interrupt and “atomic_dec_and_test” from the user program.

  1. how can I setup interrupts or access “request_irq()”
  2. how can I access atomic variables and spinlocks.

If these are not part of the standard image, how can I add them either via opkg or to my custom image.

Hi @lachlanp

Could you provide the version of the software of your module?
What is your application?

I am using the current console-tdx-image built directly from oe-core in the last few day. V2.8b3.

I currently have systems that use a linux processor for image processing and communications and a micro controller for analog and digital data acquisition. i am trying to see if I can get rid of the micro controller. This requires the Linux system to capture high speed events from flow-meters, vibration monitors and position sensors.
Low latency is required so I hope the interrupts and RT kernel will provide sufficient response time thereby reducing system complexity.

I’m not sure if it would be good enough for you or even be fast enough but have you tried accessing the file descriptor in question via sysfs? Maybe you can use C poll funtion in order to listen for changes, and hopefully with triggers you don’t have to reset the counter, just simply count the triggers removing the need for a spinlock (and saving some precious CPU cycles). However, I don’t know how accurate this could be in Linux (even with the RT kernel) rather than a hard real-time OS. I found this post that may contain good info regarding interruption handling in GPIO from user space.

Best regards,
Alvaro.

Hi

Concerning the interrupts, you cannot handle the interrupts directly in the user space, you will need a kernel driver. However nowadays there is the possibility to use UIO, which will help you to handle the interrupts from user-space.

I am trying to build an image with uio without success.

I am building console-idx-image from scratch with the latest rsync (31st Aug). I am using PREEMPT-RT and trying to install uio.

In build/local.conf I have:
PREFERRED_PROVIDER_virtual/kernel = “linux-toradex-rt”

I then run:

bitbake virtual/kernel -c menuconfig

I then set ‘*’ against 'Device Drivers->Userspace I/O driver->Userspace I/O plugin with generic irq handler.
This should make uio part of the default system. I save the .config

I look at:
./build/tmp-glibc/work/colibri_imx6ull-angstrom-linux-gnueabi/linux-toradex-rt/4.9-1.0.x+gitAUTOINC+07d40f6ffc-r0/build/.config
which has the follwing entries:
CONFIG_PREEMPT=y
CONFIG_PREEMPT_RT_BASE=y
CONFIG_HAVE_PREEMPT_LAZY=y
CONFIG_PREEMPT_LAZY=y
CONFIG_UIO=y
CONFIG_UIO_PDRV_GENIRQ=y

I then build the image and load on the colibri imx6ULL
I then run:

root@colibri-imx6ull:~# find / -name uio.h
/usr/include/sys/uio.h
/usr/include/bits/uio_lim.h
/usr/include/bits/uio-ext.h
/usr/include/linux/uio.h

I cannot find /usr/include/linux/uio_driver.h
It is in the build system:
./oe-core/build/tmp-glibc/work-shared/colibri-imx6ull/kernel-source/include/linux/uio_driver.h

I can locate the driver module as follows:
root@colibri-imx6ull:~# find / -name uio_pdrv*
/sys/bus/platform/drivers/uio_pdrv_genirq

But I cannot interface with it via a ‘c’ program with access to uio_driver.h because I njeed

struct uio_info;
extern void uio_unregister_device(struct uio_info *info);

How can I gget uio_driver.h to load so that I can access the uio_infor structure and register the interrupt?

Why do you think you need those files? Have you looked at the userspace program example in the link provided by jaski.tx ? here’s another example of UIO use:
https://yurovsky.github.io/2014/10/10/linux-uio-gpio-interrupt.html