I am developing a system in which multiple tasks of different priorities communicate over an I2C bus. FreeRTOS is running on the master device. I would like to know if there is a standard for the management of the bus.
I currently have a single “I2C manager” task that application tasks send messages to on a queue. Without going into too many specifics, the application tasks receive data they are requesting over I2C by passing references to buffers with the messages. There is a bunch of flag-setting and memory-protecting that goes with this method. While this method has worked well so far I feel it is overly complex and also doesn’t allow messages with different priorities (this could be added along with more complexity).
The other option I know of is to just have global I2C read/write functions that are protected with semaphores and are called by tasks. This inherently gives a message the priority of its task but presents the possibility of priority inversion slowing everything down.
Are one of these methods generally preferred or am I missing something?