Texas Instruments TMS320 User Manual page 166

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

Advertisement

Semaphores
Example 4.11. SEM Example Using Three Writer Tasks (continued)
4-62
/*
*
======== main ========
*/
Void main()
{
Int
i;
MsgObj
*msg;
Uns
mask;
mask = TRC_LOGTSK | TRC_LOGSWI | TRC_STSSWI | TRC_LOGCLK;
TRC_enable(TRC_GBLHOST | TRC_GBLTARG | mask);
msg = (MsgObj *)MEM_alloc(0, NUMMSGS * sizeof(MsgObj), 0);
if (msg == MEM_ILLEGAL) {
SYS_abort("Memory allocation failed!\n");
}
/* Put all messages on freequeue */
for (i = 0; i < NUMMSGS; msg++, i++) {
QUE_put(&freeQueue, msg);
}
}
/*
*
======== reader ========
*/
Void reader()
{
Msg
msg;
Int
i;
for (i = 0; i < NUMMSGS * NUMWRITERS; i++) {
/*
* Wait for semaphore to be posted by writer().
*/
SEM_pend(&sem, SYS_FOREVER);
/* dequeue message */
msg = QUE_get(&msgQueue);
/* print value */
LOG_printf(&trace, "read '%c' from (%d).", msg->val, msg-
>id);
/* free msg */
QUE_put(&freeQueue, msg);
}
LOG_printf(&trace, "reader done.");
}

Advertisement

Table of Contents
loading

Table of Contents