作者热门文章
- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我正在 Raspberry Pi 3 上做一个项目,我看到了这个代码行:
ioctl(sSpiObj.spiFd, SPI_IOC_MESSAGE(1), &sSpiTransfer);
我不知道SPI_IOC_MESSAGE(1)
是做什么的,我试图在网上找到它的解释,但我找不到。有没有人可以解释它的作用?
最佳答案
从这里查看 ioctl 声明:link你看到你必须在第二个参数中传递请求类型来告诉驱动程序你想要什么。您的第二个参数是 SPI_IOC_MESSAGE,它是在此处的 Linux 代码中定义的宏 link .它创建一个请求类型编号,其中包含您要发送的消息数量,然后将其传递给驱动程序,然后驱动程序解码请求类型和来自此的消息数量,并将第三个参数处理为要发送的消息,最后发送消息。
来自linux内核文档:
* SPI_IOC_MESSAGE gives userspace the equivalent of kernel spi_sync().
* Pass it an array of related transfers, they'll execute together.
* Each transfer may be half duplex (either direction) or full duplex.
*
* struct spi_ioc_transfer mesg[4];
* ...
* status = ioctl(fd, SPI_IOC_MESSAGE(4), mesg);
*
* So for example one transfer might send a nine bit command (right aligned
* in a 16-bit word), the next could read a block of 8-bit data before
* terminating that command by temporarily deselecting the chip; the next
* could send a different nine bit command (re-selecting the chip), and the
* last transfer might write some register values.
关于linux - 树莓派 3 上的 SPI_IOC_MESSAGE(N),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54923582/
我们正在从 ARM 嵌入式 Ubuntu 14.04 更新到 ARM 嵌入式 Ubuntu 16.04。在第一个平台上,我们可以毫无问题地访问使用 SPIDEV 的芯片。在 Ubuntu 平台上,我在
我无法让我正在处理的 SPI 程序正常运行,这似乎是 SPI_IOC_MESSAGE(N) 宏的一些问题。 这是不起作用的示例代码(ioctl 返回 EINVAL (22) ): std::vecto
我正在 Raspberry Pi 3 上做一个项目,我看到了这个代码行: ioctl(sSpiObj.spiFd, SPI_IOC_MESSAGE(1), &sSpiTransfer);
我是一名优秀的程序员,十分优秀!