【问题标题】:SPI_IOC_MESSAGE(N) on Raspberry Pi 3树莓派 3 上的 SPI_IOC_MESSAGE(N)
【发布时间】:2019-02-28 10:35:08
【问题描述】:

我正在研究一个 Raspberry Pi 3 上的项目,我看到了以下代码行:

ioctl(sSpiObj.spiFd, SPI_IOC_MESSAGE(1), &sSpiTransfer);        

我不知道SPI_IOC_MESSAGE(1) 是做什么的,我试图在互联网上找到它的解释,但我找不到。有没有人可以解释它的作用?

【问题讨论】:

    标签: linux raspberry-pi3 embedded-linux spi ioctl


    【解决方案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.
    

    【讨论】:

    • 你的回答很好,但我一个字都听不懂。 :( 什么是“请求类型”、“消息”、“取消选择”、“用户空间”……可以举一个简单的例子吗?有两个“消息”?
    猜你喜欢
    • 2017-11-12
    • 2019-06-16
    • 2018-02-07
    • 2017-03-30
    • 2023-01-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多