Queues
Memory and Low-level Functions
5-17
5.3.3
QUE Example
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.
Example 5-18.
Using QUE to Send Messages
/*
* ======== 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).
*
* 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 <sys.h>
#define NUMMSGS 5 /* number of messages */
typedef struct MsgObj {
QUE_Elem elem; /* first field for QUE */
Char val; /* message value */
} MsgObj, *Msg;
extern QUE_Obj queue;
/* Trace Log created statically */
extern LOG_Obj trace;
Void reader();
Void writer();
Содержание TMS320 Series
Страница 1: ...TMS320 DSP BIOS v5 40 User s Guide Literature Number SPRU423G April 2009 ...
Страница 16: ...xvi ...
Страница 152: ...Tasks 4 48 Figure 4 12 Trace from Example 4 7 ...
Страница 168: ...Semaphores 4 64 Figure 4 14 Trace Results from Example 4 11 ...
Страница 202: ...5 20 ...
Страница 287: ...Index 9 Index Void 1 11 W words data memory 3 15 of code 1 5 wrapper function 2 29 ...
Страница 288: ...Index 10 Index ...