POK(kernelpart)
portflushall.c
Go to the documentation of this file.
1 /*
2  * POK header
3  *
4  * The following file is a part of the POK project. Any modification should
5  * made according to the POK licence. You CANNOT use this file or a part of
6  * this file is this part of a file for your own project
7  *
8  * For more information on the POK licence, please see our LICENCE FILE
9  *
10  * Please follow the coding guidelines described in doc/CODING_GUIDELINES
11  *
12  * Copyright (c) 2007-2009 POK team
13  *
14  * Created by julien on Thu Jan 15 23:34:13 2009
15  */
16 
25 #if defined (POK_NEEDS_PORTS_QUEUEING) || defined (POK_NEEDS_PORTS_SAMPLING)
26 
27 #include <types.h>
28 #include <libc.h>
29 
30 #include <core/partition.h>
31 #include <core/lockobj.h>
32 
33 #include <middleware/port.h>
34 #include <middleware/queue.h>
35 
36 extern uint8_t pok_ports_nb_destinations[POK_CONFIG_NB_PORTS];
37 extern uint8_t pok_ports_nb_ports_by_partition[POK_CONFIG_NB_PARTITIONS];
38 extern uint8_t* pok_ports_destinations[POK_CONFIG_NB_PORTS];
39 extern uint8_t* pok_ports_by_partition[POK_CONFIG_NB_PARTITIONS];
40 extern pok_port_t pok_ports[POK_CONFIG_NB_PORTS];
41 extern uint8_t pok_ports_nodes[POK_CONFIG_NB_GLOBAL_PORTS];
42 extern uint8_t pok_global_ports_to_local_ports[POK_CONFIG_NB_GLOBAL_PORTS];
43 extern pok_queue_t pok_queue;
44 
45 uint8_t pok_buffer_flush[POK_PORT_MAX_SIZE];
46 
47 void pok_port_flush_partition (uint8_t pid)
48 {
49  uint8_t nb;
50  uint8_t local;
51  uint8_t i;
52  uint8_t j;
53  uint8_t ndest;
54  uint8_t local_dest; /* recipient port, global id */
55  uint8_t global_dest; /* recipient port, local id */
56  pok_port_size_t len;
57 
58  nb = pok_ports_nb_ports_by_partition[pid];
59 
60  for (i = 0 ; i < nb ; i++)
61  {
62  local = pok_ports_by_partition[pid][i];
63 
64  if (pok_ports[local].direction != POK_PORT_DIRECTION_OUT)
65  {
66  continue;
67  }
68 
69  if (pok_ports[local].empty == TRUE)
70  {
71  continue;
72  }
73 
74  if (pok_ports[local].must_be_flushed == FALSE)
75  {
76  continue;
77  }
78 
79  len = pok_port_consumed_size (local);
80 
81  if (pok_port_get (local, pok_buffer_flush, len) != POK_ERRNO_OK)
82  {
83  continue;
84  }
85 
86  ndest = pok_ports_nb_destinations[local];
87 
88  for (j=0 ; j < ndest ; j++)
89  {
90  global_dest = pok_ports_destinations[local][j];
91 
92  local_dest = pok_global_ports_to_local_ports[global_dest];
93  if (pok_ports[local_dest].ready != TRUE)
94  {
95  continue;
96  }
97 
98  if (pok_ports[local_dest].direction != POK_PORT_DIRECTION_IN)
99  {
100  continue;
101  }
102 
103  pok_port_write (local_dest, pok_buffer_flush, len);
104 
105  pok_lockobj_eventbroadcast (&pok_ports[local_dest].lock);
106  /*
107  * We notify every waiting thread in this port that data are
108  * now avaiable
109  */
110  }
111  pok_lockobj_eventbroadcast (&pok_ports[local].lock);
112  /*
113  * We notify every thread blocked on this port that free space
114  * is now available
115  */
116 
117  pok_ports[local].must_be_flushed = FALSE;
118  }
119 }
120 
125 void pok_port_flushall (void)
126 {
127  uint8_t p;
128  for (p = 0 ; p < POK_CONFIG_NB_PARTITIONS ; p++)
129  {
130  if ((pok_partitions[p].mode == POK_PARTITION_MODE_NORMAL) || (pok_partitions[p].mode == POK_PARTITION_MODE_IDLE))
131  {
132  pok_port_flush_partition (p);
133  }
134  }
135 }
136 
137 #endif