How to read/write to an SPI bus without a while(1)-loop?


I use Legato 16.10.4 on my mangOH Green board with an WP8548 target.
I successfully managed to install spidev and spisvc (I’ve built my own kernel module spisvc.ko based on the yocto-install).
The spiService application is running and I can call le_spi_Open() and le_spi_Configure() from withing the routine COMPONENT_INIT.
But, how I can handle the different SPI read and write calls?

The Legato docs indicate that a COMPONENT_INIT should always return, so, I can’t use a while(1).
I’ve used the le_fdMonitor API to handle my different UART read and write calls, using the file descriptor that I received from my le_tty_Open() call, and that worked fine.
But, I think I can’t use le_fdMonitor for my SPI handling because SPI works with an le_spi_DeviceHandle instead of a file descriptor.

Any suggestion to handle my different SPI read and write calls?



Yes, COMPONENT_INIT should always return and we should not use any infinite loop(while(1)) inside that.
Coming to your use case “to handle my different SPI read and write calls” , I can suggest you to create two different threads in the COMPONENT_INIT to handle the read and write calls. See that i have attached the example application codethread_test.c (936 Bytes)
where i am creating 2 threads with while loop inside . But be careful using while(1) loop.

Muralidhara N.