Texas Instruments TMS320 User Manual page 164

Dsp/bios v5.40
Hide thumbs Also See for TMS320:
Table of Contents

Advertisement

Semaphores
Example 4-9. Setting a Timeout with SEM_pend
Example 4-10. Signaling a Semaphore with SEM_post
4.7.1
SEM Example
4-60
Bool SEM_pend(sem, timeout);
SEM_Handle sem;
Uns
timeout; /* return after this many system clock ticks*/
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.
Void SEM_post(sem);
SEM_Handle
sem;
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.

Advertisement

Table of Contents
loading

Table of Contents