source: rtems/cpukit/score/include/rtems/score/coremsg.h @ 484a769

4.104.114.95
Last change on this file since 484a769 was 484a769, checked in by Ralf Corsepius <ralf.corsepius@…>, on 09/04/08 at 17:46:39

Convert to "bool".

  • Property mode set to 100644
File size: 15.4 KB
Line 
1/**
2 *  @file  rtems/score/coremsg.h
3 *
4 *  This include file contains all the constants and structures associated
5 *  with the Message queue Handler.
6 */
7
8/*
9 *  COPYRIGHT (c) 1989-2007.
10 *  On-Line Applications Research Corporation (OAR).
11 *
12 *  The license and distribution terms for this file may be
13 *  found in the file LICENSE in this distribution or at
14 *  http://www.rtems.com/license/LICENSE.
15 *
16 *  $Id$
17 */
18
19#ifndef _RTEMS_SCORE_COREMSG_H
20#define _RTEMS_SCORE_COREMSG_H
21
22/**
23 *  @defgroup ScoreMessageQueue Message Queue Handler
24 *
25 *  This handler encapsulates functionality which provides the foundation
26 *  Message Queue services used in all of the APIs supported by RTEMS.
27 */
28/**@{*/
29
30#include <limits.h>
31#include <rtems/score/thread.h>
32#include <rtems/score/threadq.h>
33#include <rtems/score/priority.h>
34#include <rtems/score/watchdog.h>
35
36#ifdef __cplusplus
37extern "C" {
38#endif
39
40/**
41 *  @brief  Message Queue MP Callback Prototype
42 *
43 *  The following type defines the callout which the API provides
44 *  to support global/multiprocessor operations on message_queues.
45 */
46typedef void ( *CORE_message_queue_API_mp_support_callout )(
47                 Thread_Control *,
48                 Objects_Id
49             );
50
51/**
52 *  @brief Message Buffer Contents Management Structure
53 *
54 *  The following defines the data types needed to manipulate
55 *  the contents of message buffers.
56 *
57 *  @note  The buffer field is normally longer than a single uint32_t
58 *         but since messages are variable length we just make a ptr to 1.
59 */
60typedef struct {
61  /** This field is the size of this message. */
62  size_t      size;
63  /** This field contains the actual message. */
64  uint32_t    buffer[1];
65} CORE_message_queue_Buffer;
66
67/**
68 *  @brief Message Structure
69 *
70 *  The following records define the organization of a message
71 *  buffer.
72 */
73typedef struct {
74  /** This element allows this structure to be placed on chains. */
75  Chain_Node                 Node;
76  /** This field is the priority of this message. */
77  int                        priority;
78  /** This field points to the contents of the message. */
79  CORE_message_queue_Buffer  Contents;
80}   CORE_message_queue_Buffer_control;
81
82/**
83 *  @brief Message Queue Blocking Disciplines
84 *
85 *  This enumerated types defines the possible blocking disciplines
86 *  for a message queue.
87 */
88typedef enum {
89  /** This value indicates that pending messages are in FIFO order. */
90  CORE_MESSAGE_QUEUE_DISCIPLINES_FIFO,
91  /** This value indicates that pending messages are in priority order. */
92  CORE_MESSAGE_QUEUE_DISCIPLINES_PRIORITY
93}   CORE_message_queue_Disciplines;
94
95/**
96 *  @brief Message Priority for Appending
97 *
98 *  This is the priority constant used when appending messages onto
99 *  a message queue.
100 */
101#define  CORE_MESSAGE_QUEUE_SEND_REQUEST   INT_MAX
102
103/**
104 *  @brief Message Priority for Prepending
105 *
106 *  This is the priority constant used when prepending messages onto
107 *  a message queue.
108 */
109#define  CORE_MESSAGE_QUEUE_URGENT_REQUEST INT_MIN
110
111/**
112 *  @brief Message Insertion Operation Types
113 *
114 *  The following type details the modes in which a message
115 *  may be submitted to a message queue.  The message may be posted
116 *  in a send or urgent fashion.
117 *
118 *  @note  All other values are message priorities.  Numerically smaller
119 *         priorities indicate higher priority messages.
120 */
121typedef int CORE_message_queue_Submit_types;
122
123/**
124 *  @brief Core Message Queue Return Statuses
125 *
126 *  This enumerated type defines the possible set of Core Message
127 *  Queue handler return statuses.
128 */
129typedef enum {
130  /** This value indicates the operation completed sucessfully. */
131  CORE_MESSAGE_QUEUE_STATUS_SUCCESSFUL,
132  /** This value indicates that the message was too large for this queue. */
133  CORE_MESSAGE_QUEUE_STATUS_INVALID_SIZE,
134  /** This value indicates that there are too many messages pending. */
135  CORE_MESSAGE_QUEUE_STATUS_TOO_MANY,
136  /** This value indicates that a receive was unsuccessful. */
137  CORE_MESSAGE_QUEUE_STATUS_UNSATISFIED,
138  /** This value indicates that a blocking send was unsuccessful. */
139  CORE_MESSAGE_QUEUE_STATUS_UNSATISFIED_NOWAIT,
140  /** This value indicates that the message queue being blocked upon
141   *  was deleted while the thread was waiting.
142   */
143  CORE_MESSAGE_QUEUE_STATUS_WAS_DELETED,
144  /** This value indicates that the thread had to timeout while waiting
145   *  to receive a message because one did not become available.
146   */
147  CORE_MESSAGE_QUEUE_STATUS_TIMEOUT,
148  /** This value indicates that a blocking receive was unsuccessful. */
149  CORE_MESSAGE_QUEUE_STATUS_UNSATISFIED_WAIT
150}   CORE_message_queue_Status;
151
152/**
153 *  @brief Core Message Queue Last Status
154 *
155 *  This is the last status value.
156 */
157#define CORE_MESSAGE_QUEUE_STATUS_LAST CORE_MESSAGE_QUEUE_STATUS_UNSATISFIED_WAIT
158
159/**
160 *  @brief Message Queue Attributes Type
161 *
162 *  The following defines the control block used to manage the
163 *  attributes of each message queue.
164 */
165typedef struct {
166  /** This field specifies the order in which blocking tasks will be ordered. */
167  CORE_message_queue_Disciplines  discipline;
168}   CORE_message_queue_Attributes;
169
170/**
171 *  @brief Message Queue Notification Callback Prototype
172 *
173 *  The following defines the type for a Notification handler.  A notification
174 *  handler is invoked when the message queue makes a 0->1 transition on
175 *  pending messages.
176 */
177typedef void (*CORE_message_queue_Notify_Handler)( void * );
178
179/**
180 *  @brief Core Message Queue Control Structure
181 *
182 *  The following defines the control block used to manage each
183 *  Message Queue
184 */
185typedef struct {
186  /** This field is the Waiting Queue used to manage the set of tasks
187   *  which are blocked waiting to receive a message from this queue.
188   */
189  Thread_queue_Control               Wait_queue;
190  /** This element is the set of attributes which define this instance's
191   *  behavior.
192   */
193  CORE_message_queue_Attributes      Attributes;
194  /** This element is maximum number of messages which may be pending
195   *  at any given time.
196   */
197  uint32_t                           maximum_pending_messages;
198  /** This element is the number of messages which are currently pending.
199   */
200  uint32_t                           number_of_pending_messages;
201  /** This is the size in bytes of the largest message which may be
202   *  sent via this queue.
203   */
204  size_t                             maximum_message_size;
205  /** This chain is the set of pending messages.  It may be ordered by
206   *  message priority or in FIFO order.
207   */
208  Chain_Control                      Pending_messages;
209  /** This is the address of the memory allocated for message buffers.
210   *  It is allocated are part of message queue initialization and freed
211   *  as part of destroying it.
212   */
213  CORE_message_queue_Buffer         *message_buffers;
214  /** This is the routine invoked when the message queue transitions
215   *  from zero (0) messages pending to one (1) message pending.
216   */
217  CORE_message_queue_Notify_Handler  notify_handler;
218  /** This field is the argument passed to the @ref notify_argument. */
219  void                              *notify_argument;
220  /** This chain is the set of inactive messages.  A message is inactive
221   *  when it does not contain a pending message.
222   */
223  Chain_Control                      Inactive_messages;
224}   CORE_message_queue_Control;
225
226/**
227 *  @brief Initialize a Message Queue
228 *
229 *  This routine initializes @a the_message_queue based on the parameters passed.
230 *
231 *  @param[in] the_message_queue points to the message queue to initialize
232 *  @param[in] the_message_queue_attributes points to the attributes that
233 *         will be used with this message queue instance
234 *  @param[in] maximum_pending_messages is the maximum number of messages
235 *         that will be allowed to pend at any given time
236 *  @param[in] maximum_message_size is the size of largest message that
237 *         may be sent to this message queue instance
238 *
239 *  @return TRUE if the message queue can be initialized.  In general,
240 *         FALSE will only be returned if memory for the pending
241 *         messages cannot be allocated.
242 */
243bool _CORE_message_queue_Initialize(
244  CORE_message_queue_Control    *the_message_queue,
245  CORE_message_queue_Attributes *the_message_queue_attributes,
246  uint32_t                       maximum_pending_messages,
247  size_t                         maximum_message_size
248);
249
250/**
251 *  @brief Close a Message Queue
252 *
253 *  This function closes a message by returning all allocated space and
254 *  flushing @a the_message_queue's task wait queue.
255 *
256 *  @param[in] the_message_queue points to the message queue to close
257 *  @param[in] remote_extract_callout is the routine to call for each thread
258 *         that is extracted from the set of waiting threads
259 *  @param[in] status is the status that each waiting thread will return
260 *         from it's blocking service
261 */
262void _CORE_message_queue_Close(
263  CORE_message_queue_Control *the_message_queue,
264  Thread_queue_Flush_callout  remote_extract_callout,
265  uint32_t                    status
266);
267
268/**
269 *  @brief Flush Pending Messages
270 *
271 *  This function flushes @a the_message_queue's pending message queue.  The
272 *  number of messages flushed from the queue is returned.
273 *
274 *  @param[in] the_message_queue points to the message queue to flush
275 *
276 *  @return This method returns the number of message pending messages flushed.
277 */
278uint32_t   _CORE_message_queue_Flush(
279  CORE_message_queue_Control *the_message_queue
280);
281
282/**
283 *  @brief Flush Messages Support Routine
284 *
285 *  This routine flushes all outstanding messages and returns
286 *  them to the inactive message chain.
287 *
288 *  @param[in] the_message_queue points to the message queue to flush
289 *
290 *  @return This method returns the number of message pending messages flushed.
291 */
292uint32_t   _CORE_message_queue_Flush_support(
293  CORE_message_queue_Control *the_message_queue
294);
295
296/**
297 *  @brief Flush Waiting Threads.
298 *
299 *  This function flushes the threads which are blocked on
300 *  @a the_message_queue's pending message queue.  They are
301 *  unblocked whether blocked sending or receiving.
302 *
303 *  @param[in] the_message_queue points to the message queue to flush
304 */
305void _CORE_message_queue_Flush_waiting_threads(
306  CORE_message_queue_Control *the_message_queue
307);
308
309/**
310 *  @brief Broadcast a Message to the Message Queue
311 *
312 *  This function sends a message for every thread waiting on the queue and
313 *  returns the number of threads made ready by the message.
314 *
315 *  @param[in] the_message_queue points to the message queue
316 *  @param[in] buffer is the starting address of the message to broadcast
317 *  @param[in] size is the size of the message being broadcast
318 *  @param[in] id is the RTEMS object Id associated with this message queue.
319 *         It is used when unblocking a remote thread.
320 *  @param[in] api_message_queue_mp_support is the routine to invoke if
321 *         a thread that is unblocked is actually a remote thread.
322 *  @param[out] count points to the variable that will contain the
323 *         number of tasks that are sent this message
324 *  @return @a *count will contain the number of messages sent
325 *  @return indication of the successful completion or reason for failure
326 */
327CORE_message_queue_Status _CORE_message_queue_Broadcast(
328  CORE_message_queue_Control                *the_message_queue,
329  const void                                *buffer,
330  size_t                                     size,
331  Objects_Id                                 id,
332  CORE_message_queue_API_mp_support_callout  api_message_queue_mp_support,
333  uint32_t                                  *count
334);
335
336/**
337 *  @brief Submit a Message to the Message Queue
338 *
339 *  This routine implements the send and urgent message functions. It
340 *  processes a message that is to be submitted to the designated
341 *  message queue.  The message will either be processed as a
342 *  send message which it will be inserted at the rear of the queue
343 *  or it will be processed as an urgent message which will be inserted
344 *  at the front of the queue.
345 *
346 *  @param[in] the_message_queue points to the message queue
347 *  @param[in] buffer is the starting address of the message to send
348 *  @param[in] size is the size of the message being send
349 *  @param[in] id is the RTEMS object Id associated with this message queue.
350 *         It is used when unblocking a remote thread.
351 *  @param[in] api_message_queue_mp_support is the routine to invoke if
352 *         a thread that is unblocked is actually a remote thread.
353 *  @param[in] submit_type determines whether the message is prepended,
354 *         appended, or enqueued in priority order.
355 *  @param[in] wait indicates whether the calling thread is willing to block
356 *         if the message queue is full.
357 *  @param[in] timeout is the maximum number of clock ticks that the calling
358 *         thread is willing to block if the message queue is full.
359 *  @return indication of the successful completion or reason for failure
360 */
361CORE_message_queue_Status _CORE_message_queue_Submit(
362  CORE_message_queue_Control                *the_message_queue,
363  const void                                *buffer,
364  size_t                                     size,
365  Objects_Id                                 id,
366  CORE_message_queue_API_mp_support_callout  api_message_queue_mp_support,
367  CORE_message_queue_Submit_types            submit_type,
368  bool                                       wait,
369  Watchdog_Interval                          timeout
370);
371
372/**
373 *  @brief Size a Message from the Message Queue
374 *
375 *  This kernel routine dequeues a message, copies the message buffer to
376 *  a given destination buffer, and frees the message buffer to the
377 *  inactive message pool.  The thread will be blocked if wait is TRUE,
378 *  otherwise an error will be given to the thread if no messages are available.
379 *
380 *  @param[in] the_message_queue points to the message queue
381 *  @param[in] id is the RTEMS object Id associated with this message queue.
382 *         It is used when unblocking a remote thread.
383 *  @param[in] buffer is the starting address of the message buffer to
384 *         to be filled in with a message
385 *  @param[in] size is the size of the @a buffer and indicates the maximum
386 *         size message that the caller can receive.
387 *  @param[in] wait indicates whether the calling thread is willing to block
388 *         if the message queue is empty.
389 *  @param[in] timeout is the maximum number of clock ticks that the calling
390 *         thread is willing to block if the message queue is empty.
391 *
392 *  @return indication of the successful completion or reason for failure
393 *  @note Returns message priority via return are in TCB.
394 */
395void _CORE_message_queue_Seize(
396  CORE_message_queue_Control      *the_message_queue,
397  Objects_Id                       id,
398  void                            *buffer,
399  size_t                          *size_p,
400  bool                             wait,
401  Watchdog_Interval                timeout
402);
403
404/**
405 *  This kernel routine inserts the specified message into the
406 *  message queue.  It is assumed that the message has been filled
407 *  in before this routine is called.
408 *
409 *  @param[in] the_message_queue points to the message queue
410 *  @param[in] the_message is the message to enqueue
411 *  @param[in] submit_type determines whether the message is prepended,
412 *         appended, or enqueued in priority order.
413 */
414void _CORE_message_queue_Insert_message(
415  CORE_message_queue_Control        *the_message_queue,
416  CORE_message_queue_Buffer_control *the_message,
417  CORE_message_queue_Submit_types    submit_type
418);
419
420#ifndef __RTEMS_APPLICATION__
421#include <rtems/score/coremsg.inl>
422#endif
423
424#ifdef __cplusplus
425}
426#endif
427
428/**@}*/
429
430#endif
431/*  end of include file */
Note: See TracBrowser for help on using the repository browser.