cancel
Showing results for 
Search instead for 
Did you mean: 

How can I dictate, without changing the task priorities, who gets the mutex/binary semaphore, when several tasks are waiting for it?

arnold_w
Senior

I'm implementing, using FreeRTOS, a simple communication protocol based on a 1-wire UART and a request-to-read pin. It has a master and a slave both of them can initiate a read from the other. If both the slave and master want to read at the same time, then the master will dictate who gets to do the read first. The master is, however, "fair" and will grant every other read to the slave so it never gets starved. I was thinking of protecting access to the UART and the request-to-read pin with a mutex/binary semaphore, but how can I then ensure that the master is fair? Let's assume 2 tasks (t1 and t2) inside the master want to read simultaneously and the slave (handled by a slaveReaderTask inside the master) also wants to read, then t1 should get the first read, then the slave and then t2. However, at the end of the t1 read there will be 2 tasks waiting for the mutex (t2 and slaveReaderTask) and t2 could possibly have the highest priority, but I want slaveReaderTask to get the mutex due to fairness. How can I solve this?

0 REPLIES 0