EasyManua.ls Logo

Texas Instruments TMS320 - Page 172

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...
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 % NUMMSGS + (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);
}

Table of Contents

Other manuals for Texas Instruments TMS320

Related product manuals