source: rtems/c/src/exec/itron/src/msgbuffer.c @ ad502d18

4.104.114.84.95
Last change on this file since ad502d18 was 352c9b2, checked in by Joel Sherrill <joel.sherrill@…>, on 11/09/99 at 22:07:23

This patch adds the basic framework for the ITRON 3.0 API implementation
for RTEMS.

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