POK(kernelpart)
/home/jaouen/pok_official/pok/trunk/kernel/middleware/portsamplingwrite.c
Go to the documentation of this file.
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 
00024 #ifdef POK_NEEDS_PORTS_SAMPLING
00025 #include <errno.h>
00026 #include <types.h>
00027 #include <libc.h>
00028 #include <core/debug.h>
00029 #include <core/sched.h>
00030 #include <core/lockobj.h>
00031 #include <middleware/port.h>
00032 #include <middleware/queue.h>
00033 
00034 extern uint8_t       pok_current_partition;
00035 extern uint8_t       pok_ports_parts_nb_ports[POK_CONFIG_NB_PARTITIONS];
00036 extern uint8_t*      pok_ports_parts_ports_identifiers[POK_CONFIG_NB_PARTITIONS];
00037 extern uint8_t*      pok_ports_local_to_global[POK_CONFIG_NB_PARTITIONS];
00038 extern pok_port_t    pok_ports[POK_CONFIG_NB_PORTS];
00039 extern pok_queue_t   pok_queues[POK_CONFIG_NB_PARTITIONS];
00040 
00041 
00042 pok_ret_t pok_port_sampling_write (const pok_port_id_t   id, 
00043                                   const void*            data, 
00044                                   const pok_port_size_t  len)
00045 {
00046    /* We don't handle the timeout at this time */
00047 
00048    if (data == NULL)
00049    {
00050       return POK_ERRNO_EINVAL;
00051    }
00052 
00053    if (id > POK_CONFIG_NB_PORTS)
00054    {
00055       return POK_ERRNO_EINVAL;
00056    }
00057 
00058    if (! pok_own_port (POK_SCHED_CURRENT_PARTITION, id))
00059    {
00060       return POK_ERRNO_PORT;
00061    }
00062 
00063    if (pok_ports[id].ready != TRUE)
00064    {
00065       return POK_ERRNO_EINVAL;
00066    }
00067    
00068    if (len > pok_ports[id].size)
00069    {
00070       return POK_ERRNO_EINVAL;
00071    }
00072 
00073    if (pok_ports[id].direction != POK_PORT_DIRECTION_OUT)
00074    {
00075       return POK_ERRNO_DIRECTION;
00076    }
00077 
00078    pok_lockobj_lock (&pok_ports[id].lock, NULL);
00079 
00080    pok_port_write (id, data, len);
00081    
00082    pok_lockobj_unlock (&pok_ports[id].lock, NULL);
00083 
00084    pok_ports[id].must_be_flushed = TRUE;
00085 
00086    return POK_ERRNO_OK;
00087 }
00088 
00089 #endif