Notify gpio interrupt to user space from a kernel module [closed]

痴心易碎 提交于 2019-12-05 09:33:17

Take a look at the GPIO keyboard driver (drivers/input/keyboard/gpio_keys.c). It is a good starting point for your problem.

In the userspace you then listen (some blocking read for example, or just tail to test) to /dev/input/yourevent for events.

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)

But there is a limitation: u 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.

If i were you, i would have preferred to do this unless i dont want to transfer data from kernel to user. For data transfer requirement, i would have used Netlink or some other mechanism.

You can: (1) Send a signal to the user application, or (2) implement file_operations->poll method, use poll_wait and wait queue to wake user application when interrupt occur.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!