[I2C] Not optimal driver for multi-threaded environment
Although the driver works correctly, in a context where there are different threads it can have troubles concerning execution time.
The working principle of the driver is like this:
- Perform a change in the peripheral; this will normally cause an event interrupt to be invoked;
- Make the thread manually wait and yield;
- When the interrupt is invoked to notify of an event or an error, it will wake up the thread that was performing the I2C transaction;
- When the thread is scheduled again, it will continue the transaction it was performing
The critical part is the the last point: the thread using the I2C driver would be waken up immediately only if it has a priority strictly grater than the thread running in that moment. If this condition doesn't hold, the thread is only in ready state and will wait for the scheduler to schedule it. This potentially could happen after some milliseconds (in miosix every 1ms the scheduler schedules another thread). So, in the case of the reading of a lot of bytes from the peripheral, this problem could scale, delaying all the sampling process of milliseconds.