EasyManua.ls Logo

Texas Instruments TMS320

Texas Instruments TMS320
288 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
Semaphores
4-62
Example 4.11. SEM Example Using Three Writer Tasks (continued)
/*
* ======== 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.”);
}

Table of Contents

Other manuals for Texas Instruments TMS320

Related product manuals