POK(kernelpart)
/home/jaouen/pok_official/pok/trunk/kernel/middleware/portqueueingsend.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 
00017 #ifdef POK_NEEDS_PORTS_QUEUEING
00018 
00019 #include <types.h>
00020 #include <errno.h>
00021 
00022 #include <core/lockobj.h>
00023 #include <core/sched.h>
00024 #include <core/time.h>
00025 
00026 #include <middleware/port.h>
00027 #include <middleware/queue.h>
00028 
00029 extern pok_port_t    pok_ports[POK_CONFIG_NB_PORTS];
00030 extern pok_queue_t   pok_queue;
00031 
00032 
00033 pok_ret_t pok_port_queueing_send (const pok_port_id_t   id, 
00034                                   const void*           data, 
00035                                   const pok_port_size_t len, 
00036                                   uint64_t              timeout)
00037 {
00038    pok_lockobj_lockattr_t  lockattr;
00039    (void) lockattr;
00040 
00041    pok_ret_t ret;
00042 
00043    if (id > POK_CONFIG_NB_PORTS)
00044    {
00045       return POK_ERRNO_EINVAL;
00046    }
00047 
00048    if (len <= 0)
00049    {
00050       return POK_ERRNO_SIZE;
00051    }
00052 
00053    if (data == NULL)
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_PORT;
00066    }
00067 
00068    if (len > pok_ports[id].size)
00069    {
00070       return POK_ERRNO_SIZE;
00071    }
00072 
00073    if (pok_ports[id].direction != POK_PORT_DIRECTION_OUT)
00074    {
00075       return POK_ERRNO_DIRECTION;
00076    }
00077 
00078    if (pok_ports[id].partition != POK_SCHED_CURRENT_PARTITION)
00079    {
00080       return POK_ERRNO_EPERM;
00081    }
00082 
00083    if (pok_ports[id].kind != POK_PORT_KIND_QUEUEING)
00084    {
00085       return POK_ERRNO_KIND;
00086    }
00087 
00088    ret = pok_lockobj_lock (&pok_ports[id].lock, NULL);
00089 
00090    if (ret != POK_ERRNO_OK)
00091    {
00092       return ret;
00093    }
00094 
00095    if (timeout != 0)
00096    {
00097       timeout = timeout + POK_GETTICK();
00098    }
00099 
00100    while (len > pok_port_available_size (id))
00101    {
00102       if (timeout == 0)
00103       {
00104          pok_lockobj_unlock (&pok_ports[id].lock, NULL);
00105          return POK_ERRNO_FULL;
00106       }
00107       else
00108       {
00109          ret = pok_lockobj_eventwait (&pok_ports[id].lock, timeout);
00110          if (ret != POK_ERRNO_OK)
00111          {
00112             pok_lockobj_unlock (&pok_ports[id].lock, NULL);
00113             return (ret);
00114          }
00115       }
00116    }
00117 
00118    pok_port_write (id, data, len);
00119 
00120    pok_ports[id].must_be_flushed = TRUE;
00121 
00122    ret = pok_lockobj_unlock (&pok_ports[id].lock, NULL);
00123 
00124    if (ret != POK_ERRNO_OK)
00125    {
00126       return ret;
00127    }
00128    return POK_ERRNO_OK;
00129 }
00130 
00131 #endif
00132