不确定我是否应该将其发布在这里,但我必须问一下。
语境 :
软件必须处理 GPIO,有些是输出(需要时写入),有些是输入(某些需要时读取,其他最好是类似中断)。
该软件是一个多线程应用程序,在 SCHED_FIFO 调度策略中具有约 10-15 个线程。
假设我有一个名为 WGPIO 的模块,它是处理 GPIO 的包装器。(顺便说一句,这是由 Linux 团队开发的。WGPIO 仍然位于用户空间,但如果需要,他们可以开发驱动程序)
这是我们所说的设计的一些伪代码。
gpio_state state = ON;
// IO_O is output. Set to ON, don't care if it's active_high or active_low btw
WGPIO_WriteOutput(IO_O,state);
// IO_I is input, read when needed
WGPIO_ReadInput(IO_I,&state);
// register callback when rising edge occurs on IO named IO_IT
WGPIO_SetCallback(IO_IT,EDGE_RISING,my_callback);
// Unmask to enable further IT-like processing
WGPIO_UnmaskIRQ(IO_IT);
Run Code Online (Sandbox Code Playgroud)
我必须能够在 5 到 10 毫秒内处理一些 GPIO 变化。
多个 FD 上的一些用户空间轮询(WGPIO 将具有 SCHED_FIFO 线程)是否足以在我的应用程序中模拟“类似中断”的处理?这看起来是最简单的想法。
如果您需要更多详细信息,请随时询问。提前致谢。
Run Code Online (Sandbox Code Playgroud)"value" ... reads as either 0 (low) or 1 (high). If the GPIO is configured as an output, this value may be written; any nonzero value is treated as high. 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. "edge" ... reads as either "none", "rising", "falling", or "both". Write these strings to select the signal edge(s) that will make poll(2) on the "value" file return. This file exists only if the pin can be configured as an interrupt generating input pin.
/sys/class/gpio/gpioN/edge首选方法通常是使用和poll(2)for POLLPRI | POLLERR(重要的是,它不是POLLIN!)配置中断/sys/class/gpio/gpioN/value。如果您的流程是一些需要实时处理事件的“实时”流程,请考虑降低其友好度。
您甚至可以在 github 上找到一些使用 poll 的示例代码,例如。这个回购协议。
| 归档时间: |
|
| 查看次数: |
9782 次 |
| 最近记录: |