Changeset 3c49a508 in rtems


Ignore:
Timestamp:
11/12/99 14:15:50 (23 years ago)
Author:
Joel Sherrill <joel.sherrill@…>
Branches:
4.10, 4.11, 4.8, 4.9, 5, master
Children:
5aa5560
Parents:
3ad17f5
Message:

Cleaned up style.

Files:
2 edited

Legend:

Unmodified
Added
Removed
  • c/src/exec/itron/src/msgbuffer.c

    r3ad17f5 r3c49a508  
    11/*
     2 *  ITRON Message Buffer Manager
     3 *
    24 *  The license and distribution terms for this file may be
    35 *  found in the file LICENSE in this distribution or at
     
    1315
    1416ER _ITRON_Message_buffer_Translate_core_message_buffer_return_code(
    15     CORE_message_queue_Status status)
    16 {
    17     switch (status) {
     17  CORE_message_queue_Status status
     18)
     19{
     20  switch (status) {
    1821    case CORE_MESSAGE_QUEUE_STATUS_SUCCESSFUL:
    19         return E_OK;
     22      return E_OK;
    2023    case CORE_MESSAGE_QUEUE_STATUS_TOO_MANY:
    21         return E_TMOUT;
     24      return E_TMOUT;
    2225    case CORE_MESSAGE_QUEUE_STATUS_INVALID_SIZE:
    23         return E_PAR;
     26      return E_PAR;
    2427    case CORE_MESSAGE_QUEUE_STATUS_UNSATISFIED_NOWAIT:
    25         return E_TMOUT;
     28      return E_TMOUT;
    2629    case CORE_MESSAGE_QUEUE_STATUS_TIMEOUT:
    27         return E_TMOUT;
     30      return E_TMOUT;
    2831    default:
    29         return E_ID;
    30     }
     32      return E_ID;
     33  }
    3134}
    3235
     
    4447
    4548void _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         );
     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;
    64103   
    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 
    77 ER 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;
     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 );
    101133   
    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);
     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);
    111232    }
    112233
    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    
    132234    /*
    133235     *  If multiprocessing were supported, this is where we would announce
     
    138240#endif
    139241
    140     _Thread_Enable_dispatch();
    141 
    142242    return E_OK;
    143243}
    144244
    145245/*
    146  *  del_mbf - Delete MessageBuffer
    147  */
    148 
    149 ER 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);
     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;
    157316   
    158     switch (location) {
     317  the_message_buffer = _ITRON_Message_buffer_Get(mbfid, &location);
     318  switch (location) {
    159319    case OBJECTS_REMOTE:
    160320    case OBJECTS_ERROR:           /* Multiprocessing not supported */
    161         return _ITRON_Message_buffer_Clarify_get_id_error(mbfid);
     321      return _ITRON_Message_buffer_Clarify_get_id_error(mbfid);
    162322
    163323    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);
     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
    169338    /*
    170339     *  If multiprocessing were supported, this is where we would announce
     
    174343#if defined(RTEMS_MULTIPROCESSING)
    175344#endif
    176         _Thread_Enable_dispatch();
    177         return E_OK;
     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;
    178382    }
    179    
     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();
    180405    return E_OK;
    181 }
    182 
    183 /*
    184  *  snd_mbf - Send Message to MessageBuffer
    185  */
    186 
    187 ER 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 
    200 ER 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 
    248 ER 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 
    262 ER 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 
    275 ER 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 
    288 ER 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 
    353 ER 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 }
     406  }   
     407  return E_OK;
     408}
  • cpukit/itron/src/msgbuffer.c

    r3ad17f5 r3c49a508  
    11/*
     2 *  ITRON Message Buffer Manager
     3 *
    24 *  The license and distribution terms for this file may be
    35 *  found in the file LICENSE in this distribution or at
     
    1315
    1416ER _ITRON_Message_buffer_Translate_core_message_buffer_return_code(
    15     CORE_message_queue_Status status)
    16 {
    17     switch (status) {
     17  CORE_message_queue_Status status
     18)
     19{
     20  switch (status) {
    1821    case CORE_MESSAGE_QUEUE_STATUS_SUCCESSFUL:
    19         return E_OK;
     22      return E_OK;
    2023    case CORE_MESSAGE_QUEUE_STATUS_TOO_MANY:
    21         return E_TMOUT;
     24      return E_TMOUT;
    2225    case CORE_MESSAGE_QUEUE_STATUS_INVALID_SIZE:
    23         return E_PAR;
     26      return E_PAR;
    2427    case CORE_MESSAGE_QUEUE_STATUS_UNSATISFIED_NOWAIT:
    25         return E_TMOUT;
     28      return E_TMOUT;
    2629    case CORE_MESSAGE_QUEUE_STATUS_TIMEOUT:
    27         return E_TMOUT;
     30      return E_TMOUT;
    2831    default:
    29         return E_ID;
    30     }
     32      return E_ID;
     33  }
    3134}
    3235
     
    4447
    4548void _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         );
     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;
    64103   
    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 
    77 ER 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;
     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 );
    101133   
    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);
     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);
    111232    }
    112233
    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    
    132234    /*
    133235     *  If multiprocessing were supported, this is where we would announce
     
    138240#endif
    139241
    140     _Thread_Enable_dispatch();
    141 
    142242    return E_OK;
    143243}
    144244
    145245/*
    146  *  del_mbf - Delete MessageBuffer
    147  */
    148 
    149 ER 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);
     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;
    157316   
    158     switch (location) {
     317  the_message_buffer = _ITRON_Message_buffer_Get(mbfid, &location);
     318  switch (location) {
    159319    case OBJECTS_REMOTE:
    160320    case OBJECTS_ERROR:           /* Multiprocessing not supported */
    161         return _ITRON_Message_buffer_Clarify_get_id_error(mbfid);
     321      return _ITRON_Message_buffer_Clarify_get_id_error(mbfid);
    162322
    163323    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);
     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
    169338    /*
    170339     *  If multiprocessing were supported, this is where we would announce
     
    174343#if defined(RTEMS_MULTIPROCESSING)
    175344#endif
    176         _Thread_Enable_dispatch();
    177         return E_OK;
     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;
    178382    }
    179    
     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();
    180405    return E_OK;
    181 }
    182 
    183 /*
    184  *  snd_mbf - Send Message to MessageBuffer
    185  */
    186 
    187 ER 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 
    200 ER 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 
    248 ER 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 
    262 ER 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 
    275 ER 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 
    288 ER 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 
    353 ER 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 }
     406  }   
     407  return E_OK;
     408}
Note: See TracChangeset for help on using the changeset viewer.