28 static LedMsg_t ledMsg;
30 ledMsg.super.signal = LED_ON_SIG;
39 <b>Message passing</b> @n
40 Messages are passed between tasks by copying the message into a message queue. The posted message must
41 be of the same type that are held by the message queue. The application must allocate space
for this
42 message queue and pass the address of the queue, the queue length and the message size when creating the task:
44 static LedMsg_t msgpool[ Q_SIZE ];
47 task_create( task, prio, msgpool, Q_SIZE,
sizeof(LedMsg_t) );
52 <b>Mutual exclusion and synchronization</b> @n
53 For each message queue, cocoOS creates a binary semaphore and an
event intended to be used
for mutual exclusion
54 and synchronization. @n Before accessing the queue
for either posting or receiving a message, the semaphore
55 should is automatically acquired by the OS. If the semaphore is already taken by another task, the task will be put
56 into the waiting
state until the semaphore is released. @n @n
58 The
event associated with a message queue is automatically signaled when the queue contents changes,
59 i.e. a message is posted to or removed from the queue. A task will be put to wait
for the
event when a
60 message queue was full or empty when trying to post or receive a message respectively. Then when the
61 event is signalled, the task makes a
new post/receive retry to the message queue. @n
62 When a message has been received or posted, the queue semaphore is
finally automatically released by the OS. @n
64 <b>Posting messages</b> @n
65 A message can be posted immediately into another task
's message queue by using msg_post(). The message will be placed
66 in the receiving task's message queue fifo and will be processed as soon as possible.
67 With
msg_post_in() it is possible to specify a delay before the message will be delivered to the receiving task.
68 See also <b>Asynchronous message posting</b> below.
71 static
Msg_t msgpool[ 16 ];
85 static void task1(
void) {
88 msg.signal = 10MS_SIG;
106 static void task3(
void) {
109 msg.signal = BUTTON_SIG;
130 <b>Receiving messages</b>@n
131 Receiving messages is done in the same manner as posting messages, but
using msg_receive() instead.
132 See also <b>Asynchronous message receiving</b> below.@n
135 static
Msg_t msgpool[ 16 ];
148 static void task2(
void) {
166 <b>Periodic messages</b>@n
167 A message can also be setup to be delivered periodically to its receiver with
msg_post_every(). This message will be put into
168 the message queue as a usual delayed message posted with the
msg_post_in() method. When the message delay
169 expires, the message is delivered to the task and reposted to the queue automatically with the timer reloaded.
170 A posted periodic message can not be stopped, it will be delivered periodically forever.
171 Note that this type of message should be posted outside the endless task loop. Otherwise the queue will quickly fill up and the
172 system will be overloaded.
174 <b>Asynchronous message posting</b>@n
175 The task can also post messages using the
msg_post_async() function. The only difference from the usual
msg_post() is that, the
176 task will not block waiting for the queue if it was full. The task will continue executing immediately instead. @n
179 <b>Asynchronous message receiving</b>@n
180 The msg_reveive_async() can be used to poll the queue for messages without blocking the task if the queue is empty. If there are no messages
181 waiting in queue, the function will return immediately and the signal member of the msg parameter will be set to the value NO_MSG_ID (0xff)
184 void ledTask(
void ) {
192 if ( msg.super.signal == LED_SIG ) {
195 else if ( msg.super.signal == NO_MSG_ID ) {
208 The message API consists of the following macros and functions:@n
void os_start(void)
Definition: os_kernel.c:121
#define msg_post_every(task_id, msg, period)
Definition: os_applAPI.h:742
#define task_wait(x)
Definition: os_applAPI.h:112
#define msg_post(task_id, msg)
Definition: os_applAPI.h:553
TaskState_t state
current runstate
Definition: os_task.c:43
uint8_t task_create(taskproctype taskproc, void *data, uint8_t prio, Msg_t *msgPool, uint8_t poolSize, uint16_t msgSize)
Definition: os_task.c:134
#define event_wait(event)
Definition: os_applAPI.h:263
#define msg_post_in(task_id, msg, delay)
Definition: os_applAPI.h:679
#define msg_post_async(task_id, msg)
Definition: os_applAPI.h:615
#define msg_receive(task_id, pMsg)
Definition: os_applAPI.h:804
#define msg_receive_async(task_id, pMsg)
Definition: os_applAPI.h:870
#define task_open()
Definition: os_applAPI.h:67
Definition: os_msgqueue.h:50
#define task_close()
Definition: os_applAPI.h:88