Chapter 3 Introduction to MR308
- 42 -
3.5.8 Synchronization and Communication Function (Mailbox)
The mailbox is a mechanism to perform data communication between tasks. In Figure 3.33, for example, task A
can drop a message into the mailbox and task B can retrieve the message from the mailbox. Since mail-
box-based communication is achieved by transferring the beginning address of a message from a task to an-
other, this mode of communication is performed at high speed independently of the message size.
The kernel manages the message queue by means of a link list. The application should prepare a header area
that is to be used for a link list. This is called the message header. The message header and the area actually
used by the application to store a message are called the message packet. The kernel rewrites the content of
the message header as it manages the message queue. The message header cannot be rewritten from the ap-
plication. The structure of the message queue is shown in Figure 3.34. The message header has its data types
defined as shown below.
T_MSG: Mailbox message header
T_MSG_PRI: Mailbox message header with priority included
Messages in any size can be enqueued in the message queue because the header area is reserved on the ap-
plication side. In no event will tasks be kept waiting for transmission.
Messages can be assigned priority, so that messages will be received in order of priority beginning with the
highest. In this case, TA_MPRI should be added to the mailbox attribute. If messages need to be received in
order of FIFO, add TA_MFIFO to the mailbox attribute.34 Furthermore, if tasks in a message wait state are to
receive a message, the tasks can be prioritized in which order they can receive a message, beginning with one
that has the highest priority. In this case, add TA_TPRI to the mailbox attribute. If tasks are to receive a mes-
sage in order of FIFO, add TA_TFIFO to the mailbox attribute.35

Message Message

TaskB

TaskA

Figure 3.33 Mailbox
34 It is in the mailbox definition "message_queue" of the configuration file that the TA_MPRI or TA_MFIFO attribute should be added.
35 It is in the mailbox definition "wait_queue" of the configuration file that the TA_TPRI or TA_TFIFO attribute should be added.