1 | .. comment SPDX-License-Identifier: CC-BY-SA-4.0 |
---|
2 | |
---|
3 | .. COMMENT: COPYRIGHT (c) 1988-2008. |
---|
4 | .. COMMENT: On-Line Applications Research Corporation (OAR). |
---|
5 | .. COMMENT: All rights reserved. |
---|
6 | |
---|
7 | Message Manager |
---|
8 | ############### |
---|
9 | |
---|
10 | .. index:: messages |
---|
11 | .. index:: message queues |
---|
12 | |
---|
13 | Introduction |
---|
14 | ============ |
---|
15 | |
---|
16 | The message manager provides communication and synchronization capabilities |
---|
17 | using RTEMS message queues. The directives provided by the message manager |
---|
18 | are: |
---|
19 | |
---|
20 | - rtems_message_queue_create_ - Create a queue |
---|
21 | |
---|
22 | - rtems_message_queue_ident_ - Get ID of a queue |
---|
23 | |
---|
24 | - rtems_message_queue_delete_ - Delete a queue |
---|
25 | |
---|
26 | - rtems_message_queue_send_ - Put message at rear of a queue |
---|
27 | |
---|
28 | - rtems_message_queue_urgent_ - Put message at front of a queue |
---|
29 | |
---|
30 | - rtems_message_queue_broadcast_ - Broadcast N messages to a queue |
---|
31 | |
---|
32 | - rtems_message_queue_receive_ - Receive message from a queue |
---|
33 | |
---|
34 | - rtems_message_queue_get_number_pending_ - Get number of messages pending on a queue |
---|
35 | |
---|
36 | - rtems_message_queue_flush_ - Flush all messages on a queue |
---|
37 | |
---|
38 | Background |
---|
39 | ========== |
---|
40 | |
---|
41 | Messages |
---|
42 | -------- |
---|
43 | |
---|
44 | A message is a variable length buffer where information can be stored to |
---|
45 | support communication. The length of the message and the information stored in |
---|
46 | that message are user-defined and can be actual data, pointer(s), or empty. |
---|
47 | |
---|
48 | Message Queues |
---|
49 | -------------- |
---|
50 | |
---|
51 | A message queue permits the passing of messages among tasks and ISRs. Message |
---|
52 | queues can contain a variable number of messages. Normally messages are sent |
---|
53 | to and received from the queue in FIFO order using the |
---|
54 | ``rtems_message_queue_send`` directive. However, the |
---|
55 | ``rtems_message_queue_urgent`` directive can be used to place messages at the |
---|
56 | head of a queue in LIFO order. |
---|
57 | |
---|
58 | Synchronization can be accomplished when a task can wait for a message to |
---|
59 | arrive at a queue. Also, a task may poll a queue for the arrival of a message. |
---|
60 | |
---|
61 | The maximum length message which can be sent is set on a per message queue |
---|
62 | basis. The message content must be copied in general to/from an internal |
---|
63 | buffer of the message queue or directly to a peer in certain cases. This copy |
---|
64 | operation is performed with interrupts disabled. So it is advisable to keep |
---|
65 | the messages as short as possible. |
---|
66 | |
---|
67 | Building a Message Queue Attribute Set |
---|
68 | -------------------------------------- |
---|
69 | .. index:: message queue attributes |
---|
70 | |
---|
71 | In general, an attribute set is built by a bitwise OR of the desired attribute |
---|
72 | components. The set of valid message queue attributes is provided in the |
---|
73 | following table: |
---|
74 | |
---|
75 | .. list-table:: |
---|
76 | :class: rtems-table |
---|
77 | |
---|
78 | * - ``RTEMS_FIFO`` |
---|
79 | - tasks wait by FIFO (default) |
---|
80 | * - ``RTEMS_PRIORITY`` |
---|
81 | - tasks wait by priority |
---|
82 | * - ``RTEMS_LOCAL`` |
---|
83 | - local message queue (default) |
---|
84 | * - ``RTEMS_GLOBAL`` |
---|
85 | - global message queue |
---|
86 | |
---|
87 | An attribute listed as a default is not required to appear in the attribute |
---|
88 | list, although it is a good programming practice to specify default attributes. |
---|
89 | If all defaults are desired, the attribute ``RTEMS_DEFAULT_ATTRIBUTES`` should |
---|
90 | be specified on this call. |
---|
91 | |
---|
92 | This example demonstrates the attribute_set parameter needed to create a local |
---|
93 | message queue with the task priority waiting queue discipline. The |
---|
94 | attribute_set parameter to the ``rtems_message_queue_create`` directive could |
---|
95 | be either ``RTEMS_PRIORITY`` or ``RTEMS_LOCAL | RTEMS_PRIORITY``. The |
---|
96 | attribute_set parameter can be set to ``RTEMS_PRIORITY`` because |
---|
97 | ``RTEMS_LOCAL`` is the default for all created message queues. If a similar |
---|
98 | message queue were to be known globally, then the attribute_set parameter would |
---|
99 | be ``RTEMS_GLOBAL | RTEMS_PRIORITY``. |
---|
100 | |
---|
101 | Building a MESSAGE_QUEUE_RECEIVE Option Set |
---|
102 | ------------------------------------------- |
---|
103 | |
---|
104 | In general, an option is built by a bitwise OR of the desired option |
---|
105 | components. The set of valid options for the ``rtems_message_queue_receive`` |
---|
106 | directive are listed in the following table: |
---|
107 | |
---|
108 | .. list-table:: |
---|
109 | :class: rtems-table |
---|
110 | |
---|
111 | * - ``RTEMS_WAIT`` |
---|
112 | - task will wait for a message (default) |
---|
113 | * - ``RTEMS_NO_WAIT`` |
---|
114 | - task should not wait |
---|
115 | |
---|
116 | An option listed as a default is not required to appear in the option OR list, |
---|
117 | although it is a good programming practice to specify default options. If all |
---|
118 | defaults are desired, the option ``RTEMS_DEFAULT_OPTIONS`` should be specified |
---|
119 | on this call. |
---|
120 | |
---|
121 | This example demonstrates the option parameter needed to poll for a message to |
---|
122 | arrive. The option parameter passed to the ``rtems_message_queue_receive`` |
---|
123 | directive should be ``RTEMS_NO_WAIT``. |
---|
124 | |
---|
125 | Operations |
---|
126 | ========== |
---|
127 | |
---|
128 | Creating a Message Queue |
---|
129 | ------------------------ |
---|
130 | |
---|
131 | The ``rtems_message_queue_create`` directive creates a message queue with the |
---|
132 | user-defined name. The user specifies the maximum message size and maximum |
---|
133 | number of messages which can be placed in the message queue at one time. The |
---|
134 | user may select FIFO or task priority as the method for placing waiting tasks |
---|
135 | in the task wait queue. RTEMS allocates a Queue Control Block (QCB) from the |
---|
136 | QCB free list to maintain the newly created queue as well as memory for the |
---|
137 | message buffer pool associated with this message queue. RTEMS also generates a |
---|
138 | message queue ID which is returned to the calling task. |
---|
139 | |
---|
140 | For GLOBAL message queues, the maximum message size is effectively limited to |
---|
141 | the longest message which the MPCI is capable of transmitting. |
---|
142 | |
---|
143 | Obtaining Message Queue IDs |
---|
144 | --------------------------- |
---|
145 | |
---|
146 | When a message queue is created, RTEMS generates a unique message queue ID. |
---|
147 | The message queue ID may be obtained by either of two methods. First, as the |
---|
148 | result of an invocation of the ``rtems_message_queue_create`` directive, the |
---|
149 | queue ID is stored in a user provided location. Second, the queue ID may be |
---|
150 | obtained later using the ``rtems_message_queue_ident`` directive. The queue ID |
---|
151 | is used by other message manager directives to access this message queue. |
---|
152 | |
---|
153 | Receiving a Message |
---|
154 | ------------------- |
---|
155 | |
---|
156 | The ``rtems_message_queue_receive`` directive attempts to retrieve a message |
---|
157 | from the specified message queue. If at least one message is in the queue, |
---|
158 | then the message is removed from the queue, copied to the caller's message |
---|
159 | buffer, and returned immediately along with the length of the message. When |
---|
160 | messages are unavailable, one of the following situations applies: |
---|
161 | |
---|
162 | - By default, the calling task will wait forever for the message to arrive. |
---|
163 | |
---|
164 | - Specifying the ``RTEMS_NO_WAIT`` option forces an immediate return with an |
---|
165 | error status code. |
---|
166 | |
---|
167 | - Specifying a timeout limits the period the task will wait before returning |
---|
168 | with an error status. |
---|
169 | |
---|
170 | If the task waits for a message, then it is placed in the message queue's task |
---|
171 | wait queue in either FIFO or task priority order. All tasks waiting on a |
---|
172 | message queue are returned an error code when the message queue is deleted. |
---|
173 | |
---|
174 | Sending a Message |
---|
175 | ----------------- |
---|
176 | |
---|
177 | Messages can be sent to a queue with the ``rtems_message_queue_send`` and |
---|
178 | ``rtems_message_queue_urgent`` directives. These directives work identically |
---|
179 | when tasks are waiting to receive a message. A task is removed from the task |
---|
180 | waiting queue, unblocked, and the message is copied to a waiting task's message |
---|
181 | buffer. |
---|
182 | |
---|
183 | When no tasks are waiting at the queue, ``rtems_message_queue_send`` places the |
---|
184 | message at the rear of the message queue, while ``rtems_message_queue_urgent`` |
---|
185 | places the message at the front of the queue. The message is copied to a |
---|
186 | message buffer from this message queue's buffer pool and then placed in the |
---|
187 | message queue. Neither directive can successfully send a message to a message |
---|
188 | queue which has a full queue of pending messages. |
---|
189 | |
---|
190 | Broadcasting a Message |
---|
191 | ---------------------- |
---|
192 | |
---|
193 | The ``rtems_message_queue_broadcast`` directive sends the same message to every |
---|
194 | task waiting on the specified message queue as an atomic operation. The |
---|
195 | message is copied to each waiting task's message buffer and each task is |
---|
196 | unblocked. The number of tasks which were unblocked is returned to the caller. |
---|
197 | |
---|
198 | Deleting a Message Queue |
---|
199 | ------------------------ |
---|
200 | |
---|
201 | The ``rtems_message_queue_delete`` directive removes a message queue from the |
---|
202 | system and frees its control block as well as the memory associated with this |
---|
203 | message queue's message buffer pool. A message queue can be deleted by any |
---|
204 | local task that knows the message queue's ID. As a result of this directive, |
---|
205 | all tasks blocked waiting to receive a message from the message queue will be |
---|
206 | readied and returned a status code which indicates that the message queue was |
---|
207 | deleted. Any subsequent references to the message queue's name and ID are |
---|
208 | invalid. Any messages waiting at the message queue are also deleted and |
---|
209 | deallocated. |
---|
210 | |
---|
211 | Directives |
---|
212 | ========== |
---|
213 | |
---|
214 | This section details the message manager's directives. A subsection is |
---|
215 | dedicated to each of this manager's directives and describes the calling |
---|
216 | sequence, related constants, usage, and status codes. |
---|
217 | |
---|
218 | .. _rtems_message_queue_create: |
---|
219 | |
---|
220 | MESSAGE_QUEUE_CREATE - Create a queue |
---|
221 | ------------------------------------- |
---|
222 | .. index:: create a message queue |
---|
223 | |
---|
224 | **CALLING SEQUENCE:** |
---|
225 | |
---|
226 | .. index:: rtems_message_queue_create |
---|
227 | |
---|
228 | .. code-block:: c |
---|
229 | |
---|
230 | rtems_status_code rtems_message_queue_create( |
---|
231 | rtems_name name, |
---|
232 | uint32_t count, |
---|
233 | size_t max_message_size, |
---|
234 | rtems_attribute attribute_set, |
---|
235 | rtems_id *id |
---|
236 | ); |
---|
237 | |
---|
238 | **DIRECTIVE STATUS CODES:** |
---|
239 | |
---|
240 | .. list-table:: |
---|
241 | :class: rtems-table |
---|
242 | |
---|
243 | * - ``RTEMS_SUCCESSFUL`` |
---|
244 | - queue created successfully |
---|
245 | * - ``RTEMS_INVALID_NAME`` |
---|
246 | - invalid queue name |
---|
247 | * - ``RTEMS_INVALID_ADDRESS`` |
---|
248 | - ``id`` is NULL |
---|
249 | * - ``RTEMS_INVALID_NUMBER`` |
---|
250 | - invalid message count |
---|
251 | * - ``RTEMS_INVALID_SIZE`` |
---|
252 | - invalid message size |
---|
253 | * - ``RTEMS_TOO_MANY`` |
---|
254 | - too many queues created |
---|
255 | * - ``RTEMS_UNSATISFIED`` |
---|
256 | - unable to allocate message buffers |
---|
257 | * - ``RTEMS_MP_NOT_CONFIGURED`` |
---|
258 | - multiprocessing not configured |
---|
259 | * - ``RTEMS_TOO_MANY`` |
---|
260 | - too many global objects |
---|
261 | |
---|
262 | **DESCRIPTION:** |
---|
263 | |
---|
264 | This directive creates a message queue which resides on the local node with the |
---|
265 | user-defined name specified in name. For control and maintenance of the queue, |
---|
266 | RTEMS allocates and initializes a QCB. Memory is allocated from the RTEMS |
---|
267 | Workspace for the specified count of messages, each of max_message_size bytes |
---|
268 | in length. The RTEMS-assigned queue id, returned in id, is used to access the |
---|
269 | message queue. |
---|
270 | |
---|
271 | Specifying ``RTEMS_PRIORITY`` in attribute_set causes tasks waiting for a |
---|
272 | message to be serviced according to task priority. When ``RTEMS_FIFO`` is |
---|
273 | specified, waiting tasks are serviced in First In-First Out order. |
---|
274 | |
---|
275 | **NOTES:** |
---|
276 | |
---|
277 | This directive will not cause the calling task to be preempted. |
---|
278 | |
---|
279 | The following message queue attribute constants are defined by RTEMS: |
---|
280 | |
---|
281 | .. list-table:: |
---|
282 | :class: rtems-table |
---|
283 | |
---|
284 | * - ``RTEMS_FIFO`` |
---|
285 | - tasks wait by FIFO (default) |
---|
286 | * - ``RTEMS_PRIORITY`` |
---|
287 | - tasks wait by priority |
---|
288 | * - ``RTEMS_LOCAL`` |
---|
289 | - local message queue (default) |
---|
290 | * - ``RTEMS_GLOBAL`` |
---|
291 | - global message queue |
---|
292 | |
---|
293 | Message queues should not be made global unless remote tasks must interact with |
---|
294 | the created message queue. This is to avoid the system overhead incurred by |
---|
295 | the creation of a global message queue. When a global message queue is |
---|
296 | created, the message queue's name and id must be transmitted to every node in |
---|
297 | the system for insertion in the local copy of the global object table. |
---|
298 | |
---|
299 | For GLOBAL message queues, the maximum message size is effectively limited to |
---|
300 | the longest message which the MPCI is capable of transmitting. |
---|
301 | |
---|
302 | The total number of global objects, including message queues, is limited by the |
---|
303 | ``maximum_global_objects`` field in the configuration table. |
---|
304 | |
---|
305 | .. _rtems_message_queue_ident: |
---|
306 | |
---|
307 | MESSAGE_QUEUE_IDENT - Get ID of a queue |
---|
308 | --------------------------------------- |
---|
309 | .. index:: get ID of a message queue |
---|
310 | |
---|
311 | **CALLING SEQUENCE:** |
---|
312 | |
---|
313 | .. index:: rtems_message_queue_ident |
---|
314 | |
---|
315 | .. code-block:: c |
---|
316 | |
---|
317 | rtems_status_code rtems_message_queue_ident( |
---|
318 | rtems_name name, |
---|
319 | uint32_t node, |
---|
320 | rtems_id *id |
---|
321 | ); |
---|
322 | |
---|
323 | **DIRECTIVE STATUS CODES:** |
---|
324 | |
---|
325 | .. list-table:: |
---|
326 | :class: rtems-table |
---|
327 | |
---|
328 | * - ``RTEMS_SUCCESSFUL`` |
---|
329 | - queue identified successfully |
---|
330 | * - ``RTEMS_INVALID_ADDRESS`` |
---|
331 | - ``id`` is NULL |
---|
332 | * - ``RTEMS_INVALID_NAME`` |
---|
333 | - queue name not found |
---|
334 | * - ``RTEMS_INVALID_NODE`` |
---|
335 | - invalid node id |
---|
336 | |
---|
337 | **DESCRIPTION:** |
---|
338 | |
---|
339 | This directive obtains the queue id associated with the queue name specified in |
---|
340 | name. If the queue name is not unique, then the queue id will match one of the |
---|
341 | queues with that name. However, this queue id is not guaranteed to correspond |
---|
342 | to the desired queue. The queue id is used with other message related |
---|
343 | directives to access the message queue. |
---|
344 | |
---|
345 | **NOTES:** |
---|
346 | |
---|
347 | This directive will not cause the running task to be preempted. |
---|
348 | |
---|
349 | If node is ``RTEMS_SEARCH_ALL_NODES``, all nodes are searched with the local |
---|
350 | node being searched first. All other nodes are searched with the lowest |
---|
351 | numbered node searched first. |
---|
352 | |
---|
353 | If node is a valid node number which does not represent the local node, then |
---|
354 | only the message queues exported by the designated node are searched. |
---|
355 | |
---|
356 | This directive does not generate activity on remote nodes. It accesses only |
---|
357 | the local copy of the global object table. |
---|
358 | |
---|
359 | .. _rtems_message_queue_delete: |
---|
360 | |
---|
361 | MESSAGE_QUEUE_DELETE - Delete a queue |
---|
362 | ------------------------------------- |
---|
363 | .. index:: delete a message queue |
---|
364 | |
---|
365 | **CALLING SEQUENCE:** |
---|
366 | |
---|
367 | .. index:: rtems_message_queue_delete |
---|
368 | |
---|
369 | .. code-block:: c |
---|
370 | |
---|
371 | rtems_status_code rtems_message_queue_delete( |
---|
372 | rtems_id id |
---|
373 | ); |
---|
374 | |
---|
375 | **DIRECTIVE STATUS CODES:** |
---|
376 | |
---|
377 | .. list-table:: |
---|
378 | :class: rtems-table |
---|
379 | |
---|
380 | * - ``RTEMS_SUCCESSFUL`` |
---|
381 | - queue deleted successfully |
---|
382 | * - ``RTEMS_INVALID_ID`` |
---|
383 | - invalid queue id |
---|
384 | * - ``RTEMS_ILLEGAL_ON_REMOTE_OBJECT`` |
---|
385 | - cannot delete remote queue |
---|
386 | |
---|
387 | **DESCRIPTION:** |
---|
388 | |
---|
389 | This directive deletes the message queue specified by ``id``. As a result of |
---|
390 | this directive, all tasks blocked waiting to receive a message from this queue |
---|
391 | will be readied and returned a status code which indicates that the message |
---|
392 | queue was deleted. If no tasks are waiting, but the queue contains messages, |
---|
393 | then RTEMS returns these message buffers back to the system message buffer |
---|
394 | pool. The QCB for this queue as well as the memory for the message buffers is |
---|
395 | reclaimed by RTEMS. |
---|
396 | |
---|
397 | **NOTES:** |
---|
398 | |
---|
399 | The calling task will be preempted if its preemption mode is enabled and one or |
---|
400 | more local tasks with a higher priority than the calling task are waiting on |
---|
401 | the deleted queue. The calling task will NOT be preempted if the tasks that |
---|
402 | are waiting are remote tasks. |
---|
403 | |
---|
404 | The calling task does not have to be the task that created the queue, although |
---|
405 | the task and queue must reside on the same node. |
---|
406 | |
---|
407 | When the queue is deleted, any messages in the queue are returned to the free |
---|
408 | message buffer pool. Any information stored in those messages is lost. |
---|
409 | |
---|
410 | When a global message queue is deleted, the message queue id must be |
---|
411 | transmitted to every node in the system for deletion from the local copy of the |
---|
412 | global object table. |
---|
413 | |
---|
414 | Proxies, used to represent remote tasks, are reclaimed when the message queue |
---|
415 | is deleted. |
---|
416 | |
---|
417 | .. _rtems_message_queue_send: |
---|
418 | |
---|
419 | MESSAGE_QUEUE_SEND - Put message at rear of a queue |
---|
420 | --------------------------------------------------- |
---|
421 | .. index:: send message to a queue |
---|
422 | |
---|
423 | **CALLING SEQUENCE:** |
---|
424 | |
---|
425 | .. index:: rtems_message_queue_send |
---|
426 | |
---|
427 | .. code-block:: c |
---|
428 | |
---|
429 | rtems_status_code rtems_message_queue_send( |
---|
430 | rtems_id id, |
---|
431 | cons void *buffer, |
---|
432 | size_t size |
---|
433 | ); |
---|
434 | |
---|
435 | **DIRECTIVE STATUS CODES:** |
---|
436 | |
---|
437 | .. list-table:: |
---|
438 | :class: rtems-table |
---|
439 | |
---|
440 | * - ``RTEMS_SUCCESSFUL`` |
---|
441 | - message sent successfully |
---|
442 | * - ``RTEMS_INVALID_ID`` |
---|
443 | - invalid queue id |
---|
444 | * - ``RTEMS_INVALID_SIZE`` |
---|
445 | - invalid message size |
---|
446 | * - ``RTEMS_INVALID_ADDRESS`` |
---|
447 | - ``buffer`` is NULL |
---|
448 | * - ``RTEMS_UNSATISFIED`` |
---|
449 | - out of message buffers |
---|
450 | * - ``RTEMS_TOO_MANY`` |
---|
451 | - queue's limit has been reached |
---|
452 | |
---|
453 | **DESCRIPTION:** |
---|
454 | |
---|
455 | This directive sends the message buffer of size bytes in length to the queue |
---|
456 | specified by id. If a task is waiting at the queue, then the message is copied |
---|
457 | to the waiting task's buffer and the task is unblocked. If no tasks are waiting |
---|
458 | at the queue, then the message is copied to a message buffer which is obtained |
---|
459 | from this message queue's message buffer pool. The message buffer is then |
---|
460 | placed at the rear of the queue. |
---|
461 | |
---|
462 | **NOTES:** |
---|
463 | |
---|
464 | The calling task will be preempted if it has preemption enabled and a higher |
---|
465 | priority task is unblocked as the result of this directive. |
---|
466 | |
---|
467 | Sending a message to a global message queue which does not reside on the local |
---|
468 | node will generate a request to the remote node to post the message on the |
---|
469 | specified message queue. |
---|
470 | |
---|
471 | If the task to be unblocked resides on a different node from the message queue, |
---|
472 | then the message is forwarded to the appropriate node, the waiting task is |
---|
473 | unblocked, and the proxy used to represent the task is reclaimed. |
---|
474 | |
---|
475 | .. _rtems_message_queue_urgent: |
---|
476 | |
---|
477 | MESSAGE_QUEUE_URGENT - Put message at front of a queue |
---|
478 | ------------------------------------------------------ |
---|
479 | .. index:: put message at front of queue |
---|
480 | |
---|
481 | **CALLING SEQUENCE:** |
---|
482 | |
---|
483 | .. index:: rtems_message_queue_urgent |
---|
484 | |
---|
485 | .. code-block:: c |
---|
486 | |
---|
487 | rtems_status_code rtems_message_queue_urgent( |
---|
488 | rtems_id id, |
---|
489 | const void *buffer, |
---|
490 | size_t size |
---|
491 | ); |
---|
492 | |
---|
493 | **DIRECTIVE STATUS CODES:** |
---|
494 | |
---|
495 | .. list-table:: |
---|
496 | :class: rtems-table |
---|
497 | |
---|
498 | * - ``RTEMS_SUCCESSFUL`` |
---|
499 | - message sent successfully |
---|
500 | * - ``RTEMS_INVALID_ID`` |
---|
501 | - invalid queue id |
---|
502 | * - ``RTEMS_INVALID_SIZE`` |
---|
503 | - invalid message size |
---|
504 | * - ``RTEMS_INVALID_ADDRESS`` |
---|
505 | - ``buffer`` is NULL |
---|
506 | * - ``RTEMS_UNSATISFIED`` |
---|
507 | - out of message buffers |
---|
508 | * - ``RTEMS_TOO_MANY`` |
---|
509 | - queue's limit has been reached |
---|
510 | |
---|
511 | **DESCRIPTION:** |
---|
512 | |
---|
513 | This directive sends the message buffer of size bytes in length to the queue |
---|
514 | specified by id. If a task is waiting on the queue, then the message is copied |
---|
515 | to the task's buffer and the task is unblocked. If no tasks are waiting on the |
---|
516 | queue, then the message is copied to a message buffer which is obtained from |
---|
517 | this message queue's message buffer pool. The message buffer is then placed at |
---|
518 | the front of the queue. |
---|
519 | |
---|
520 | **NOTES:** |
---|
521 | |
---|
522 | The calling task will be preempted if it has preemption enabled and a higher |
---|
523 | priority task is unblocked as the result of this directive. |
---|
524 | |
---|
525 | Sending a message to a global message queue which does not reside on the local |
---|
526 | node will generate a request telling the remote node to post the message on the |
---|
527 | specified message queue. |
---|
528 | |
---|
529 | If the task to be unblocked resides on a different node from the message queue, |
---|
530 | then the message is forwarded to the appropriate node, the waiting task is |
---|
531 | unblocked, and the proxy used to represent the task is reclaimed. |
---|
532 | |
---|
533 | .. _rtems_message_queue_broadcast: |
---|
534 | |
---|
535 | MESSAGE_QUEUE_BROADCAST - Broadcast N messages to a queue |
---|
536 | --------------------------------------------------------- |
---|
537 | .. index:: broadcast message to a queue |
---|
538 | |
---|
539 | **CALLING SEQUENCE:** |
---|
540 | |
---|
541 | .. index:: rtems_message_queue_broadcast |
---|
542 | |
---|
543 | .. code-block:: c |
---|
544 | |
---|
545 | rtems_status_code rtems_message_queue_broadcast( |
---|
546 | rtems_id id, |
---|
547 | const void *buffer, |
---|
548 | size_t size, |
---|
549 | uint32_t *count |
---|
550 | ); |
---|
551 | |
---|
552 | **DIRECTIVE STATUS CODES:** |
---|
553 | |
---|
554 | .. list-table:: |
---|
555 | :class: rtems-table |
---|
556 | |
---|
557 | * - ``RTEMS_SUCCESSFUL`` |
---|
558 | - message broadcasted successfully |
---|
559 | * - ``RTEMS_INVALID_ID`` |
---|
560 | - invalid queue id |
---|
561 | * - ``RTEMS_INVALID_ADDRESS`` |
---|
562 | - ``buffer`` is NULL |
---|
563 | * - ``RTEMS_INVALID_ADDRESS`` |
---|
564 | - ``count`` is NULL |
---|
565 | * - ``RTEMS_INVALID_SIZE`` |
---|
566 | - invalid message size |
---|
567 | |
---|
568 | **DESCRIPTION:** |
---|
569 | |
---|
570 | This directive causes all tasks that are waiting at the queue specified by id |
---|
571 | to be unblocked and sent the message contained in buffer. Before a task is |
---|
572 | unblocked, the message buffer of size byes in length is copied to that task's |
---|
573 | message buffer. The number of tasks that were unblocked is returned in count. |
---|
574 | |
---|
575 | **NOTES:** |
---|
576 | |
---|
577 | The calling task will be preempted if it has preemption enabled and a higher |
---|
578 | priority task is unblocked as the result of this directive. |
---|
579 | |
---|
580 | The execution time of this directive is directly related to the number of tasks |
---|
581 | waiting on the message queue, although it is more efficient than the equivalent |
---|
582 | number of invocations of ``rtems_message_queue_send``. |
---|
583 | |
---|
584 | Broadcasting a message to a global message queue which does not reside on the |
---|
585 | local node will generate a request telling the remote node to broadcast the |
---|
586 | message to the specified message queue. |
---|
587 | |
---|
588 | When a task is unblocked which resides on a different node from the message |
---|
589 | queue, a copy of the message is forwarded to the appropriate node, the waiting |
---|
590 | task is unblocked, and the proxy used to represent the task is reclaimed. |
---|
591 | |
---|
592 | .. _rtems_message_queue_receive: |
---|
593 | |
---|
594 | MESSAGE_QUEUE_RECEIVE - Receive message from a queue |
---|
595 | ---------------------------------------------------- |
---|
596 | .. index:: receive message from a queue |
---|
597 | |
---|
598 | **CALLING SEQUENCE:** |
---|
599 | |
---|
600 | .. index:: rtems_message_queue_receive |
---|
601 | |
---|
602 | .. code-block:: c |
---|
603 | |
---|
604 | rtems_status_code rtems_message_queue_receive( |
---|
605 | rtems_id id, |
---|
606 | void *buffer, |
---|
607 | size_t *size, |
---|
608 | rtems_option option_set, |
---|
609 | rtems_interval timeout |
---|
610 | ); |
---|
611 | |
---|
612 | **DIRECTIVE STATUS CODES:** |
---|
613 | |
---|
614 | .. list-table:: |
---|
615 | :class: rtems-table |
---|
616 | |
---|
617 | * - ``RTEMS_SUCCESSFUL`` |
---|
618 | - message received successfully |
---|
619 | * - ``RTEMS_INVALID_ID`` |
---|
620 | - invalid queue id |
---|
621 | * - ``RTEMS_INVALID_ADDRESS`` |
---|
622 | - ``buffer`` is NULL |
---|
623 | * - ``RTEMS_INVALID_ADDRESS`` |
---|
624 | - ``size`` is NULL |
---|
625 | * - ``RTEMS_UNSATISFIED`` |
---|
626 | - queue is empty |
---|
627 | * - ``RTEMS_TIMEOUT`` |
---|
628 | - timed out waiting for message |
---|
629 | * - ``RTEMS_OBJECT_WAS_DELETED`` |
---|
630 | - queue deleted while waiting |
---|
631 | |
---|
632 | **DESCRIPTION:** |
---|
633 | |
---|
634 | This directive receives a message from the message queue specified in id. The |
---|
635 | ``RTEMS_WAIT`` and ``RTEMS_NO_WAIT`` options of the options parameter allow the |
---|
636 | calling task to specify whether to wait for a message to become available or |
---|
637 | return immediately. For either option, if there is at least one message in the |
---|
638 | queue, then it is copied to buffer, size is set to return the length of the |
---|
639 | message in bytes, and this directive returns immediately with a successful |
---|
640 | return code. The buffer has to be big enough to receive a message of the |
---|
641 | maximum length with respect to this message queue. |
---|
642 | |
---|
643 | If the calling task chooses to return immediately and the queue is empty, then |
---|
644 | a status code indicating this condition is returned. If the calling task |
---|
645 | chooses to wait at the message queue and the queue is empty, then the calling |
---|
646 | task is placed on the message wait queue and blocked. If the queue was created |
---|
647 | with the ``RTEMS_PRIORITY`` option specified, then the calling task is inserted |
---|
648 | into the wait queue according to its priority. But, if the queue was created |
---|
649 | with the ``RTEMS_FIFO`` option specified, then the calling task is placed at |
---|
650 | the rear of the wait queue. |
---|
651 | |
---|
652 | A task choosing to wait at the queue can optionally specify a timeout value in |
---|
653 | the timeout parameter. The timeout parameter specifies the maximum interval to |
---|
654 | wait before the calling task desires to be unblocked. If it is set to |
---|
655 | ``RTEMS_NO_TIMEOUT``, then the calling task will wait forever. |
---|
656 | |
---|
657 | **NOTES:** |
---|
658 | |
---|
659 | The following message receive option constants are defined by RTEMS: |
---|
660 | |
---|
661 | .. list-table:: |
---|
662 | :class: rtems-table |
---|
663 | |
---|
664 | * - ``RTEMS_WAIT`` |
---|
665 | - task will wait for a message (default) |
---|
666 | * - ``RTEMS_NO_WAIT`` |
---|
667 | - task should not wait |
---|
668 | |
---|
669 | Receiving a message from a global message queue which does not reside on the |
---|
670 | local node will generate a request to the remote node to obtain a message from |
---|
671 | the specified message queue. If no message is available and ``RTEMS_WAIT`` was |
---|
672 | specified, then the task must be blocked until a message is posted. A proxy is |
---|
673 | allocated on the remote node to represent the task until the message is posted. |
---|
674 | |
---|
675 | A clock tick is required to support the timeout functionality of this |
---|
676 | directive. |
---|
677 | |
---|
678 | .. _rtems_message_queue_get_number_pending: |
---|
679 | |
---|
680 | MESSAGE_QUEUE_GET_NUMBER_PENDING - Get number of messages pending on a queue |
---|
681 | ---------------------------------------------------------------------------- |
---|
682 | .. index:: get number of pending messages |
---|
683 | |
---|
684 | **CALLING SEQUENCE:** |
---|
685 | |
---|
686 | .. index:: rtems_message_queue_get_number_pending |
---|
687 | |
---|
688 | .. code-block:: c |
---|
689 | |
---|
690 | rtems_status_code rtems_message_queue_get_number_pending( |
---|
691 | rtems_id id, |
---|
692 | uint32_t *count |
---|
693 | ); |
---|
694 | |
---|
695 | **DIRECTIVE STATUS CODES:** |
---|
696 | |
---|
697 | .. list-table:: |
---|
698 | :class: rtems-table |
---|
699 | |
---|
700 | * - ``RTEMS_SUCCESSFUL`` |
---|
701 | - number of messages pending returned successfully |
---|
702 | * - ``RTEMS_INVALID_ADDRESS`` |
---|
703 | - ``count`` is NULL |
---|
704 | * - ``RTEMS_INVALID_ID`` |
---|
705 | - invalid queue id |
---|
706 | |
---|
707 | **DESCRIPTION:** |
---|
708 | |
---|
709 | This directive returns the number of messages pending on this message queue in |
---|
710 | count. If no messages are present on the queue, count is set to zero. |
---|
711 | |
---|
712 | **NOTES:** |
---|
713 | |
---|
714 | Getting the number of pending messages on a global message queue which does not |
---|
715 | reside on the local node will generate a request to the remote node to actually |
---|
716 | obtain the pending message count for the specified message queue. |
---|
717 | |
---|
718 | .. _rtems_message_queue_flush: |
---|
719 | |
---|
720 | MESSAGE_QUEUE_FLUSH - Flush all messages on a queue |
---|
721 | --------------------------------------------------- |
---|
722 | .. index:: flush messages on a queue |
---|
723 | |
---|
724 | **CALLING SEQUENCE:** |
---|
725 | |
---|
726 | .. index:: rtems_message_queue_flush |
---|
727 | |
---|
728 | .. code-block:: c |
---|
729 | |
---|
730 | rtems_status_code rtems_message_queue_flush( |
---|
731 | rtems_id id, |
---|
732 | uint32_t *count |
---|
733 | ); |
---|
734 | |
---|
735 | **DIRECTIVE STATUS CODES:** |
---|
736 | |
---|
737 | .. list-table:: |
---|
738 | :class: rtems-table |
---|
739 | |
---|
740 | * - ``RTEMS_SUCCESSFUL`` |
---|
741 | - message queue flushed successfully |
---|
742 | * - ``RTEMS_INVALID_ADDRESS`` |
---|
743 | - ``count`` is NULL |
---|
744 | * - ``RTEMS_INVALID_ID`` |
---|
745 | - invalid queue id |
---|
746 | |
---|
747 | **DESCRIPTION:** |
---|
748 | |
---|
749 | This directive removes all pending messages from the specified queue id. The |
---|
750 | number of messages removed is returned in count. If no messages are present on |
---|
751 | the queue, count is set to zero. |
---|
752 | |
---|
753 | **NOTES:** |
---|
754 | |
---|
755 | Flushing all messages on a global message queue which does not reside on the |
---|
756 | local node will generate a request to the remote node to actually flush the |
---|
757 | specified message queue. |
---|