Exemplo n.º 1
0
int __po_hi_transport_send (__po_hi_task_id id, __po_hi_port_t port)
{
   __po_hi_msg_t         msg;
   __po_hi_request_t*    request;
   __po_hi_uint8_t       ndest;
   __po_hi_uint8_t       i;
   __po_hi_local_port_t  local_port;
   __po_hi_port_t        destination_port;
   __po_hi_entity_t      destination_entity;

   local_port  = __po_hi_get_local_port_from_global_port (port);
   request     = __po_hi_gqueue_get_most_recent_value (id, local_port);

   if (request->port == -1)
   {
      __PO_HI_DEBUG_DEBUG ("Send output task %d, port %d : no value to send\n", id, port);
      return __PO_HI_SUCCESS;
   }

   ndest          = __po_hi_gqueue_get_destinations_number (id, local_port);

   __PO_HI_DEBUG_DEBUG ("Send value, emitter task %d, emitter port %d, emitter entity %d, destination ports :\n", id,  port, __po_hi_port_global_to_entity[port]);

#if __PO_HI_DEBUG_LEVEL >= __PO_HI_DEBUG_LEVEL_INFO
   __DEBUGMSG ("SENT Value: |");
   {
         int s;
         int i;
         unsigned int* tmp;
         tmp = (unsigned int*) &request->vars;
         s = sizeof (request->vars);
         for (i = 0 ; i < s ; i+=4)
         {
            __DEBUGMSG("%x", *tmp);
            tmp++;
            fflush (stdout);
         }
   }
   __DEBUGMSG ("|\n");
#endif

   for (i=0 ; i < __po_hi_gqueue_get_destinations_number (id, local_port) ; i++)
   {
      destination_port     = __po_hi_gqueue_get_destination (id, local_port, i);
      destination_entity   = __po_hi_get_entity_from_global_port (destination_port);
      __PO_HI_DEBUG_DEBUG ("\t%d (entity=%d)", destination_port, destination_entity);
      __po_hi_msg_reallocate (&msg);

      request->port = destination_port;

      if (__po_hi_transport_get_node_from_entity (__po_hi_get_entity_from_global_port (port)) ==
          __po_hi_transport_get_node_from_entity (__po_hi_get_entity_from_global_port (destination_port)))
      {
            __PO_HI_DEBUG_DEBUG (" [deliver locally]\n");
            __po_hi_main_deliver (request);
      }
#ifndef XM3_RTEMS_MODE
      else
      {
            __PO_HI_DEBUG_DEBUG (" [deliver remotely]\n");
            __po_hi_transport_call_sending_func_by_port (id, port);
      }
#else /* for XTratuM */
      else
      {
         __po_hi_port_kind_t pkind = __po_hi_transport_get_port_kind (port);
         int ret;
         ret = -1;
         if (pkind == __PO_HI_OUT_DATA_INTER_PROCESS)
         {
            ret = XM_write_sampling_message (__po_hi_xtratum_port[port], request, sizeof (__po_hi_request_t));
         }

         if (pkind == __PO_HI_OUT_EVENT_DATA_INTER_PROCESS)
         {
            ret = XM_send_queuing_message (__po_hi_xtratum_port[port], request, sizeof (__po_hi_request_t));
         }

         if (ret < 0)
         {
            __PO_HI_DEBUG_CRITICAL ("[GQUEUE] Cannot deliver the data using inter-partitions ports, return=%d\n", ret);
         }
         else
         {
            __PO_HI_DEBUG_DEBUG ("[GQUEUE] Data delivered using inter-partitions ports, return=%d\n", ret);
         }
      }
#endif
   }
Exemplo n.º 2
0
void PartitionMain(void){

	//Puertos de lectura
    if ((p_sim=XM_create_sampling_port(PORT_SIM, PORT_SIZE, XM_DESTINATION_PORT))<0) {
        printf("[ControlNivel] port [%s] cannot be created\n", PORT_SIM);
        return;
    }
    if ((p_e=XM_create_sampling_port(PORT_E, PORT_SIZE, XM_DESTINATION_PORT))<0) {
        printf("[ControlNivel] port [%s] cannot be created\n", PORT_E);
        return;
    }

    //Puertos de escritura
    if ((p_pvs1=XM_create_sampling_port(PORT_PVS1, PORT_SIZE, XM_SOURCE_PORT))<0) {
        printf("[Simulador] port [%s] cannot be created\n", PORT_PVS1);
        return;
    }
	if ((p_pvs3=XM_create_sampling_port(PORT_PVS3, PORT_SIZE, XM_SOURCE_PORT))<0) {
        printf("[Simulador] port [%s] cannot be created\n", PORT_PVS3);
        return;
    }

	float n_nivel; 
	Estado n_e; 
	int flags;
    while (1) {
		//Anem llegint estats mentre estiga parat
		do{
    		XM_read_sampling_message(p_e, &n_e, sizeof(n_e), &flags);
    		if (flags&XM_MSG_VALID){
        		if(estado != n_e) estado = n_e;
			}else{
				XM_idle_self();
			}
	        printf("[P%d] Soc el control de nivell i estic PARAT\n", XM_PARTITION_SELF);
		} while(estado==PARADO);
		
		//Si es rep ordre de acabar, parem la partició
		if(estado==TERMINADO) XM_halt_partition(XM_PARTITION_SELF);

	
		//Llegim nou nivell
    	XM_read_sampling_message(p_sim, &n_nivel, sizeof(n_nivel), &flags);
    	if (flags&XM_MSG_VALID){
        	if(nivel != n_nivel){
            	nivel = n_nivel;
				actualizarPVS();
        	}	
    	}
	
		//Enviem la nova pvs
    	XM_write_sampling_message(p_pvs1, &pvs, sizeof(pvs)); 
    	XM_write_sampling_message(p_pvs3, &pvs, sizeof(pvs)); 


        printf("[P%d] Soc el control de nivell\n", XM_PARTITION_SELF);
		XM_idle_self();
	}
    
    XM_halt_partition(XM_PARTITION_SELF);
}