taskYIELD() on polls

Hi, I inherited an old code for a peripheral driver that was meant to run on a non-RTOS based environment. It is basically a sequence of register writes interleaved with polling loops waiting for some status register bits to change state as consequence of each preceding register write. In order to take full advantage of FreeRTOS I’m converting the old code using the following rules : 1) For each polling loop on status bits for which related interrupts exits (meaning the hardware raises interrupt at status change) I will write register, suspend the task in order to pass control to other ready tasks and when the interrupt triggers I will resume the previously suspended task; 2) For each polling loop on bits for which related interrupts DO NOT exist (meaning they are not supported by hardware) I’m planning to replace ordinary (empty) polling loops with the following : while(status_bit == 0){ taskYIELD(); } ..e.g. if the status bit is not == 1 I pass control to the next ready task to avoid useless CPU time consumption (eventually returning to the loop after next context switch). Question : I just read that taksYIELD() only passes control to equal priority ready tasks… can’t find something more generic to temporarily pass control even to lower priority tasks which is allways better than sticking on polling for too long. Do you have any suggestion for that ? ..and in general, based on your RTOS experience is my approach at points 1) and 2) a sound way to take advantage of FreeRTOS? Thanks, Adalberto

taskYIELD() on polls

1) For each polling loop on status bits for which related interrupts exits (meaning the hardware raises interrupt at status change) I will write register, suspend the task in order to pass control to other ready tasks and when the interrupt triggers I will resume the previously suspended task;
You can use a semaphore for this. Make sure the semaphore is empty at the start, then

write_register();
if( xSemaphoreTake( Semaphore, MAX_TIME ) != pdPASS )
{
    /* Semaphore was not given by interrupt within the expected 
    time. Handle the error. */
}
else
{
    /* Semaphore was given, move to next step. */
}
If you expect the status change to happen very quickly then polling would be ok anyway.
2) For each polling loop on bits for which related interrupts /DO NOT exist/ (meaning they are not supported by hardware) I’m planning to replace ordinary (empty) polling loops with the following : while(status_bit == 0){ taskYIELD(); } ..e.g. if the status bit is not == 1 I pass control to the next ready task to avoid useless CPU time consumption (eventually returning to the loop after next context switch).
As you come on to mention, this will allow tasks of equal priority to run. If this is done in an idle priority task then all other tasks will be able to run in between yields.
/Question/ : I just read that taksYIELD() only passes control to equal priority ready tasks… can’t find something more generic to temporarily pass control even to lower priority tasks which is allways better than sticking on polling for too long. Do you have any suggestion for that ?
You can do something like

while( status_bit == 0 ) vTaskDelay( x );
Where you decide what ‘x’ should be. If this is practical or not depends on what you are actually doing. It could add a significant amounts of time to the process.
..and in general, based on your RTOS experience is my approach at points 1) and 2) a sound way to take advantage of FreeRTOS?
Yes.