...
Also, the small hourglass close to the receiving task indicates that the task has an option to specify a timeout. This timeout indicates that the task is willing to wait for the semaphore to be signaled (or posted to) within a certain amount of time. If the semaphore is not signaled within that time, µC/OS-III resumes the task and returns an error code indicating that the task was made ready-to-run because of a timeout and not the semaphore was signaled.
Panel | ||||
---|---|---|---|---|
| ||||
...
The figure below shows that a task can be synchronized with an ISR (or another task) by using a semaphore. In this case, no data is exchanged, however there is an indication that the ISR or the task (on the left) has occurred. Using a semaphore for this type of synchronization is called a unilateral rendez-vous.
Panel | ||||
---|---|---|---|---|
| ||||
A unilateral rendez-vous is used when a task initiates an I/O operation and waits (i.e., call OSSemPend()
) for the semaphore to be signaled (posted). When the I/O operation is complete, an ISR (or another task) signals the semaphore (i.e., calls OSSemPost()
), and the task is resumed. This process is also shown on the timeline of the figure below and described below. The code for the ISR and task is shown in the listing follows the figure below.
Panel | ||||
---|---|---|---|---|
| ||||
...
As previously mentioned, a semaphore “remembers” how many times it was signaled (or posted to). In other words, if the ISR occurs multiple times before the task waiting for the event becomes the highest-priority task, the semaphore will keep count of the number of times it was signaled. When the task becomes the highest priority ready-to-run task, it will execute without blocking as many times as there were ISRs signaled. This is called Credit Tracking and is illustrated in the figure below and described below.
Panel | ||||
---|---|---|---|---|
| ||||
...
It is possible for more than one task to wait on the same semaphore, each with its own timeout as illustrated in the figure below.
Panel | ||||
---|---|---|---|---|
| ||||
...
Panel | |||||||
---|---|---|---|---|---|---|---|
| |||||||
(1) Your task signals (or posts to) the semaphore by calling (2) The next argument specifies how the task wants to post. There are a number of options to choose from. When you specify If specifying The calling task can “add” the option OS_OPT_POST_1 OS_OPT_POST_ALL OS_OPT_POST_1 + OS_OPT_POST_NO_SCHED OS_OPT_POST_ALL + OS_OPT_POST_NO_SCHED
(3) |
...