POK(kernelpart)
|
00001 /* 00002 * POK header 00003 * 00004 * The following file is a part of the POK project. Any modification should 00005 * made according to the POK licence. You CANNOT use this file or a part of 00006 * this file is this part of a file for your own project 00007 * 00008 * For more information on the POK licence, please see our LICENCE FILE 00009 * 00010 * Please follow the coding guidelines described in doc/CODING_GUIDELINES 00011 * 00012 * Copyright (c) 2007-2009 POK team 00013 * 00014 * Created by julien on Thu Jan 15 23:34:13 2009 00015 */ 00016 00025 #if defined (POK_NEEDS_PORTS_QUEUEING) || defined (POK_NEEDS_PORTS_SAMPLING) 00026 00027 #include <types.h> 00028 #include <libc.h> 00029 00030 #include <core/partition.h> 00031 #include <core/lockobj.h> 00032 00033 #include <middleware/port.h> 00034 #include <middleware/queue.h> 00035 00036 extern uint8_t pok_ports_nb_destinations[POK_CONFIG_NB_PORTS]; 00037 extern uint8_t pok_ports_nb_ports_by_partition[POK_CONFIG_NB_PARTITIONS]; 00038 extern uint8_t* pok_ports_destinations[POK_CONFIG_NB_PORTS]; 00039 extern uint8_t* pok_ports_by_partition[POK_CONFIG_NB_PARTITIONS]; 00040 extern pok_port_t pok_ports[POK_CONFIG_NB_PORTS]; 00041 extern uint8_t pok_ports_nodes[POK_CONFIG_NB_GLOBAL_PORTS]; 00042 extern uint8_t pok_global_ports_to_local_ports[POK_CONFIG_NB_GLOBAL_PORTS]; 00043 extern pok_queue_t pok_queue; 00044 00045 uint8_t pok_buffer_flush[POK_PORT_MAX_SIZE]; 00046 00047 void pok_port_flush_partition (uint8_t pid) 00048 { 00049 uint8_t nb; 00050 uint8_t local; 00051 uint8_t i; 00052 uint8_t j; 00053 uint8_t ndest; 00054 uint8_t local_dest; /* recipient port, global id */ 00055 uint8_t global_dest; /* recipient port, local id */ 00056 pok_port_size_t len; 00057 00058 nb = pok_ports_nb_ports_by_partition[pid]; 00059 00060 for (i = 0 ; i < nb ; i++) 00061 { 00062 local = pok_ports_by_partition[pid][i]; 00063 00064 if (pok_ports[local].direction != POK_PORT_DIRECTION_OUT) 00065 { 00066 continue; 00067 } 00068 00069 if (pok_ports[local].empty == TRUE) 00070 { 00071 continue; 00072 } 00073 00074 if (pok_ports[local].must_be_flushed == FALSE) 00075 { 00076 continue; 00077 } 00078 00079 len = pok_port_consumed_size (local); 00080 00081 if (pok_port_get (local, pok_buffer_flush, len) != POK_ERRNO_OK) 00082 { 00083 continue; 00084 } 00085 00086 ndest = pok_ports_nb_destinations[local]; 00087 00088 for (j=0 ; j < ndest ; j++) 00089 { 00090 global_dest = pok_ports_destinations[local][j]; 00091 00092 local_dest = pok_global_ports_to_local_ports[global_dest]; 00093 if (pok_ports[local_dest].ready != TRUE) 00094 { 00095 continue; 00096 } 00097 00098 if (pok_ports[local_dest].direction != POK_PORT_DIRECTION_IN) 00099 { 00100 continue; 00101 } 00102 00103 pok_port_write (local_dest, pok_buffer_flush, len); 00104 00105 pok_lockobj_eventbroadcast (&pok_ports[local_dest].lock); 00106 /* 00107 * We notify every waiting thread in this port that data are 00108 * now avaiable 00109 */ 00110 } 00111 pok_lockobj_eventbroadcast (&pok_ports[local].lock); 00112 /* 00113 * We notify every thread blocked on this port that free space 00114 * is now available 00115 */ 00116 00117 pok_ports[local].must_be_flushed = FALSE; 00118 } 00119 } 00120 00125 void pok_port_flushall (void) 00126 { 00127 uint8_t p; 00128 for (p = 0 ; p < POK_CONFIG_NB_PARTITIONS ; p++) 00129 { 00130 if ((pok_partitions[p].mode == POK_PARTITION_MODE_NORMAL) || (pok_partitions[p].mode == POK_PARTITION_MODE_IDLE)) 00131 { 00132 pok_port_flush_partition (p); 00133 } 00134 } 00135 } 00136 00137 #endif