POK(kernelpart)
portcreate.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 
17 #if defined (POK_NEEDS_PORTS_SAMPLING) || defined (POK_NEEDS_PORTS_QUEUEING)
18 
19 #include <errno.h>
20 #include <types.h>
21 #include <core/error.h>
22 #include <core/partition.h>
23 #include <middleware/port.h>
24 #include <middleware/queue.h>
25 #include <libc.h>
26 
27 extern uint8_t pok_current_partition;
28 extern uint8_t pok_ports_parts_nb_ports[POK_CONFIG_NB_PARTITIONS];
29 extern uint8_t* pok_ports_parts_ports_identifiers[POK_CONFIG_NB_PARTITIONS];
30 extern pok_port_t pok_ports[POK_CONFIG_NB_PORTS];
31 extern pok_queue_t pok_queue;
32 
33 pok_ret_t pok_port_create (char* name,
34  const pok_port_size_t size,
35  const pok_port_direction_t direction,
36  uint8_t kind, pok_port_id_t* id)
37 {
38  uint8_t gid;
39  pok_ret_t ret;
40 
41  ret = POK_ERRNO_OK;
42 
43 
44  if (size > POK_PORT_MAX_SIZE)
45  {
46 #if (defined POK_NEEDS_PARTITIONS) && (defined POK_NEEDS_ERROR_HANDLING)
47  POK_ERROR_CURRENT_PARTITION(POK_ERROR_KIND_PARTITION_CONFIGURATION);
48 #endif
49  return POK_ERRNO_PORT;
50  }
51 
52  if (size > pok_queue.available_size)
53  {
54 #if (defined POK_NEEDS_PARTITIONS) && (defined POK_NEEDS_ERROR_HANDLING)
55  POK_ERROR_CURRENT_PARTITION(POK_ERROR_KIND_PARTITION_CONFIGURATION);
56 #endif
57  return POK_ERRNO_PORT;
58  }
59 
60  if ((direction != POK_PORT_DIRECTION_IN) &&
61  (direction != POK_PORT_DIRECTION_OUT))
62  {
63 #if (defined POK_NEEDS_PARTITIONS) && (defined POK_NEEDS_ERROR_HANDLING)
64  POK_ERROR_CURRENT_PARTITION(POK_ERROR_KIND_PARTITION_CONFIGURATION);
65 #endif
66  return POK_ERRNO_PORT;
67  }
68 
69  switch (kind)
70  {
72  {
73 #ifdef POK_NEEDS_PORTS_SAMPLING
74  ret = pok_port_sampling_id (name, &gid);
75 #endif
76  break;
77  }
79  {
80 #ifdef POK_NEEDS_PORTS_QUEUEING
81  ret = pok_port_queueing_id (name, &gid);
82 #endif
83  break;
84  }
85  default:
86  {
87  return POK_ERRNO_EINVAL;
88  break;
89  }
90  }
91 
92  if (ret != POK_ERRNO_OK)
93  {
94 #if (defined POK_NEEDS_PARTITIONS) && (defined POK_NEEDS_ERROR_HANDLING)
95  POK_ERROR_CURRENT_PARTITION(POK_ERROR_KIND_PARTITION_INIT);
96 #endif
97  return ret;
98  }
99 
100  if (! pok_own_port (POK_SCHED_CURRENT_PARTITION, gid))
101  {
102  return POK_ERRNO_PORT;
103  }
104 
105  /*
106  * Check if the port was already created
107  * If it's already created, we return ERRNO_EXISTS but indicate
108  * the right port-id. This should not be taken as an assumption
109  * but could help the developper when a partition is restarted.
110  */
111  if (pok_ports[gid].ready == TRUE)
112  {
113  *id = gid;
114  return POK_ERRNO_EXISTS;
115  }
116 
117  pok_ports[gid].index = pok_queue.size - pok_queue.available_size;
118  pok_ports[gid].off_b = 0;
119  pok_ports[gid].off_e = 0;
120  pok_ports[gid].size = size;
121  pok_ports[gid].full = FALSE;
122  pok_ports[gid].partition = pok_current_partition;
123  pok_ports[gid].direction = direction;
124  pok_ports[gid].ready = TRUE;
125  pok_ports[gid].kind = kind;
126 
127  pok_queue.available_size = pok_queue.available_size - size;
128 
129  *id = gid;
130 
131  return POK_ERRNO_OK;
132 }
133 #endif