17 #include <core/dependencies.h>
19 #ifdef POK_NEEDS_MIDDLEWARE
20 #ifdef POK_NEEDS_BUFFERS
24 #include <core/event.h>
25 #include <core/time.h>
26 #include <libc/string.h>
27 #include <middleware/buffer.h>
30 extern char pok_buffers_data[1024];
32 pok_ret_t pok_buffer_send (
const pok_buffer_id_t
id,
34 const pok_port_size_t len,
35 const uint64_t timeout)
39 if (
id > POK_CONFIG_NB_BUFFERS)
41 return POK_ERRNO_EINVAL;
44 if (pok_buffers[
id].ready == FALSE)
46 return POK_ERRNO_EINVAL;
51 return POK_ERRNO_EINVAL;
56 return POK_ERRNO_EINVAL;
59 if (len > (pok_buffers[
id].size * pok_buffers[
id].msgsize))
61 return POK_ERRNO_EINVAL;
64 pok_event_lock (pok_buffers[
id].lock);
66 while (pok_buffers[
id].full)
70 pok_event_unlock (pok_buffers[
id].lock);
71 return POK_ERRNO_FULL;
75 ret = pok_event_wait (pok_buffers[
id].lock, timeout);
76 if (ret != POK_ERRNO_OK)
78 pok_event_unlock (pok_buffers[
id].lock);
84 memcpy (&pok_buffers_data[pok_buffers[
id].index + pok_buffers[
id].off_e], data, len);
85 pok_buffers[id].off_e = (pok_buffers[id].off_e + len ) % pok_buffers[
id].size;
87 if (pok_buffers[
id].off_e == pok_buffers[
id].off_b)
89 pok_buffers[id].full = TRUE;
92 pok_buffers[id].empty = FALSE;
94 pok_event_unlock (pok_buffers[
id].lock);
96 pok_event_broadcast (pok_buffers[
id].lock);