Free RTOS Semaphores Free RTOS allows communication and

  • Slides: 14
Download presentation
Free. RTOS Semaphores Free. RTOS allows communication and synchronization between tasks using semaphores. These

Free. RTOS Semaphores Free. RTOS allows communication and synchronization between tasks using semaphores. These are actually implemented using queues. ECP-622– Spring 2020 Week 7 - Page 1

Free. RTOS Semaphores Free. RTOS allows communication and synchronization between tasks using semaphores. These

Free. RTOS Semaphores Free. RTOS allows communication and synchronization between tasks using semaphores. These are actually implemented using queues. API functions are available for binary semaphores, counting semaphores and mutexes. ECP-622– Spring 2020 Week 7 - Page 1

Free. RTOS Binary Semaphores The function x. Semaphore. Create. Binary(void)creates a binary semaphore and

Free. RTOS Binary Semaphores The function x. Semaphore. Create. Binary(void)creates a binary semaphore and returns a handle to this semaphore (or NULL if creation fails). ECP-622– Spring 2020 Week 7 - Page 2

Free. RTOS Binary Semaphores The function x. Semaphore. Create. Binary(void)creates a binary semaphore and

Free. RTOS Binary Semaphores The function x. Semaphore. Create. Binary(void)creates a binary semaphore and returns a handle to this semaphore (or NULL if creation fails). need to be included. Initial state of semaphore is equivalent to a value of 0. semphr. h ECP-622– Spring 2020 Week 7 - Page 2

Free. RTOS Binary Semaphores The function x. Semaphore. Create. Binary(void)creates a binary semaphore and

Free. RTOS Binary Semaphores The function x. Semaphore. Create. Binary(void)creates a binary semaphore and returns a handle to this semaphore (or NULL if creation fails). need to be included. Initial state of semaphore is equivalent to a value of 0. semphr. h The down () and up () functions are executed by the API functions: x. Semaphore. Take (Semaphore_handle, Ticks_to_wait) x. Semaphore. Give (Semaphore_handle) ECP-622– Spring 2020 Week 7 - Page 2

Free. RTOS Counting Semaphores The function x. Semaphore. Create. Counting()creates a counting semaphore and

Free. RTOS Counting Semaphores The function x. Semaphore. Create. Counting()creates a counting semaphore and returns a handle to this semaphore (or NULL if creation fails). ECP-622– Spring 2020 Week 7 - Page 3

Free. RTOS Counting Semaphores The function x. Semaphore. Create. Counting()creates a counting semaphore and

Free. RTOS Counting Semaphores The function x. Semaphore. Create. Counting()creates a counting semaphore and returns a handle to this semaphore (or NULL if creation fails). #include “semphr. h" ……………… Semaphore. Handle_t sh; ……………. sh=x. Semaphore. Create. Counting(10, 1); Maximum count ECP-622– Spring 2020 Initial count Week 7 - Page 3

Free. RTOS Counting Semaphores The functions x. Semaphore. Take() and x. Semaphore. Give() are

Free. RTOS Counting Semaphores The functions x. Semaphore. Take() and x. Semaphore. Give() are used also for down and up operations on counting semaphores. These functions return pd. TRUE (=1) if successful, and pd. FALSE (=0) otherwise, e. g. : ECP-622– Spring 2020 Week 7 - Page 4

Free. RTOS Counting Semaphores The functions x. Semaphore. Take() and x. Semaphore. Give() are

Free. RTOS Counting Semaphores The functions x. Semaphore. Take() and x. Semaphore. Give() are used also for down and up operations on counting semaphores. These functions return pd. TRUE (=1) if successful, and pd. FALSE (=0) otherwise, e. g. : o Specified tick counts expire without taking the semaphore. ECP-622– Spring 2020 Week 7 - Page 4

Free. RTOS Counting Semaphores The functions x. Semaphore. Take() and x. Semaphore. Give() are

Free. RTOS Counting Semaphores The functions x. Semaphore. Take() and x. Semaphore. Give() are used also for down and up operations on counting semaphores. These functions return pd. TRUE (=1) if successful, and pd. FALSE (=0) otherwise, e. g. : o Specified tick counts expire without taking the semaphore. o Giving a counting semaphore will cause it to exceed maximum count. o Giving a binary semaphore that’s already given (=1). ECP-622– Spring 2020 Week 7 - Page 4

Free. RTOS Mutexes A mutex is a semaphore used for mutual exclusion. It differs

Free. RTOS Mutexes A mutex is a semaphore used for mutual exclusion. It differs from a binary semaphore in the following: o Initial state of semaphore is equivalent to a value of 1. ECP-622– Spring 2020 Week 7 - Page 5

Free. RTOS Mutexes A mutex is a semaphore used for mutual exclusion. It differs

Free. RTOS Mutexes A mutex is a semaphore used for mutual exclusion. It differs from a binary semaphore in the following: o Initial state of semaphore is equivalent to a value of 1. o Mutex implements priority inheritance: priority of task holding the mutex is temporarily raised to that of highest priority task attempting to take the same mutex. ECP-622– Spring 2020 Week 7 - Page 5

Free. RTOS Mutexes A mutex is a semaphore used for mutual exclusion. It differs

Free. RTOS Mutexes A mutex is a semaphore used for mutual exclusion. It differs from a binary semaphore in the following: o Initial state of semaphore is equivalent to a value of 1. o Mutex implements priority inheritance: priority of task holding the mutex is temporarily raised to that of highest priority task attempting to take the same mutex. o A task that takes a mutex will always give it back. ECP-622– Spring 2020 Week 7 - Page 5

Free. RTOS Mutexes A mutex is a semaphore used for mutual exclusion. It differs

Free. RTOS Mutexes A mutex is a semaphore used for mutual exclusion. It differs from a binary semaphore in the following: o Initial state of semaphore is equivalent to a value of 1. o Mutex implements priority inheritance: priority of task holding the mutex is temporarily raised to that of highest priority task attempting to take the same mutex. o A task that takes a mutex will always give it back. It is created using the function x. Semaphore. Create. Mutex(void) and manipulated by the same functions x. Semaphore. Take() and x. Semaphore. Give(). ECP-622– Spring 2020 Week 7 - Page 5