Hi, I am using ‘Boot2Qt 6.2.1 Toradex Verdin-iMX8MP’ Bsp for dhalia carrier board. I am new to the project.
In my current project, we are polling the GPIO pins to read the value. Instead, I want to implement interrupts. Could you please let me know how to configure GPIO ISRs? The underlying operating system is embedded linux. I am not sure about the exact kernel version. Is there any examples on how to configure GPIO ISRs at the application level?
Attached is the gpio file from my application.
gpio.cpp (12.9 KB)
Here is the snippet of few GPIO configurations. As you can see, there is no interrupt service routine configuration.
sleepSwitch = new Gpio(POWERSWITCH_SLEEP);
buttonSwitch = new Gpio(POWERSWITCH_WAKEUP);
“If the pin can be configured as interrupt-generating interrupt
and if it has been configured to generate interrupts (see the
description of “edge”), you can poll(2) on that file and
poll(2) will return whenever the interrupt was triggered. If
you use poll(2), set the events POLLPRI and POLLERR. If you
use select(2), set the file descriptor in exceptfds. After
poll(2) returns, either lseek(2) to the beginning of the sysfs
file and read the new value or close the file and re-open it
to read the value.”
Thanks for the pointers. Just to double check.
In this case, Do I still have to poll (2) continuously to check if interrupt occurred? Or is it a callback function to let us know that the interrupt has occurred?
Poll is a blocking function. it will return when interrupt happened.poll(2): wait for some event on file descriptor - Linux man page
I see. Is there a way to configure this interrupt like a callback function instead of a blocking call?
Yes. you can move blocking call to a separate thread and signal or invoke a callback function when call returns.