waiting on semaphores – indefinitely

1. To wait indefinitely, one needs to use: xSemaphoreTake( xSemaPhore, portMAX_DELAY ); Also, the configuration #define INCLUDE_vTaskSuspend            1 has to be set to 1. What is the relationship between the two? Is portMax_DELAY not enough in itself? 2. Documentation on  xSemaphoreCreateMutex() in semaphor.h is confusing It is defined as: #define xSemaphoreCreateMutex() xQueueCreateMutex() where as the explanation calls for: xSemaphoreCreateMutex( xSemaphoreHandle xSemaphore ) and the usage is: XMutex = xSemaphoreCreateMutex(); 3. What is the difference between binary semaphore and mutex – If taskA takes a semaphore xSemaphoreTake( xSema1, portMAX_DELAY ); and not give, can TaskB get the xSema1 or will it go into waiting for the sema till it is given back by taskA?

waiting on semaphores – indefinitely

> 1. To wait indefinitely, one needs to use: > xSemaphoreTake( xSemaPhore, portMAX_DELAY ); > Also, the configuration #define INCLUDE_vTaskSuspend        >     1 > has to be set to 1. > What is the relationship between the two? > Is portMax_DELAY not enough in itself? Including INCLUDE_vTaskSuspend causes a new state list to be included – one in which suspended tasks are referenced (not surprisingly).  Suspended tasks differ from blocked tasks as they do not have a timeout.  If this list was not included in the build then the only option is to place tasks in a blocked list, from which it would eventually unblock.  On 32bit systems unblocking after 0xffffffff ticks is usually very similar to blocking indefinitely anyway. The suspended list is used for convenience only – tasks that are blocked indefinitely remain conceptually in the blocked state – not the suspended state. If you don’t want to use INCLUDE_vTaskSuspend then you have the option to place calls in a loop, for example: while( xSemaphoreTake( xSemaphore, portMAX_DELAY ) != pdPASS ); has the same effect as waiting indefinitely, if a little less efficient. > > 2. Documentation on  xSemaphoreCreateMutex() in semaphor.h is > confusing > It is defined as: > #define xSemaphoreCreateMutex() xQueueCreateMutex() > where as the explanation calls for: > xSemaphoreCreateMutex( xSemaphoreHandle xSemaphore ) > and the usage is: > XMutex = xSemaphoreCreateMutex(); Err – its even worse on the WEB site.  I will fix this.  Thought it had been already. For now take a look in FreeRTOS/Demo/Common/Minimal/GenQTest.c for an example usage. > 3. What is the difference between binary semaphore and mutex – > If taskA takes a semaphore xSemaphoreTake( xSema1, portMAX_DELAY ); > and not give, can TaskB get the xSema1 or will it go into > waiting for the sema > till it is given back by taskA? The primary difference is that mutexes use priority inheritance, binary semaphores don’t.  This means mutexes must always be ‘given back’, whereas binary semaphores can be used for unidirectional synchronisation, with an ISR for example, where the semaphore is always given by the ISR and always taken by a task and never the other way around. Regards.

waiting on semaphores – indefinitely

The WEB docs should now be correct (?), I have also updated the SVN copy of semphr.h. Regards.