marifca wrote on Wednesday, June 11, 2014:
Hi,
I am new to RTOS world. Starting with FreeRTOS. I am using Freescale Coldfire V2 microcontrollers and managed to start several tasks running on it. But I am a bit confused regarding the delay used in semaphores. I have an interrupt giving a semaphore using xSemaphoreGiveFromISR() and a task blocking this accepts it using xSemaphoreTake() as in the following example
// A task that uses the semaphore.
void vAnotherTask( void * pvParameters )
{
// … Do other things.
if( xSemaphore != NULL )
{
// See if we can obtain the semaphore. If the semaphore is not available
// wait 10 ticks to see if it becomes free.
if( xSemaphoreTake( xSemaphore, ( TickType_t ) 10 ) == pdTRUE )
{
// We were able to obtain the semaphore and can now access the
// shared resource.
// ..."My Code"
// We have finished accessing the shared resource. Release the
// semaphore.
xSemaphoreGive( xSemaphore );
}
else
{
// We could not obtain the semaphore and can therefore not access
// the shared resource safely.
}
}
}
My question is what does this ( TickType_t ) 10 actually means or doing here? What happens to the “My code” block in the following three cases:
- xTicksToWait value is 0 … is “My code” executed with every tick? Then what is the the significance of giving the semaphore from an interrupt and an event tracking mechanism?
- xTicksToWait value is 10 …
- xTicksToWait value is MaxDelay (I guess 0xffffffff) and what is the difference in action between the used value of 0 and MaxDelay?
Also I would like to know what if I use
xSemaphoreTake( xSemaphore, ( TickType_t ) 10 );
//“My Code”
xSemaphoreGive( xSemaphore );
instead of the if-else structure shown above. Will it exit the task without executing “My code” if the semaphore cannot be taken? I am asking this because I have seen some code examples on a FreeRTOS book for PC showing such examples without the if( == pdTRUE) else{} statements.
Thanks in advance.