rtel wrote on Tuesday, April 13, 2010:
The binary semaphore can either be ‘full’ or ‘empty’ (hence binary). When it is full a call to xSemaphoreTake() will pass. When it is empty a call to xSemaphoreTake() will fail because there is no semaphore to take.
In this example the semaphore is used to signal events, in effect to synchronise a task with an interrupt. The interrupt gives the semaphore, to make the semaphore full, and in so doing unblocks the task. The task, once unblocked, takes the semaphore to make the semaphore empty once again. It then goes around the loop to call xSemaphoreTake() again, at which point it will once again enter the Blocked state to wait for the next interrupt.
However, the semaphore is created to already be in the full state. If the task did not take the semaphore before entering the infinite loop the first call to xSemaphoreTake() would therefore pass - even though no interrupts had yet occurred. The first call to xSemaphoreTake() (outside the loop) ensures the semaphore is empty before the infinite loop is entered - the semaphore should be empty because no interrupts have yet occurred. Now the first call to xSemaphoreTake() will cause the task to enter the Blocked state, because the semaphore is already empty.
Hope this helps your understanding and does not cloud it even more :o)