我正在研究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.