New to RTOS, but perfectly comfortable with bare metal and serial protocols in general.
But nervous about accessing a variety of slave devices on a single i2c channel, which are polled at different rates (or even sporadically "on demand".) It makes sense to me to have different tasks for different parts of my system, even if they use a common i2c interface.
Anyway, I have converted MQX i2c driver into a thin layer of something a bit more sensible which maps to the bare metal for most slave devices.
_mqx_int i2cSendData (uint_8 address, uint_8 no_bytes,char *pData); //start/ack/address/ack/datawrite.../stop sequence
_mqx_int i2cReadData (uint_8 address, uint_8 no_bytes,char *pData); //start/ack/address/ack/dataread.../stop sequence
_mqx_int i2cReadDevice (uint_8 address, uint_8 Offs, uint_8 no_bytes,char *pData); //start/ack/address/datawrite/rp_start/address/dataread/stop sequence
These work perfectly in a single thread.
But these i2c transactions each use several MQX driver calls. So how should I keep the transactions safe between threads?
Should I open and close the master every time I need it?
Wrap the api in CriticalSection? (not nice).
Or is there some better way?