Multithread SPI

Hi All,

We are trying to get SPI working in multiple threads. We connect to the API in the thread with tryConnectService, which results in LE_OK.

But if we try to open the spi with le_spi_Open it returns LE_DUPLICATE (the file is already opened by the main thread) and if we try to write using the handle from the main thread the app crashes (in the log we get the error that the handle cannot be written to since it is not owned by the thread).

Is it possible to use the same spi port in multiple threads?

Best regards,

how about use the standard linux api to open() and ioctl()?

“Is it possible to use the same spi port in multiple threads?”

Short answer is yes, but user need to implement its own synchronization. This is nothing to do with Legato API, it is Unix (hence Linux) basic concept. A device like SPI would have a specific device file which user can open to read or write to by calling system call API. In return, kernel returns the file descriptor (which you call handler). In fact, this file descriptor can be shared across linux processes .

Having said so, why do you want to operate this SPI from multi thread? What are you trying to achieve? Why not create a thread to solely operate on this port. Then you may create other thread which send request to the other thread for any SPI operation. This way, you only have one thread solely responsible for SPI operation and you don’t have to worry about the synchronization anymore. Is this feasible for your project?

Thank you for your reply! I will try your solution to use a single thread for all SPI communication.

Best regards,