Download 8051 RTOS
Transcript
Interprocess Communication
See section 10.6.2, Starting the COM Extension, for more information regarding the com hook
routine StartCOMExtension().
StatusType StartCOMExtension(void);
{
myStruct st;
/* prepare the default message */
st.header = 0x12;
for (i=0;i<PAYLOADSIZE;i++)
{
st.payload[i] = 0;
}
st.crc = 0xFF;
/* initialize the receive message object recMU */
InitMessage(recMU,&st);
...
TerminateTask();
}
You can also use InitMessage() to reset your unqueued messages at any moment (after you
have called StartCOM() and before you call StopCOM()).
10.4.5 Long versus Short Messages
Sending a message involves the copying of data from an application buffer into (at least one) receive
message objects. Reversely, receiving a message involves the copying of data from a receive
message object into an application buffer.
Concurrency problems to protect critical data are resolved inside the RTOS code by means of
temporarily suspending all Category 2 ISRs (and the system timer).
While copying to/from unqueue receive message objects we need always protection against
concurrency, thus Category 2 ISRs must be always disabled during the copy process. As a simple
mental exercise, imagine what would happen if a SendMessage call is preempted by another
SendMessage. After the two calls, the buffer data are corrupted (a mix of both messages).
While copying to/from queue receive message objects, concurrency problems can be avoided without
real need to disable Category 2 ISRs (implementing locks in every member of the message queue).
So, keeping interrupts enabled while copying the messages is certainly possible. Extra software is
needed to handle locks in the queue. If the messages to be copied are very long, you simply cannot
allow interrupts to be disabled during the whole copy process. However, if messages are so short that
interrupts can be easily disabled during the copy process, this extra handling should be best avoided.
If you set the non-standard attribute LONGMSG to TRUE, Category 2 ISRs are disabled while the
copy process of queued messages and extra software (i.e. run-time performance) is needed. If set to
FALSE, Category 2 ISRs are enabled but no extra software is needed.
10-13