GPIO hardware interrupt reading in user space application

117 views
Skip to first unread message

Narasimha Rao

unread,
Mar 10, 2021, 9:57:43 AM3/10/21
to inside...@googlegroups.com
Hi Team  and Anil,

I have configured it as a GPIO line to interrupt and insert the module into the kernel successfully.
Now functionality is also fine by using pushbutton.

I am trying to read interrupts using a POLL system call from a user space application.

In the /sys/class/gpio/gpio33/..
1. open the "edge" file path and pass the argument to POLL.
2. In "edge", there is no change like "none" is there.
3. How it will change the value like "rising" or "falling"
4. request_irq ( i have passed the FLAG - rising edge),

Can you please suggest any application to read the interrupt wherever triggered.
'

Regards,
Narasimha Rao

Anil Kumar Pugalia

unread,
Mar 12, 2021, 6:52:57 AM3/12/21
to inside...@googlegroups.com

You don't read interrupts in user space. Rather trigger something for user space when the interrupt arrives. So, for example, you may implement the poll system call which unblock on interrupt.

Regards
Anil
Passion: http://sysplay.in (Playing with Systems)
Narasimha Rao wrote on 10/03/21 8:27 pm:
--
You received this message because you are subscribed to the Google Groups "SysPlay's Inside Linux" group.
To unsubscribe from this group and stop receiving emails from it, send an email to inside_linux...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/inside_linux/CAAvht3V%2BtUvZsGm5MWMWVuCtAea-so_LP66HaOFeupybGnT0qw%40mail.gmail.com.

Narasimha Rao

unread,
Mar 12, 2021, 7:10:48 AM3/12/21
to inside...@googlegroups.com
Thanks Anil for the information.

Here , I am opening file path like /sys/class/gpio/gpioxx/value using open system call.
Passing this argument to poll() but the poll() is not blocking here. 
Ex: poll(fds, 1, -1);
I used lseek and read dummy also.
Fds.fd =fd,  fds.events =POLLPRI, fds.revents = 0;


Is there any other way to do this functionality to block and based on the triggered unblock.

If I checked fds.revents, the value is returned POLLPRI and POLLERR .

Why the poll function is behaves like this?

Regards, Narasimha 



Anil Kumar Pugalia

unread,
Mar 12, 2021, 8:10:25 AM3/12/21
to inside...@googlegroups.com

Did you implement the poll system call in your driver?

Regards
Anil
Passion: http://sysplay.in (Playing with Systems)
Narasimha Rao wrote on 12/03/21 5:40 pm:

Narasimha Rao

unread,
Mar 12, 2021, 8:53:09 AM3/12/21
to inside...@googlegroups.com
No, i didn't implement poll function in kernel module but I implemented handler now.

If I implement poll function then how could I manage that interrupt by using poll_wait ().


Regards,
Narasimha 

Er Krishna

unread,
Mar 12, 2021, 9:29:29 AM3/12/21
to inside...@googlegroups.com
Please look uio driver model example. You will get the answer. Please google it a bit.

Ty,
Krishna

Anil Kumar Pugalia

unread,
Mar 12, 2021, 9:34:25 AM3/12/21
to inside...@googlegroups.com

poll_wait need to be called in the poll function only.

Regards
Anil
Passion: http://sysplay.in (Playing with Systems)
Narasimha Rao wrote on 12/03/21 7:22 pm:

Anil Kumar Pugalia

unread,
Mar 12, 2021, 9:34:29 AM3/12/21
to inside...@googlegroups.com

poll_wait need to be called in the poll function only.

Regards

Anil
Passion: http://sysplay.in (Playing with Systems)
Narasimha Rao wrote on 12/03/21 7:22 pm:

Narasimha Rao

unread,
Mar 12, 2021, 9:54:18 AM3/12/21
to inside...@googlegroups.com
Thanks Krishna and anil,

@Anil,
How to connect both handler and poll function. Suppose If I have multiple gpio line interrupts then how?

Could you please share the code for the same. If you have predefined (poll()).



Regards,
Narasimha 

Anil Kumar Pugalia

unread,
Mar 12, 2021, 10:11:14 AM3/12/21
to inside...@googlegroups.com

Look into the code suggested by Krishna.

Regards
Anil
Passion: http://sysplay.in (Playing with Systems)
Narasimha Rao wrote on 12/03/21 8:24 pm:
Reply all
Reply to author
Forward
0 new messages