EasyManuals Logo

Texas Instruments TMS320 User Manual

Texas Instruments TMS320
288 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Page #164 background imageLoading...
Page #164 background image
Semaphores
4-60
Example 4-9. Setting a Timeout with SEM_pend
Example 4-10 provides an example of SEM_post, which is used to signal a
semaphore. If a task is waiting for the semaphore, SEM_post removes the
task from the semaphore queue and puts it on the ready queue. If no tasks
are waiting, SEM_post simply increments the semaphore count and returns.
Example 4-10. Signaling a Semaphore with SEM_post
4.7.1 SEM Example
Example 4-11 provides sample code for three writer tasks which create
unique messages and place them on a queue for one reader task. The writer
tasks call SEM_post to indicate that another message has been enqueued.
The reader task calls SEM_pend to wait for messages. SEM_pend returns
only when a message is available on the queue. The reader task prints the
message using the LOG_printf function.
The three writer tasks, reader task, semaphore, and queues in this example
program were created statically.
Since this program employs multiple tasks, a counting semaphore is used to
synchronize access to the queue. Figure 4-14 provides a view of the results
from Example 4-10. Though the three writer tasks are scheduled first, the
messages are read as soon as they have been enqueued because the
reader’s task priority is higher than that of the writer.
Bool SEM_pend(sem, timeout);
SEM_Handle sem;
Uns timeout; /* return after this many system clock ticks*/
Void SEM_post(sem);
SEM_Handle sem;

Table of Contents

Other manuals for Texas Instruments TMS320

Questions and Answers:

Question and Answer IconNeed help?

Do you have a question about the Texas Instruments TMS320 and is the answer not in the manual?

Texas Instruments TMS320 Specifications

General IconGeneral
BrandTexas Instruments
ModelTMS320
CategoryComputer Hardware
LanguageEnglish

Related product manuals