Reputation: 117
I have two devices connected to the same SPI bus on a Raspberry Pi. Both devices use the same custom device driver, which exposes them as two separate miscellaneous devices in user space, supporting simple register write operations.
In my user-space program, I open both device files and perform IOCTL operations on them. However, I observe an issue:
When I perform 1000 writes to the first device, followed immediately by a few writes to the second device, the second device seems to receive values intended for the first device, despite using separate chip select (CS) pins. In the device driver, SPI writes are performed using spi_sync()
.
Questions:
Behavior of spi_sync()
: Based on the documentation, spi_sync()
is a synchronous function. Does this mean that the kernel thread performing the write only returns after the data has been fully transmitted on the SPI bus?
IOCTL behavior: When a user program calls IOCTL for an SPI write operation, does it block until the device driver completes the SPI transfer, or does it return immediately after copying user data into kernel space?
Concurrent writes from different processes: If another user-space program writes to the second device at the same time, will this result in interleaved SPI transfers on the bus? Will the SPI core handle chip select (CS) assertion correctly for each transfer to ensure data integrity?
Upvotes: 0
Views: 18