Question: In your own words, describe how semaphores and binary mutexes are implemented in FreeRTOS. (Do not include semaphore counts.) In the discussion go to the level of FreeRTOS code relevant to semaphores (i.e. your description should include code snippets from the FreeRTOS semaphore code). Make sure you cover all relevant aspects of priority issues and how the code supports the context switching mechanism (without going into code-level details on how the context switching mechanism is implemented). Include a section that relates the FreeRTOS description to the content of the SYSC 5701 lessons. Solution: Semaphore is a Greek word where sema means "sign or signal" and phore means "vector" and is said to be used as a protected variable. There are basically four types of traffic lights:1. Binary traffic lights2. Traffic light counting3. Mutex4. Recursive MutexIn FreeRTOS, the concept of semaphore has a different meaning depending on the context and also its level of usage. FreeRTOS implements semaphores to synchronize the set of tasks with the other events in the system and they are implemented based on the queue mechanism. A macro being defined is responsible for creating a semaphore using the permanent queue mechanism. This queue length can be 0 or 1 depending on the type and context of the semaphore used. The concept of binary semaphore and Mutex are considered two different levels of semaphore implementation or can be considered two different use cases i.e. Mutual exclusion and reporting. Confusion still exists there about the use and terminology of Mutex and Semaphores. As mentioned, the semaphore can take on different meanings based on the context level and...... middle of the sheet...... vSemaphoreCreateBinary( xSemaphore );if( xSemaphore != NULL ){if( xSemaphoreGive( xSemaphore ) ! = pdTRUE ){// We would expect this call to fail because we cannot provide // a semaphore without "getting" it first!}// Get the semaphore: do not block if the semaphore is not // immediately available. if( xSemaphoreTake( xSemaphore, ( portTickType ) 0 ) ){// Now we have the semaphore and can access the shared resource.// ...// We are done accessing the shared resource, so we can free the semaphore. if( xSemaphoreGive( xSemaphore ) != pdTRUE ){// We wouldn't expect this call to fail because we need to have // gotten the semaphore to get here.}}}}
tags