中断处理和用户空间通知 [英] Interrupt handling and user space notification

查看:253
本文介绍了中断处理和用户空间通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有几个分配给gpios的注册中断,以及在用户空间中的应用程序. 如何通知应用程序发生了中断以及发生了哪个中断?

I have several registered interrupts assigned to gpios, and application in user space. How to notify application about occurred interrupt and which interrupt there was?

可能fasync适用于此目标,但是我可以找到一些示例,该示例如何将信息从中断处理程序发送到用户空间应用程序.

Possibly fasync is applicable for this goal, but I can find examples how to send information from interrupt handler to user space application.

如果您能提供一些有用的示例,那将是很好的.

It will be good if you can present some useful examples.

谢谢.

推荐答案

您不需要花哨的内核即可进行用户空间通信.用户空间应用程序可以使用Sysfs访问GPIO.在 Documentation/gpio.txt 中了解其内容.

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.

首先,像这样导出GPIO引脚(实际数量取决于您的设置):

First, export a GPIO pin like this (the actual number depends on your setup):

# echo 23 > /sys/class/gpio/export

这将导出GPIO引脚#23,从而创建/sys/class/gpio/gpio23.

This will export GPIO pin #23, and thus create /sys/class/gpio/gpio23.

设置方向:

# echo in > /sys/class/gpio/gpio23/direction

如果硬件GPIO控制器支持中断生成,则驱动程序也应支持中断生成,您将看到/sys/class/gpio/gpio23/edge.将risingfallingboth写入此文件以指示将创建用户空间中断"的信号沿.现在,要中断操作,请在/sys/class/gpio/gpio23/value上使用 poll(2) 系统调用.然后,当poll调用解除阻塞时,读取新值(/sys/class/gpio/gpio23/value),它将是'0''1'(ASCII).

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).

这篇关于中断处理和用户空间通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆