SPI Master Driver with multiple tasks and one physical device; clarification on thread-safety.
Posted: Wed Sep 30, 2020 5:37 pm
Hello,
I am slightly confused by the SPI Master Driver documentation. It is warned that "if multiple tasks try to access the same SPI Device, the driver is not thread-safe." and the recommended workaround are mutexes or refactoring the application as to let the SPI peripheral be only accessed by one task at a time. The terminology section hints that "Device" is understood as a physical device (due signals and CS-lines being mentioned).
Does this apply strictly to physical devices on the SPI bus, or just to logical devices represented by their respective spi_device_handle_t -handles added on the bus with spi_bus_add_device()? I.e. could I have multiple tasks accessing a single physical SPI device in a thread safe manner, given that each task uses it's own logical spi_device_handle_t -handle (and acquiring/releasing the bus for the logical device as needed with spi_device_acquire/release_bus() )?
I am mainly interested in knowing this in order to avoid perhaps totally unnecessary semaphores or mutexes to protect bus access, in case the already existing spi_device_acquire_bus() and multiple handles representing the same physical device would already serve as a way for a task to prevent other tasks from meddling with the bus while it performs its function.
I am slightly confused by the SPI Master Driver documentation. It is warned that "if multiple tasks try to access the same SPI Device, the driver is not thread-safe." and the recommended workaround are mutexes or refactoring the application as to let the SPI peripheral be only accessed by one task at a time. The terminology section hints that "Device" is understood as a physical device (due signals and CS-lines being mentioned).
Does this apply strictly to physical devices on the SPI bus, or just to logical devices represented by their respective spi_device_handle_t -handles added on the bus with spi_bus_add_device()? I.e. could I have multiple tasks accessing a single physical SPI device in a thread safe manner, given that each task uses it's own logical spi_device_handle_t -handle (and acquiring/releasing the bus for the logical device as needed with spi_device_acquire/release_bus() )?
I am mainly interested in knowing this in order to avoid perhaps totally unnecessary semaphores or mutexes to protect bus access, in case the already existing spi_device_acquire_bus() and multiple handles representing the same physical device would already serve as a way for a task to prevent other tasks from meddling with the bus while it performs its function.