I have been developing control software based on FreeRTOS. I have divided the
whole software into several tasks (the first executed every 1 ms, the second
executed every 20 ms and third executed every 100 ms). Each task call several
me defined functions. These functions have as one of their parameters some bit
variables (for example signal for blocking the PI controller or ramp calculation).
One task for example sets the bit for PI controller blocking and function called in
another task reads value of this bit and changes its behavior accordingly.
These bit variables are defined in a "bit array" which is shared by the tasks.
I have written several functions for manipulating with the bits in the bits array.
But I have problem with synchronizing the access to the bits array from the tasks.
I have tried to take semaphore (mutex) at the beginnig of each bit handling
function and then release the semaphore (mutex) at the end. But these tries were
unsuccessful. The bits in the bits array are randomly overwritten by the tasks
and all the timing of the software is corrupted. I don't know where the problem
is. I am also not sure if my "architecture" with the shared bits array is the
right one. Can anybody more experienced give me any advice or recommendation how
to solve this problem? Thanks in advance for any suggestions.
Have you considered using an event group?
Sounds like you could also make use of the somewhat new 'Notification' feature if it provides enough bits for your purposes.