Mailboxes
4-68
Example 4.15.
MBX Example With Two Types of Tasks (continued)
After the program runs, review the trace log contents. The results should be
similar to that shown in Figure 4-15.
/*
* ======== reader ========
*/
Void reader(Void)
{
MsgObj msg;
Int i;
for (i=0; ;i++) {
/* wait for mailbox to be posted by writer() */
if (MBX_pend(&mbx, &msg, TIMEOUT) == 0) {
LOG_printf(&trace, "timeout expired for MBX_pend()");
break;
}
/* print value */
LOG_printf(&trace, "read ’%c’ from (%d).", msg.val, msg.id);
}
LOG_printf(&trace, "reader done.");
}
/*
* ======== writer ========
*/
Void writer(Int id)
{
MsgObj msg;
Int i;
for (i=0; i < NUMMSGS; i++) {
/* fill in value */
msg.id = id;
msg.val = i % N (Int)(‘a’);
LOG_printf(&trace, "(%d) writing ‘%c’ ...", id,
(Int)msg.val);
/* enqueue message */
MBX_post(&mbx, &msg, TIMEOUT);
/* what happens if you call TSK_yield() here? */
/* TSK_yield(); */
}
LOG_printf(&trace, "writer (%d) done.", id);
}
Summary of Contents for TMS320 Series
Page 1: ...TMS320 DSP BIOS v5 40 User s Guide Literature Number SPRU423G April 2009 ...
Page 16: ...xvi ...
Page 152: ...Tasks 4 48 Figure 4 12 Trace from Example 4 7 ...
Page 168: ...Semaphores 4 64 Figure 4 14 Trace Results from Example 4 11 ...
Page 202: ...5 20 ...
Page 287: ...Index 9 Index Void 1 11 W words data memory 3 15 of code 1 5 wrapper function 2 29 ...
Page 288: ...Index 10 Index ...