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