Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:24:22

0001 /* SPDX-License-Identifier: BSD-2-Clause */
0002 
0003 /**
0004  * @file
0005  *
0006  * @ingroup RTEMSImplClassicEventMP
0007  *
0008  * @brief This source file contains the implementation to support the Event
0009  *   Manager in multiprocessing (MP) configurations.
0010  */
0011 
0012 /*
0013  *  COPYRIGHT (c) 1989-2008.
0014  *  On-Line Applications Research Corporation (OAR).
0015  *
0016  * Redistribution and use in source and binary forms, with or without
0017  * modification, are permitted provided that the following conditions
0018  * are met:
0019  * 1. Redistributions of source code must retain the above copyright
0020  *    notice, this list of conditions and the following disclaimer.
0021  * 2. Redistributions in binary form must reproduce the above copyright
0022  *    notice, this list of conditions and the following disclaimer in the
0023  *    documentation and/or other materials provided with the distribution.
0024  *
0025  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0026  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0027  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0028  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
0029  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0030  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0031  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0032  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0033  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0034  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
0035  * POSSIBILITY OF SUCH DAMAGE.
0036  */
0037 
0038 #ifdef HAVE_CONFIG_H
0039 #include "config.h"
0040 #endif
0041 
0042 #include <rtems/rtems/eventimpl.h>
0043 #include <rtems/rtems/statusimpl.h>
0044 #include <rtems/score/threadimpl.h>
0045 #include <rtems/score/statesimpl.h>
0046 
0047 /**
0048  *  The following enumerated type defines the list of
0049  *  remote event operations.
0050  */
0051 typedef enum {
0052   EVENT_MP_SEND_REQUEST  =  0,
0053   EVENT_MP_SEND_RESPONSE =  1
0054 }   Event_MP_Remote_operations;
0055 
0056 /**
0057  *  The following data structure defines the packet used to perform
0058  *  remote event operations.
0059  */
0060 typedef struct {
0061   rtems_packet_prefix         Prefix;
0062   Event_MP_Remote_operations  operation;
0063   rtems_event_set             event_in;
0064 }   Event_MP_Packet;
0065 
0066 RTEMS_STATIC_ASSERT(
0067   sizeof(Event_MP_Packet) <= MP_PACKET_MINIMUM_PACKET_SIZE,
0068   Event_MP_Packet
0069 );
0070 
0071 static Event_MP_Packet *_Event_MP_Get_packet( Objects_Id id )
0072 {
0073   if ( !_Thread_MP_Is_remote( id ) ) {
0074     return NULL;
0075   }
0076 
0077   return (Event_MP_Packet *) _MPCI_Get_packet();
0078 }
0079 
0080 rtems_status_code _Event_MP_Send(
0081   rtems_id        id,
0082   rtems_event_set event_in
0083 )
0084 {
0085   Event_MP_Packet *the_packet;
0086   Status_Control   status;
0087 
0088   the_packet = _Event_MP_Get_packet( id );
0089   if ( the_packet == NULL ) {
0090     return RTEMS_INVALID_ID;
0091   }
0092 
0093   the_packet->Prefix.the_class  = MP_PACKET_EVENT;
0094   the_packet->Prefix.length     = sizeof ( *the_packet );
0095   the_packet->Prefix.to_convert = sizeof ( *the_packet );
0096   the_packet->operation         = EVENT_MP_SEND_REQUEST;
0097   the_packet->Prefix.id         = id;
0098   the_packet->event_in          = event_in;
0099 
0100   status = _MPCI_Send_request_packet(
0101     _Objects_Get_node( id ),
0102     &the_packet->Prefix,
0103     STATES_READY
0104   );
0105   return _Status_Get( status );
0106 }
0107 
0108 static void _Event_MP_Send_response_packet (
0109   Event_MP_Remote_operations  operation,
0110   Thread_Control             *the_thread
0111 )
0112 {
0113   Event_MP_Packet *the_packet;
0114 
0115   switch ( operation ) {
0116 
0117     case EVENT_MP_SEND_RESPONSE:
0118 
0119       the_packet = ( Event_MP_Packet *) the_thread->receive_packet;
0120 
0121 /*
0122  *  The packet being returned already contains the class, length, and
0123  *  to_convert fields, therefore they are not set in this routine.
0124  */
0125       the_packet->operation = operation;
0126       the_packet->Prefix.id = the_packet->Prefix.source_tid;
0127 
0128       _MPCI_Send_response_packet(
0129         _Objects_Get_node( the_packet->Prefix.source_tid ),
0130         &the_packet->Prefix
0131       );
0132       break;
0133 
0134     case EVENT_MP_SEND_REQUEST:
0135       break;
0136 
0137   }
0138 }
0139 
0140 void _Event_MP_Process_packet (
0141   rtems_packet_prefix  *the_packet_prefix
0142 )
0143 {
0144   Event_MP_Packet *the_packet;
0145 
0146   the_packet = (Event_MP_Packet *) the_packet_prefix;
0147 
0148   switch ( the_packet->operation ) {
0149 
0150     case EVENT_MP_SEND_REQUEST:
0151 
0152       the_packet->Prefix.return_code = rtems_event_send(
0153         the_packet->Prefix.id,
0154         the_packet->event_in
0155       );
0156 
0157       _Event_MP_Send_response_packet(
0158         EVENT_MP_SEND_RESPONSE,
0159         _Thread_Executing
0160       );
0161       break;
0162 
0163     case EVENT_MP_SEND_RESPONSE: {
0164       _MPCI_Process_response( the_packet_prefix );
0165       _MPCI_Return_packet( the_packet_prefix );
0166 
0167       break;
0168     }
0169 
0170   }
0171 }
0172 
0173 /*
0174  *  _Event_MP_Send_object_was_deleted
0175  *
0176  *  This subprogram is not needed since there are no objects
0177  *  deleted by this manager.
0178  *
0179  */
0180 
0181 /*
0182  *  _Event_MP_Send_extract_proxy
0183  *
0184  *  This subprogram is not needed since there are no objects
0185  *  deleted by this manager.
0186  *
0187  */
0188 
0189 /* end of file */