Texas Instruments TMS320 User Manual page 167

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

Advertisement

Example 4.11. SEM Example Using Three Writer Tasks (continued)
/*
*
======== writer ========
*/
Void writer(Int id)
{
Msg
msg;
Int
i;
for (i = 0; i < NUMMSGS; i++) {
/*
* Get msg from the free queue. Since reader is higher
* priority and only blocks on sem, this queue is
* never empty.
*/
if (QUE_empty(&freeQueue)) {
SYS_abort("Empty free queue!\n");
}
msg = QUE_get(&freeQueue);
/* fill in value */
msg->id = id;
msg->val = (i & 0xf) + 'a';
LOG_printf(&trace, "(%d) writing '%c' ...", id, msg->val);
/* enqueue message */
QUE_put(&msgQueue, msg);
/* post semaphore */
SEM_post(&sem);
/* what happens if you call TSK_yield() here? */
/* TSK_yield(); */
}
LOG_printf(&trace, "writer (%d) done.", id);
}
Note:
Non-pointer type function arguments to LOG_printf need explicit type
casting to (Arg) as shown in the following code example:
LOG_printf(&trace, "Task %d Done", (Arg)id);
Semaphores
Thread Scheduling
4-63

Advertisement

Table of Contents
loading

Table of Contents