Texas Instruments TMS320 User Manual page 200

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

Advertisement

Queues
Example 5.18. Using QUE to Send Messages (continued)
5-18
/*
======== main ======== */
Void main()
{
/*
* Writer must be called before reader to ensure that the
*
queue is non-empty for the reader.
*/
writer();
reader();
}
/*
======== reader ======== */
Void reader()
{
Msg
msg;
Int
i;
for (i=0; i < NUMMSGS; i++) {
/* The queue should never be empty */
if (QUE_empty(&queue)) {
SYS_abort("queue error\n");
}
/* dequeue message */
msg = QUE_get(&queue);
/* print value */
LOG_printf(&trace, "read '%c'.", msg->val);
/* free msg */
MEM_free(0, msg, sizeof(MsgObj));
}
}
/*
======== writer ======== */
Void writer()
{
Msg
msg;
Int
i;
for (i=0; i < NUMMSGS; i++) {
/* allocate msg */
msg = MEM_alloc(0, sizeof(MsgObj), 0);
if (msg == MEM_ILLEGAL) {
SYS_abort("Memory allocation failed!\n");
}
/* fill in value */
msg->val = i + 'a';
LOG_printf(&trace, "writing '%c' ...", msg->val);
/* enqueue message */
QUE_put(&queue, msg);
}
}

Advertisement

Table of Contents
loading

Table of Contents