Texas Instruments TMS320 User Manual page 199

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

Advertisement

5.3.3
QUE Example
Example 5-18. Using QUE to Send Messages
/*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
* A queue can hold an arbitrary number of messages or elements.
* Each message must, however, be a structure with a QUE_Elem as
*
*/
#include <std.h>
#include <log.h>
#include <mem.h>
#include <que.h>
#include <sys.h>
#define NUMMSGS
typedef struct MsgObj {
} MsgObj, *Msg;
extern QUE_Obj queue;
/* Trace Log created statically */
extern LOG_Obj trace;
Void reader();
Void writer();
Example 5-18 uses a QUE queue to send five messages from a writer to a
reader task. The functions MEM_alloc and MEM_free are used to allocate
and free the MsgObj structures.
The program in Example 5-18 yields the results shown in Figure 5-3. The
writer task uses QUE_put to enqueue each of its five messages and then the
reader task uses QUE_get to dequeue each message.
======== quetest.c ========
Use a QUE queue to send messages from a writer to a read
reader.
The queue is created by the Configuration Tool.
For simplicity, we use MEM_alloc and MEM_free to manage
the MsgObj structures. It would be way more efficient to
preallocate a pool of MsgObj's and keep them on a 'free'
queue. Using the Config Tool, create 'freeQueue'. Then in
main, allocate the MsgObj's with MEM_alloc and add them to
'freeQueue' with QUE_put.
You can then replace MEM_alloc calls with QUE_get(freeQueue)
and MEM_free with QUE_put(freeQueue, msg).
its first field.
5
QUE_Elem
elem;
Char
val;
/* number of messages */
/* first field for QUE */
/* message value */
Memory and Low-level Functions
Queues
5-17

Advertisement

Table of Contents
loading

Table of Contents