GPIO 更改狀態時如何更新 sysfs? (How is sysfs updated when a GPIO changes state?)


問題描述

GPIO 更改狀態時如何更新 sysfs? (How is sysfs updated when a GPIO changes state?)

假設 gpio X 可以作為輸入引腳在 sysfs 中導出,之後將在 /sys/class/gpio/ 中創建一個名為 gpioX 的目錄。gpioX/ 包含一些文件,例如表示 gpio X 的當前狀態(高或低)的“值”。

當施加到引腳 X 的信號改變其狀態時(在內核空間中)會發生什麼(例如從低到高)?

我的意思是,在轉換之前 gpioX/value 包含“低”,但之後它將包含“高”值。操作系統如何更新此文件?

我認為需要中斷機制。是否使用中斷機制來更新sysfs?


參考解法

方法 1:

How is this file updated by the OS? I think that an interrupt mechanism is required.

It does not require an interrupt mechanism unless it supports polling (man poll) or alternate asynchronous notifications. At least with most version, the /sys/class/gpio/ only does a read of the GPIO level when someone reads the file.

sysfs, debugfs, configfs, procfs, etc are virtual file systems. When you access the file, code within the Linux kernel runs to provide the value. sysfs only provides a file like interface; that doesn't mean it is backed with actual state. The state is the GPIO level which can be read at any time.

gpio_value_show() appears to be the current implementation. What you describe with interrupts is possible. It can be done through the sysfs_set_active_low() function or the sysfs file /sys/class/gpio/gpioN/edge. Writing to the file may return an error if the GPIO doesn't support interrupts. See gpio.txt for more (especially for your particular version of Linux).

(by b0b0bartless noise)

參考文件

  1. How is sysfs updated when a GPIO changes state? (CC BY‑SA 3.0/4.0)

#interrupt #linux-kernel #sysfs #gpio






相關問題

無法在 java 命令行程序中捕獲中斷 (Unable to catch interrupt in java command line program)

不連續的 BitBlt 捕獲 (discontinuous BitBlt capture)

GPIO 更改狀態時如何更新 sysfs? (How is sysfs updated when a GPIO changes state?)

Linux IRQ 處理程序中的固有競爭條件 (Inherent race condition in Linux IRQ handlers)

STM32 外部中斷僅在調試模式下響應 (STM32 external interrupt responds only in debug mode)

Java中的線程 (Threading in Java)

如何在被 Python 殺死之前運行最後一個函數? (How to run one last function before getting killed in Python?)

在 C++ 中處理中斷 (Handling Interrupt in C++)

應用程序中斷瘋狂 (Application interrupts like crazy)

SetPriorityClass(REALTIME_PRIORITY_CLASS) 實際上做了什麼? (What does SetPriorityClass(REALTIME_PRIORITY_CLASS) actually do?)

如何找出軟件掛起的原因?(qemu + zephyr + tfm 的問題) (How to find out the cause of hanging software? (problem with qemu + zephyr + tfm))

將參數傳遞給系統調用 (Passing arguments to system calls)







留言討論