Changeset 1c10acc in rtems


Ignore:
Timestamp:
11/17/99 14:56:18 (24 years ago)
Author:
Joel Sherrill <joel.sherrill@…>
Branches:
4.10, 4.11, 4.8, 4.9, 5, master
Children:
2eda969
Parents:
0545e15
Message:

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.

Files:
2 edited

Legend:

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

    r0545e15 r1c10acc  
    11/*
     2 *  ITRON 3.0 Mailbox Manager
     3 *
    24 *  The license and distribution terms for this file may be
    35 *  found in the file LICENSE in this distribution or at
     
    1012
    1113#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}
    1242
    1343/*   
     
    4878}
    4979
     80
    5081/*
    5182 *  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 *
    52108 */
    53109
     
    57113)
    58114{
    59   return E_OK;
     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 );
    60165}
    61166
    62167/*
    63168 *  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 *
    64183 */
    65184
     
    68187)
    69188{
    70   return E_OK;
    71 }
     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
    72214
    73215/*
     
    80222)
    81223{
    82   return E_OK;
     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) );
    83259}
    84260
     
    92268)
    93269{
    94   return E_OK;
     270  return trcv_msg( ppk_msg, mbxid, TMO_FEVR );
    95271}
    96272
     
    104280)
    105281{
    106   return E_OK;
     282  return trcv_msg( ppk_msg, mbxid, TMO_POL );
    107283}
    108284
     
    117293)
    118294{
    119   return E_OK;
     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 ) );
    120338}
    121339
     
    129347)
    130348{
    131   return E_OK;
    132 }
    133 
     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
  • cpukit/itron/src/mbox.c

    r0545e15 r1c10acc  
    11/*
     2 *  ITRON 3.0 Mailbox Manager
     3 *
    24 *  The license and distribution terms for this file may be
    35 *  found in the file LICENSE in this distribution or at
     
    1012
    1113#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}
    1242
    1343/*   
     
    4878}
    4979
     80
    5081/*
    5182 *  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 *
    52108 */
    53109
     
    57113)
    58114{
    59   return E_OK;
     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 );
    60165}
    61166
    62167/*
    63168 *  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 *
    64183 */
    65184
     
    68187)
    69188{
    70   return E_OK;
    71 }
     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
    72214
    73215/*
     
    80222)
    81223{
    82   return E_OK;
     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) );
    83259}
    84260
     
    92268)
    93269{
    94   return E_OK;
     270  return trcv_msg( ppk_msg, mbxid, TMO_FEVR );
    95271}
    96272
     
    104280)
    105281{
    106   return E_OK;
     282  return trcv_msg( ppk_msg, mbxid, TMO_POL );
    107283}
    108284
     
    117293)
    118294{
    119   return E_OK;
     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 ) );
    120338}
    121339
     
    129347)
    130348{
    131   return E_OK;
    132 }
    133 
     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 TracChangeset for help on using the changeset viewer.