source: rtems/cpukit/itron/src/msgbuffer.c @ 3c49a508

4.104.114.84.95
Last change on this file since 3c49a508 was 3c49a508, checked in by Joel Sherrill <joel.sherrill@…>, on 11/12/99 at 14:15:50

Cleaned up style.

  • Property mode set to 100644
File size: 9.5 KB
Line 
1/*
2 *  ITRON Message Buffer 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/msgbuffer.h>
14#include <rtems/itron/task.h>
15
16ER _ITRON_Message_buffer_Translate_core_message_buffer_return_code(
17  CORE_message_queue_Status status
18)
19{
20  switch (status) {
21    case CORE_MESSAGE_QUEUE_STATUS_SUCCESSFUL:
22      return E_OK;
23    case CORE_MESSAGE_QUEUE_STATUS_TOO_MANY:
24      return E_TMOUT;
25    case CORE_MESSAGE_QUEUE_STATUS_INVALID_SIZE:
26      return E_PAR;
27    case CORE_MESSAGE_QUEUE_STATUS_UNSATISFIED_NOWAIT:
28      return E_TMOUT;
29    case CORE_MESSAGE_QUEUE_STATUS_TIMEOUT:
30      return E_TMOUT;
31    default:
32      return E_ID;
33  }
34}
35
36/*   
37 *  _ITRON_Message_buffer_Manager_initialization
38 * 
39 *  This routine initializes all message buffer manager related data
40 *  structures.
41 *
42 *  Input parameters:
43 *    maximum_message_buffers - maximum configured message buffers
44 *
45 *  Output parameters:  NONE
46 */
47
48void _ITRON_Message_buffer_Manager_initialization(
49  unsigned32 maximum_message_buffers
50)
51{
52  _Objects_Initialize_information(
53    &_ITRON_Message_buffer_Information, /* object information table */
54    OBJECTS_ITRON_MESSAGE_BUFFERS,      /* object class */
55    FALSE,                              /* TRUE if this is a
56                                           global object class */
57    maximum_message_buffers,            /* maximum objects of this class */
58    sizeof( ITRON_Message_buffer_Control ),  /* size of this
59                                                object's control
60                                                block */
61    FALSE,                         /* TRUE if names for this
62                                      object are strings */
63    RTEMS_MAXIMUM_NAME_LENGTH,     /* maximum length of each
64                                      object's name */
65    FALSE                          /* TRUE if this class is threads */
66  );
67 
68  /*
69   *  Register the MP Process Packet routine.
70   *
71   *  NOTE: No MP Support YET in RTEMS ITRON implementation.
72   */
73}
74
75/*
76 *  cre_mbf - Create MessageBuffer
77 */
78
79ER cre_mbf(
80  ID      mbfid,
81  T_CMBF *pk_cmbf
82)
83{
84  CORE_message_queue_Attributes   the_message_queue_attributes;
85  ITRON_Message_buffer_Control    *the_message_buffer;
86
87  /*
88   *  Bad pointer to the attributes structure
89   */
90
91  if ( !pk_cmbf )
92    return E_PAR;
93
94  /*
95   *  Bits were set that were note defined.
96   */
97
98  if (pk_cmbf->mbfatr & ~(TA_TPRI))
99    return E_RSATR;
100
101  if (pk_cmbf->bufsz < 0 || pk_cmbf->maxmsz < 0)
102    return E_PAR;
103   
104  if (pk_cmbf->bufsz < pk_cmbf->maxmsz)
105    return E_PAR;
106
107  _Thread_Disable_dispatch();             /* prevents deletion */
108
109  the_message_buffer = _ITRON_Message_buffer_Allocate(mbfid);
110  if ( !the_message_buffer ) {
111    _Thread_Enable_dispatch();
112    return _ITRON_Message_buffer_Clarify_allocation_id_error(mbfid);
113  }
114
115  if ( pk_cmbf->mbfatr & TA_TPRI )
116    the_message_queue_attributes.discipline =
117        CORE_MESSAGE_QUEUE_DISCIPLINES_PRIORITY;
118  else
119    the_message_queue_attributes.discipline =
120        CORE_MESSAGE_QUEUE_DISCIPLINES_FIFO;
121
122  _CORE_message_queue_Initialize(
123    &the_message_buffer->message_queue,
124    OBJECTS_ITRON_MESSAGE_BUFFERS,
125    &the_message_queue_attributes,
126    pk_cmbf->bufsz / pk_cmbf->maxmsz,
127    pk_cmbf->maxmsz,
128    NULL                           /* Multiprocessing not supported */
129  );
130
131  _ITRON_Objects_Open( &_ITRON_Message_buffer_Information,
132                       &the_message_buffer->Object );
133   
134  /*
135   *  If multiprocessing were supported, this is where we would announce
136   *  the existence of the semaphore to the rest of the system.
137   */
138
139#if defined(RTEMS_MULTIPROCESSING)
140#endif
141
142  _Thread_Enable_dispatch();
143
144  return E_OK;
145}
146
147/*
148 *  del_mbf - Delete MessageBuffer
149 */
150
151ER del_mbf(
152  ID mbfid
153)
154{
155  ITRON_Message_buffer_Control  *the_message_buffer;
156  Objects_Locations              location;
157
158  the_message_buffer = _ITRON_Message_buffer_Get(mbfid, &location);
159  switch (location) {
160    case OBJECTS_REMOTE:
161    case OBJECTS_ERROR:           /* Multiprocessing not supported */
162      return _ITRON_Message_buffer_Clarify_get_id_error(mbfid);
163
164    case OBJECTS_LOCAL:
165      _CORE_message_queue_Flush(&the_message_buffer->message_queue);
166      _ITRON_Objects_Close( &_ITRON_Message_buffer_Information,
167                            &the_message_buffer->Object);
168      _ITRON_Message_buffer_Free(the_message_buffer);
169
170      /*
171       *  If multiprocessing were supported, this is where we would announce
172       *  the existence of the semaphore to the rest of the system.
173       */
174
175#if defined(RTEMS_MULTIPROCESSING)
176#endif
177      _Thread_Enable_dispatch();
178      return E_OK;
179  }
180 
181  return E_OK;
182}
183
184/*
185 *  snd_mbf - Send Message to MessageBuffer
186 */
187
188ER snd_mbf(
189  ID  mbfid,
190  VP  msg,
191  INT msgsz
192)
193{
194    return E_OK;
195}
196
197/*
198 *  psnd_mbf - Poll and Send Message to MessageBuffer
199 */
200
201ER psnd_mbf(
202  ID  mbfid,
203  VP  msg,
204  INT msgsz
205)
206{
207  ITRON_Message_buffer_Control  *the_message_buffer;
208  Objects_Locations              location;
209  CORE_message_queue_Status      status;
210
211  if (msgsz <= 0 || !msg)
212    return E_PAR;
213   
214  the_message_buffer = _ITRON_Message_buffer_Get(mbfid, &location);
215  switch (location) {
216    case OBJECTS_REMOTE:
217    case OBJECTS_ERROR:           /* Multiprocessing not supported */
218      return _ITRON_Message_buffer_Clarify_get_id_error(mbfid);
219
220    case OBJECTS_LOCAL:
221      status = _CORE_message_queue_Submit(
222        &the_message_buffer->message_queue,
223        msg,
224        msgsz,
225        the_message_buffer->Object.id,
226        NULL,
227        CORE_MESSAGE_QUEUE_SEND_REQUEST
228      );
229      _Thread_Enable_dispatch();
230      return
231        _ITRON_Message_buffer_Translate_core_message_buffer_return_code(status);
232    }
233
234    /*
235     *  If multiprocessing were supported, this is where we would announce
236     *  the existence of the semaphore to the rest of the system.
237     */
238
239#if defined(RTEMS_MULTIPROCESSING)
240#endif
241
242    return E_OK;
243}
244
245/*
246 *  tsnd_mbf - Send Message to MessageBuffer with Timeout
247 */
248
249ER tsnd_mbf(
250  ID  mbfid,
251  VP  msg,
252  INT msgsz,
253  TMO tmout
254)
255{
256  return E_OK;
257}
258
259/*
260 *  rcv_mbf - Receive Message from MessageBuffer
261 */
262
263ER rcv_mbf(
264  VP   msg,
265  INT *p_msgsz,
266  ID   mbfid
267)
268{
269  return trcv_mbf(msg, p_msgsz, mbfid, TMO_FEVR);
270}
271
272/*
273 *  prcv_mbf - Poll and Receive Message from MessageBuffer
274 */
275
276ER prcv_mbf(
277  VP   msg,
278  INT *p_msgsz,
279  ID   mbfid
280)
281{
282  return trcv_mbf(msg, p_msgsz, mbfid, TMO_POL);
283}
284
285/*
286 *  trcv_mbf - Receive Message from MessageBuffer with Timeout
287 */
288
289ER trcv_mbf(
290  VP   msg,
291  INT *p_msgsz,
292  ID   mbfid,
293  TMO  tmout
294)
295{
296  ITRON_Message_buffer_Control  *the_message_buffer;
297  Objects_Locations              location;
298  CORE_message_queue_Status      status;
299  boolean                        wait;
300  Watchdog_Interval              interval;
301
302  interval = 0;
303  if (tmout == TMO_POL) {
304    wait = FALSE;
305  } else {
306    wait = TRUE;
307    if (tmout != TMO_FEVR)
308      interval = TOD_MILLISECONDS_TO_TICKS(tmout);
309  }
310
311  if (wait && _ITRON_Is_in_non_task_state() )
312    return E_CTX;
313
314  if (!p_msgsz || !msg || tmout <= -2)
315    return E_PAR;
316   
317  the_message_buffer = _ITRON_Message_buffer_Get(mbfid, &location);
318  switch (location) {
319    case OBJECTS_REMOTE:
320    case OBJECTS_ERROR:           /* Multiprocessing not supported */
321      return _ITRON_Message_buffer_Clarify_get_id_error(mbfid);
322
323    case OBJECTS_LOCAL:
324      _CORE_message_queue_Seize(
325          &the_message_buffer->message_queue,
326          the_message_buffer->Object.id,
327          msg,
328          p_msgsz,
329          wait,
330          interval
331      );
332      _Thread_Enable_dispatch();
333      status = (CORE_message_queue_Status)_Thread_Executing->Wait.return_code;
334      return
335        _ITRON_Message_buffer_Translate_core_message_buffer_return_code(status);
336    }
337
338    /*
339     *  If multiprocessing were supported, this is where we would announce
340     *  the existence of the semaphore to the rest of the system.
341     */
342
343#if defined(RTEMS_MULTIPROCESSING)
344#endif
345    return E_OK;
346}
347
348/*
349 *  ref_mbf - Reference MessageBuffer Status
350 */
351
352ER ref_mbf(
353  T_RMBF *pk_rmbf,
354  ID      mbfid
355)
356{
357  ITRON_Message_buffer_Control      *the_message_buffer;
358  Objects_Locations                  location;
359  CORE_message_queue_Control        *the_core_msgq;
360       
361  if ( !pk_rmbf )
362    return E_PAR;   /* XXX check this error code */
363
364  the_message_buffer = _ITRON_Message_buffer_Get( mbfid, &location );
365  switch ( location ) {   
366  case OBJECTS_REMOTE:               /* Multiprocessing not supported */
367  case OBJECTS_ERROR:
368    return _ITRON_Message_buffer_Clarify_get_id_error( mbfid );
369 
370  case OBJECTS_LOCAL:
371    the_core_msgq = &the_message_buffer->message_queue;
372
373    /*
374     *  Fill in the size of message to be sent
375     */
376
377    if (the_core_msgq->number_of_pending_messages == 0) {
378      pk_rmbf->msgsz = 0;
379    } else {
380      pk_rmbf->msgsz = ((CORE_message_queue_Buffer_control *)
381        the_core_msgq->Pending_messages.first)->Contents.size;
382    }
383       
384    /*
385     *  Fill in the size of free buffer
386     */
387
388    pk_rmbf->frbufsz =
389      (the_core_msgq->maximum_pending_messages -
390       the_core_msgq->number_of_pending_messages) *
391       the_core_msgq->maximum_message_size;
392
393
394    /*
395     *  Fill in whether or not there is a waiting task
396     */
397
398    if ( !_Thread_queue_First(&the_core_msgq->Wait_queue ) )
399       pk_rmbf->wtsk = FALSE;
400    else
401       pk_rmbf->wtsk =  TRUE;
402
403    pk_rmbf->stsk = FALSE;
404    _Thread_Enable_dispatch();
405    return E_OK;
406  }   
407  return E_OK;
408}
Note: See TracBrowser for help on using the repository browser.