source: rtems/c/src/exec/itron/src/mbox.c @ 1c10acc

4.104.114.84.9
Last change on this file since 1c10acc was 1c10acc, checked in by Joel Sherrill <joel.sherrill@…>, on Nov 17, 1999 at 2:56:18 PM

Update from Andrew D. McDowell? <amcdowel@…> with modifications
by Joel and Jennifer based on experience merging the other managers
and cleaning them up. No test code is available at this point.

  • Property mode set to 100644
File size: 9.2 KB
Line 
1/*
2 *  ITRON 3.0 Mailbox Manager
3 *
4 *  The license and distribution terms for this file may be
5 *  found in the file LICENSE in this distribution or at
6 *  http://www.OARcorp.com/rtems/license.html.
7 *
8 *  $Id$
9 */
10
11#include <itron.h>
12
13#include <rtems/itron/mbox.h>
14#include <rtems/itron/task.h>
15
16/*
17 *  _ITRON_Mailbox_Translate_core_message_queue_return_code
18 *
19 *  This routine translates a core message queue object status
20 *  into the appropriate ITRON status code.
21 */
22
23ER _ITRON_Mailbox_Translate_core_message_queue_return_code(
24  CORE_message_queue_Status status
25)
26{
27  switch (status) {
28    case CORE_MESSAGE_QUEUE_STATUS_SUCCESSFUL:
29      return E_OK;
30    case CORE_MESSAGE_QUEUE_STATUS_TOO_MANY:
31      return E_TMOUT;
32    case CORE_MESSAGE_QUEUE_STATUS_INVALID_SIZE:
33      return E_PAR;
34    case CORE_MESSAGE_QUEUE_STATUS_UNSATISFIED_NOWAIT:
35      return E_TMOUT;
36    case CORE_MESSAGE_QUEUE_STATUS_TIMEOUT:
37      return E_TMOUT;
38    default:
39      return E_ID;
40  }
41}
42
43/*   
44 *  _ITRON_Mailbox_Manager_initialization
45 * 
46 *  This routine initializes all mailboxes manager related data structures.
47 *
48 *  Input parameters:
49 *    maximum_mailboxes - maximum configured mailboxes
50 *
51 *  Output parameters:  NONE
52 */
53
54void _ITRON_Mailbox_Manager_initialization(
55  unsigned32 maximum_mailboxes
56) 
57{
58  _Objects_Initialize_information(
59    &_ITRON_Mailbox_Information,     /* object information table */
60    OBJECTS_ITRON_MAILBOXES,         /* object class */
61    FALSE,                           /* TRUE if this is a global */
62                                     /*   object class */
63    maximum_mailboxes,               /* maximum objects of this class */
64    sizeof( ITRON_Mailbox_Control ), /* size of this object's control block */
65    FALSE,                           /* TRUE if names for this object */
66                                     /*   are strings */
67    RTEMS_MAXIMUM_NAME_LENGTH,       /* maximum length of each object's */
68                                     /*   name */
69    FALSE                            /* TRUE if this class is threads */
70  );
71   
72  /*
73   *  Register the MP Process Packet routine.
74   *
75   *  NOTE: No MP Support YET in RTEMS ITRON implementation.
76   */
77 
78} 
79
80
81/*
82 *  cre_mbx - Create Mailbox
83 *
84 *      Creates a Mailbox according to the following spec:
85 *
86 * ------Parameters-------------------------
87 *  ID      mbxid   MailboxID
88 *  T_CMBX *pk_cmbx Packet to Create Mailbox
89 * -----------------------------------------
90 *   -*pk_cmbx members*-
91 *    VP                exinf   ExtendedInformation
92 *    ATR               mbxatr  MailboxAttributes
93 *                      (the use of the following information
94 *                        is implementation dependent)
95 *    INT               bufcnt  BufferMessageCount
96 *                      (CPU and/or implementation-dependent information
97 *                         may also be included)
98 *
99 * ----Return Parameters--------------------
100 *  ER      ercd    ErrorCode
101 * -----------------------------------------
102 *
103 *
104 * ----C Language Interface-----------------
105 *  ER ercd = cre_mbx ( ID mbxid, T_CMBX *pk_cmbx ) ;
106 * -----------------------------------------
107 *
108 */
109
110ER cre_mbx(
111  ID      mbxid,
112  T_CMBX *pk_cmbx
113)
114{
115  register ITRON_Mailbox_Control *the_mailbox;
116  CORE_message_queue_Attributes   the_mailbox_attributes;
117
118  if ( !pk_cmbx )
119    return E_PAR;
120
121  if ((pk_cmbx->mbxatr & (TA_TPRI | TA_MPRI)) != 0 )
122    return E_RSATR;
123
124  _Thread_Disable_dispatch();              /* protects object pointer */
125
126  the_mailbox = _ITRON_Mailbox_Allocate( mbxid );
127  if ( !the_mailbox ) {
128    _Thread_Enable_dispatch();
129    return _ITRON_Mailbox_Clarify_allocation_id_error( mbxid );
130  }
131
132  the_mailbox->count = pk_cmbx->bufcnt;
133  if (pk_cmbx->mbxatr & TA_MPRI)
134    the_mailbox->do_message_priority = TRUE;
135  else
136    the_mailbox->do_message_priority = FALSE;
137
138  if (pk_cmbx->mbxatr & TA_TPRI)
139    the_mailbox_attributes.discipline = CORE_MESSAGE_QUEUE_DISCIPLINES_PRIORITY;
140  else
141    the_mailbox_attributes.discipline = CORE_MESSAGE_QUEUE_DISCIPLINES_FIFO;
142
143  if ( !_CORE_message_queue_Initialize(
144           &the_mailbox->message_queue,
145           OBJECTS_ITRON_MAILBOXES,
146           &the_mailbox_attributes,
147           the_mailbox->count,
148           sizeof(T_MSG *),
149           NULL ) ) {                      /* Multiprocessing not supported */
150    _ITRON_Mailbox_Free(the_mailbox);
151    _ITRON_return_errorno( E_OBJ );
152  }
153
154  _ITRON_Objects_Open( &_ITRON_Mailbox_Information, &the_mailbox->Object );
155
156  /*
157   *  If multiprocessing were supported, this is where we would announce
158   *  the existence of the semaphore to the rest of the system.
159   */
160
161#if defined(RTEMS_MULTIPROCESSING)
162#endif
163
164  _ITRON_return_errorno( E_OK );
165}
166
167/*
168 *  del_mbx - Delete Mailbox
169 *
170 *
171 * ------Parameters--------------
172 * ID mbxid      The Mailbox's ID
173 * ------------------------------
174 *
175 * -----Return Parameters-------
176 * ER ercd       Itron Error Code
177 * -----------------------------
178 *
179 * -----C Language Interface----
180 * ER ercd = del_mbx(ID mbxid);
181 * -----------------------------
182 *
183 */
184
185ER del_mbx(
186  ID mbxid
187)
188{
189  register ITRON_Mailbox_Control *the_mailbox;
190  Objects_Locations               location;
191
192  the_mailbox= _ITRON_Mailbox_Get( mbxid, &location );
193  switch ( location ) {
194    case OBJECTS_ERROR:
195    case OBJECTS_REMOTE:
196      return _ITRON_Mailbox_Clarify_get_id_error( mbxid );
197
198    case OBJECTS_LOCAL:
199      _Objects_Close( &_ITRON_Mailbox_Information, &the_mailbox->Object );
200
201      _CORE_message_queue_Close(
202        &the_mailbox->message_queue,
203        NULL,                      /* Multiprocessing not supported */
204        CORE_MESSAGE_QUEUE_STATUS_WAS_DELETED
205      );
206
207      _ITRON_Mailbox_Free(the_mailbox);
208      break;
209  }
210
211  _ITRON_return_errorno( E_OK );
212}
213
214
215/*
216 *  snd_msg - Send Message to Mailbox
217 */
218
219ER snd_msg(
220  ID     mbxid,
221  T_MSG *pk_msg
222)
223{
224  register ITRON_Mailbox_Control *the_mailbox;
225  Objects_Locations                location;
226  CORE_message_queue_Status        status = E_OK;
227  unsigned32                       message_priority;
228  void                            *message_contents;
229
230  if ( !pk_msg )
231    return E_PAR;
232
233  the_mailbox = _ITRON_Mailbox_Get( mbxid, &location );
234  switch ( location ) {
235    case OBJECTS_REMOTE:
236    case OBJECTS_ERROR:
237      return _ITRON_Mailbox_Clarify_get_id_error( mbxid );
238
239    case OBJECTS_LOCAL:
240      if ( the_mailbox->do_message_priority )
241        message_priority = pk_msg->msgpri;
242      else
243        message_priority = CORE_MESSAGE_QUEUE_SEND_REQUEST;
244
245      message_contents = pk_msg;
246      status = _CORE_message_queue_Submit(
247        &the_mailbox->message_queue,
248        &message_contents,
249        sizeof(T_MSG *),
250        the_mailbox->Object.id,
251        NULL,          /* multiprocessing not supported */
252        message_priority
253     );
254     break;
255  }
256
257  _ITRON_return_errorno( 
258     _ITRON_Mailbox_Translate_core_message_queue_return_code(status) );
259}
260
261/*
262 *  rcv_msg - Receive Message from Mailbox
263 */
264
265ER rcv_msg(
266  T_MSG **ppk_msg,
267  ID      mbxid
268)
269{
270  return trcv_msg( ppk_msg, mbxid, TMO_FEVR );
271}
272
273/*
274 *  prcv_msg - Poll and Receive Message from Mailbox
275 */
276
277ER prcv_msg(
278  T_MSG **ppk_msg,
279  ID      mbxid
280)
281{
282  return trcv_msg( ppk_msg, mbxid, TMO_POL );
283}
284
285/*
286 *  trcv_msg - Receive Message from Mailbox with Timeout
287 */
288
289ER trcv_msg(
290  T_MSG **ppk_msg,
291  ID      mbxid,
292  TMO     tmout
293)
294{
295  register ITRON_Mailbox_Control *the_mailbox;
296  Watchdog_Interval               interval;
297  boolean                         wait;
298  Objects_Locations               location;
299  unsigned32                      size;
300
301  if (!ppk_msg)
302    return E_PAR;
303
304  interval = 0;
305  if ( tmout == TMO_POL ) {
306    wait = FALSE;
307  } else {
308    wait = TRUE;
309    if ( tmout != TMO_FEVR )
310      interval = TOD_MILLISECONDS_TO_TICKS(tmout);
311  }
312
313  if ( wait && _ITRON_Is_in_non_task_state() )
314    return E_CTX;
315
316  the_mailbox = _ITRON_Mailbox_Get( mbxid, &location );
317  switch ( location ) {
318    case OBJECTS_REMOTE:
319    case OBJECTS_ERROR:
320      return _ITRON_Mailbox_Clarify_get_id_error( mbxid );
321
322    case OBJECTS_LOCAL:
323
324      _CORE_message_queue_Seize(
325        &the_mailbox->message_queue,
326        the_mailbox->Object.id,
327        ppk_msg,
328        &size,
329        wait,
330        interval
331      );
332      break;
333  }
334
335  _ITRON_return_errorno( 
336    _ITRON_Mailbox_Translate_core_message_queue_return_code(
337        _Thread_Executing->Wait.return_code ) );
338}
339
340/*
341 *  ref_mbx - Reference Mailbox Status
342 */
343
344ER ref_mbx(
345  T_RMBX *pk_rmbx,
346  ID      mbxid
347)
348{
349  register ITRON_Mailbox_Control *the_mailbox;
350  Objects_Locations               location;
351  Chain_Control                  *pending;
352
353  if ( !pk_rmbx )
354    return E_PAR;
355
356  the_mailbox = _ITRON_Mailbox_Get( mbxid, &location );
357  switch ( location ) {
358    case OBJECTS_REMOTE:
359    case OBJECTS_ERROR:
360      return _ITRON_Mailbox_Clarify_get_id_error( mbxid );
361
362    case OBJECTS_LOCAL:
363
364      pending = &the_mailbox->message_queue.Pending_messages;
365      if ( _Chain_Is_empty( pending ) )
366        pk_rmbx->pk_msg = NULL;
367      else 
368        pk_rmbx->pk_msg = (T_MSG *) pending->first;
369
370      /*
371       *  Fill in whether or not there is a waiting task
372       */
373
374      if ( !_Thread_queue_First( &the_mailbox->message_queue.Wait_queue ) )
375        pk_rmbx->wtsk = FALSE;
376      else
377        pk_rmbx->wtsk = TRUE;
378
379      break;
380  }
381  _ITRON_return_errorno( E_OK );
382}
383
Note: See TracBrowser for help on using the repository browser.