...
Anchor
OS_MSG
, shown in Figure 15 Figure 15-11.The sender and receiver are unaware of this data structure since everything is hidden through the APIs provided by µC/OS-III. Anchor
...
Figure 15-11 OS_MSG structure
...
Anchor
µC/OS-III maintains a pool of free OS_MSGs
. The total number of available messages in the pool is determined by the value of OS_CFG_MSG_POOL_SIZE
found in os_cfg_app.h
. When µC/OS-III is initialized, OS_MSGs
are linked in a single linked list as shown in Figure 15 Figure 15-12. Notice that the free list is maintained by a data structure of type OS_MSG_POOL
, which contains four (4) fields: .NextPtr
, which points to the free list; .NbrFree
, which contains the number of free OS_MSGs
in the pool, .NbrUsed
, which contains the number of OS_MSGs
allocated to the application and, .NbrUsedMax
which detects the maximum number of messages allocated to the application. Anchor
...
Figure 15-12 Pool of free OS_MSGs
...
Anchor
Messages are queued using a data structure of type OS_MSG_Q
, as shown in Figure 15 Figure 15-13. Anchor
...
Figure 15-13 OS_MSG_Q structure
...
Anchor
.InPtr
Anchor
This field contains a pointer to where the next OS_MSG
will be inserted in the queue. In fact, the OS_MSG
will be inserted “after” the OS_MSG
pointed to.
...
.OutPtr
Anchor
This field contains a pointer to where the next OS_MSG
will be extracted.
...
.NbrEntriesSize
Anchor
This field contains the maximum number of OS_MSGs
that the queue will hold. If an application attempts to send a message and the .NbrEntries
matches this value, the queue is considered to be full and the OS_MSG
will not be inserted.
...
.NbrEntries
Anchor
This field contains the current number of OS_MSGs
in the queue.
...
.NbrEntriesMax
anchor
This field contains the highest number of OS_MSGs
existing in the queue at any given time.
...
A number of internal functions are used by µC/OS-III to manipulate the free list and messages. Specifically, OS_MsgQPut()
inserts an OS_MSG
in an OS_MSG_Q
, OS_MsgQGet()
extracts an OS_MSG
from an OS_MSG_Q
, and OS_MsgQFreeAll()
returns all OS_MSGs
in an OS_MSG_Q
to the pool of free OS_MSGs
. There are other OS_MsgQ??()
functions in os_msg.c
that are used during initialization.
Anchor
OS_MSG_Q
when four OS_MSGs
are inserted....
Figure 15-14 OS_MSG_Q with four OS_MSGs
...
Anchor
OS_MSG_Qs
are used inside two additional data structures: OS_Q
and OS_TCB
. Recall that an OS_Q
is declared when creating a message queue object. An OS_TCB
is a task control block and, as previously mentioned, each OS_TCB
can have its own message queue when the configuration constant OS_CFG_TASK_Q_EN
is set to 1 in os_cfg.h
. Figure 15 Figure 15-15 shows the contents of an OS_Q
and partial contents of an OS_TCB
containing an OS_MSG_Q
. The OS_MSG_Q
data structure is shown as an “exploded view” to emphasize the structure within the structure. Anchor
...
Figure 15-15 OS_Q and OS_TCB each contain an OS_MSG_Q