i'm reading the sensor form stm32f3discovery in a single thread program.
Let's imagine to move the code for every sensor (accelereter: i2c, magnetometer: i2c, gyroscope: SPI) into 3 thread, as far as i know my code is thread save for SAME KIND on bus; BUT as SPI and I2C are sharing DMA, will i2cAcquireBus and spiAcquireBus block each others? or i have to implement my own lock mechanism? (I'm assuming i've to use blocking function in 3 thread, and i can't run 3 ainc request togeder)
ps. i add how i'm doing EVERY read. Is it ok? it've seen around code doin *Start BEFORE *AcquareBus, but as far as i undertand from APIs mineis correct order as *AcquireBus is what prevent race condition.
Also, how can i know if a SPI reading/bus is on error state?
The api say spiExchange does not have as prerequisite to do a spiSelect, is it right? if yes, it is ok if i do it anyway?
Code: Select all
i2cAcquireBus(&I2CD1);
i2cStart(&I2CD1, &i2cconfig);
status = i2cMasterTransmitTimeout(&I2CD1, sensor_address_7_bit, ®ister_to_read, 1, buffer_rx, size_of_buffer_rx, time_out_clock);
i2cStop(&I2CD1);
i2cReleaseBus(&I2CD1);
Code: Select all
spiAcquireBus(&SPID1);
spiStart(&SPID1, &spi1cfg);
spiSelect(&SPID1);
spiExchange(&SPID1, 8, txbuf, rxbuf);
spiUnselect(&SPID1);
spiStop(&SPID1);
spiReleaseBus(&SPID1);