Semaphores
Thread Scheduling
4-61
Example 4-11.
SEM Example Using Three Writer Tasks
/*
* ======== semtest.c ========
*
* Use a QUE queue and SEM semaphore to send messages from
* multiple writer() tasks to a single reader() task. The
* reader task, the three writer tasks, queues, and semaphore
* are created statically.
*
* The MsgObj’s are preallocated in main(), and put on the
* free queue. The writer tasks get free message structures
* from the free queue, write the message, and then put the
* message structure onto the message queue.
* This example builds on quetest.c. The major differences are:
* - one reader() and multiple writer() tasks.
* - SEM_pend() and SEM_post() are used to synchronize
* access to the message queue.
* - ‘id’ field was added to MsgObj to specify writer()
* task id.
*
* Unlike a mailbox, a queue can hold an arbitrary number of
* messages or elements. Each message must, however, be a
* structure with a QUE_Elem as its first field.
*/
#include <std.h>
#include <log.h>
#include <mem.h>
#include <que.h>
#include <sem.h>
#include <sys.h>
#include <tsk.h>
#include <trc.h>
#define NUMMSGS 3 /* number of messages */
#define NUMWRITERS 3 /* number of writer tasks created with */
/* Config Tool */
typedef struct MsgObj {
QUE_Elem elem; /* first field for QUE */
Int id; /* writer task id */
Char val; /* message value */
} MsgObj, *Msg;
Void reader();
Void writer();
/*
* The following objects are created statically.
*/
extern SEM_Obj sem;
extern QUE_Obj msgQueue;
extern QUE_Obj freeQueue;
extern LOG_Obj trace
Summary of Contents for TMS320 Series
Page 1: ...TMS320 DSP BIOS v5 40 User s Guide Literature Number SPRU423G April 2009 ...
Page 16: ...xvi ...
Page 152: ...Tasks 4 48 Figure 4 12 Trace from Example 4 7 ...
Page 168: ...Semaphores 4 64 Figure 4 14 Trace Results from Example 4 11 ...
Page 202: ...5 20 ...
Page 287: ...Index 9 Index Void 1 11 W words data memory 3 15 of code 1 5 wrapper function 2 29 ...
Page 288: ...Index 10 Index ...