void user_ports_polling () { __po_hi_port_t portno; __po_hi_node_t mynode; __po_hi_node_t tmpnode; __po_hi_request_t request; __po_hi_port_kind_t pkind; int ret; mynode = __po_hi_transport_get_mynode (); for (portno = 0 ; portno < __PO_HI_NB_PORTS ; portno++) { pkind = __po_hi_transport_get_port_kind (portno); tmpnode = __po_hi_transport_get_node_from_entity (__po_hi_get_entity_from_global_port (portno)); ret = -1; if (tmpnode == mynode) { if (pkind == __PO_HI_IN_DATA_INTER_PROCESS) { ret = XM_read_sampling_message (__po_hi_transport_xtratum_get_port (portno), &request, sizeof (__po_hi_request_t), 0); } if (pkind == __PO_HI_IN_EVENT_DATA_INTER_PROCESS) { ret = XM_receive_queuing_message (__po_hi_transport_xtratum_get_port (portno), &request, sizeof (__po_hi_request_t)); } __DEBUGMSG ("[XTRATUM POLLER] Poll port %d, corresponding xtratum port = %d, return=%d\n", portno, __po_hi_transport_xtratum_get_port (portno), ret); if (ret > 0) { __po_hi_main_deliver (&request); } } } }
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); }