I have two devices that communicate via serial port in a master/slave configuration. The master sends a status command to the slave every 100 milliseconds and the slave must process the command and respond within 1 millisecond. When all is working well, the slave responds in 0.04 milliseconds.
The serial receive interrupt gets characters from the UART and sends them to the processing task via a queue. The processing task has the highest priority in the system, priority 10.
The device contains other tasks that access hardware in the system so a number of mutex semaphores are used to ensure that only one task can use a particular piece hardware at a time.
Occasionally, the serial communications fail. Instead of responding immediately to the status command, the slave device waits for up to 1 millisecond to respond to the command. Debugging shows that the task receiving the serial characters is not entered immediately upon exit from the serial interrupt, but gets entered after the next time tick. Closer inspection shows that both the base priority and priority of the receiving task have been set to 0 (the same level as the Idle task) so FreeRTOS delays processing because all other tasks now have a higher priority. My code doesn’t have any calls to set the priority of any task.
I changed the mutex semaphores to binary and the problem appears to have gone away.
Has anyone else seen a problem like this? Am I using mutex semaphores wrong?