POK(kernelpart)
portsamplingwrite.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 
24 #ifdef POK_NEEDS_PORTS_SAMPLING
25 #include <errno.h>
26 #include <types.h>
27 #include <libc.h>
28 #include <core/debug.h>
29 #include <core/sched.h>
30 #include <core/lockobj.h>
31 #include <middleware/port.h>
32 #include <middleware/queue.h>
33 
34 extern uint8_t pok_current_partition;
35 extern uint8_t pok_ports_parts_nb_ports[POK_CONFIG_NB_PARTITIONS];
36 extern uint8_t* pok_ports_parts_ports_identifiers[POK_CONFIG_NB_PARTITIONS];
37 extern uint8_t* pok_ports_local_to_global[POK_CONFIG_NB_PARTITIONS];
38 extern pok_port_t pok_ports[POK_CONFIG_NB_PORTS];
39 extern pok_queue_t pok_queues[POK_CONFIG_NB_PARTITIONS];
40 
41 
42 pok_ret_t pok_port_sampling_write (const pok_port_id_t id,
43  const void* data,
44  const pok_port_size_t len)
45 {
46  /* We don't handle the timeout at this time */
47 
48  if (data == NULL)
49  {
50  return POK_ERRNO_EINVAL;
51  }
52 
53  if (id > POK_CONFIG_NB_PORTS)
54  {
55  return POK_ERRNO_EINVAL;
56  }
57 
58  if (! pok_own_port (POK_SCHED_CURRENT_PARTITION, id))
59  {
60  return POK_ERRNO_PORT;
61  }
62 
63  if (pok_ports[id].ready != TRUE)
64  {
65  return POK_ERRNO_EINVAL;
66  }
67 
68  if (len > pok_ports[id].size)
69  {
70  return POK_ERRNO_EINVAL;
71  }
72 
73  if (pok_ports[id].direction != POK_PORT_DIRECTION_OUT)
74  {
75  return POK_ERRNO_DIRECTION;
76  }
77 
78  pok_lockobj_lock (&pok_ports[id].lock, NULL);
79 
80  pok_port_write (id, data, len);
81 
82  pok_lockobj_unlock (&pok_ports[id].lock, NULL);
83 
84  pok_ports[id].must_be_flushed = TRUE;
85 
86  return POK_ERRNO_OK;
87 }
88 
89 #endif