【发布时间】:2023-04-01 18:20:01
【问题描述】:
我阅读了this excellent DIY article 关于编写 Linux 设备驱动程序的内容,但我仍然没有在此处的主要项目中看到“森林中的森林”。最终,最终用户软件(在用户空间中)需要与硬件进行通信(设备驱动程序正在驱动/包装/适应)。硬件由电力驱动,因此需要将软件命令转换为高/低信号(1 和 0),然后将其推送到电路和连接的硬件中。一个愚蠢的简单例子:
# Send a connected LED device a command to turn on at the software layer:
led.turnOn();
# In the device driver, somehow, translate this to 0x01 (1, or 00000001):
void turnOn() {
int signal = 1;
# Now, *somehow*, push this to the hardware with the following pinout (see below):
}
# Pinout
0 ----------------> /----------\
0 ----------------> | |
0 ----------------> | |
0 ----------------> | Hardware |
0 ----------------> | |
0 ----------------> | |
0 ----------------> | |
1 ----------------> \----------/
我没有看到的是:在设备驱动程序 C 代码中,我如何从底层硬件设备读取/写入字节/数据?
我能看到的唯一理论是,也许是因为 Linux 设备被视为用户空间的“文件”(dev/led),也许将数据(例如 0x01)写入dev/led 是我们向其发送命令的方式连接的设备;也许从设备读取数据就是我们从设备读取数据的方式。
我是朝着正确的方向前进,还是偏离了轨道?
【问题讨论】:
标签: linux linux-device-driver kernel-module device-driver