c - GPIO 输出状态如何在进程退出时保持不变?

标签 c embedded-linux

从以前已知的 sysfs 接口(interface),任何人都可以设置合理配置的 GPIO 线路的输出,并且该输出将保留该值,直到 SoC 重置或有人更改线路值。 对于 GPIOlib,当消费者关闭 gpiochip 的句柄时,该值将重置为初始值。 假设,GPIO 线控制打开或关闭门的液压系统 - 当应用程序(消费者)因任何原因被终止时,门打开或关闭(可能关闭) - 无论默认线设置是什么。

我做了一些网络搜索并阅读了文档( https://www.kernel.org/doc/html/latest/driver-api/gpio/index.html ),并尝试了 https://git.kernel.org/pub/scm/libs/libgpiod/libgpiod.git/ 提供的示例.

最后 - 结果总是相同的:当进程退出时,该行被重置。 是否有机会保留特定的行值?

最佳答案

来自 gpioset.c 的来源 ( https://github.com/brgl/libgpiod/blob/master/tools/gpioset.c ):

printf("Note: the state of a GPIO line controlled over the character device reverts to default\n");
printf("when the last process referencing the file descriptor representing the device file exits.\n");
printf("This means that it's wrong to run gpioset, have it exit and expect the line to continue\n");
printf("being driven high or low. It may happen if given pin is floating but it must be interpreted\n");
printf("as undefined behavior.\n");

按设计工作...

对我来说,我错过了一个功能,即线路保持(锁定)我设置的状态。 与sysfs的导出机制相比,这绝对是一种退步。

关于c - GPIO 输出状态如何在进程退出时保持不变?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58749989/

相关文章:

c - 低级 IO read() 和 write()

linux - 如何通过/bin/sh解析HTTP头?

embedded-linux - 从内核空间禁用 LCD Controller

c++ - 在不使用Abs函数或if语句的情况下获取绝对值

c - 对于嵌入式设备上的非 ASCII 字符,mbrtowc 返回 -1,但在 linux 计算机上不返回

c++ - strcpy() 导致段错误?

c - ARM ASM : Bad Instruction end

linux - 具有 ICU 支持的 Qt 5.2.1 : all applications exit with code 1

embedded-linux - 从命令行通过/dev/mem 读取特定的内存地址

regex - U-Boot版本提取对比