Netlink: 内核与用户空间传输数据的socket协议
https://en.wikipedia.org/wiki/Netlink
There is a similar question asked here:
Notify gpio interrupt to user space from a kernel module
Please check above question. However, i can provide my approach which i suggested there as well.
You can send a signal to user space thread from kernel API, which can help u run non-blocking:
send_sig(int sig, struct task_struct *p, int priv);
You need to be aware of pid of user thread in Kernel. You can over come this by writing pid of user process via /proc and then kernel reading the pid. With this arrangement, when there is an interrupt, kernel can send signal to user thread. In case your process restarts or gets killed, you will have to update the pid via proc. Just for status notification you can use this method; however if you like to transfer data along with status than Netlink or char driver mechanism is good way.
https://stackoverflow.com/questions/19257624/interrupt-handling-and-user-space-notification
You don't need fancy kernel to userspace communication. A userspace application has access to GPIOs using Sysfs. Read about it in Documentation/gpio.txt
.
First, export a GPIO pin like this (the actual number depends on your setup):
# echo 23 > /sys/class/gpio/export
This will export GPIO pin #23, and thus create /sys/class/gpio/gpio23
.
Set its direction:
# echo in > /sys/class/gpio/gpio23/direction
If the hardware GPIO controller supports interrupts generation, the driver should also support it and you will see /sys/class/gpio/gpio23/edge
. Write either rising
, falling
or both
to this file to indicate the signal edge(s) that will create a "userspace interrupt". Now, to get interrupted, use the poll(2)
system call on /sys/class/gpio/gpio23/value
. Then, when the poll
call unblocks, read the new value (/sys/class/gpio/gpio23/value
), which will be '0'
or '1'
(ASCII).
ASK:
支付宝扫一扫捐赠
微信公众号: 共鸣圈
欢迎讨论,邮件: 924948$qq.com 请把$改成@
QQ群:263132197
QQ: 924948
poll(2)
on a custom Sysfs entry for your driver. Otherwise, check out Netlink.