unified: Tweak pipe API parameters

- Reorders parameters where necessary
 - Adds alignment parameter to K_PIPE_DEFINE()
 - Renames parameters where necessary so they are sync'd
   between header and source files

Change-Id: I4f2367abc28aff646cc90beb9f08bb266e143b0c
Signed-off-by: Peter Mitsis <peter.mitsis@windriver.com>
This commit is contained in:
Peter Mitsis 2016-10-14 14:44:57 -04:00 committed by Benjamin Walsh
commit e5d9c58301
5 changed files with 37 additions and 36 deletions

View file

@ -57,12 +57,12 @@ optional character buffer of type :c:type:`unsigned char`. It must then be
initialized by calling :c:func:`k_pipe_init()`. initialized by calling :c:func:`k_pipe_init()`.
The following code defines and initializes an empty pipe that has a ring The following code defines and initializes an empty pipe that has a ring
buffer capable of holding 100 bytes. buffer capable of holding 100 bytes and is aligned to a 4-byte boundary.
.. code-block:: c .. code-block:: c
unsigned char my_ring_buffer[100]; unsigned char __aligned(4) my_ring_buffer[100];
struct k_pipe my_pipe; struct k_pipe my_pipe;
k_pipe_init(&my_pipe, my_ring_buffer, sizeof(my_ring_buffer)); k_pipe_init(&my_pipe, my_ring_buffer, sizeof(my_ring_buffer));
@ -75,7 +75,7 @@ that that macro defines both the pipe and its ring buffer.
.. code-block:: c .. code-block:: c
K_PIPE_DEFINE(my_pipe, 100); K_PIPE_DEFINE(my_pipe, 100, 4);
Writing to a Pipe Writing to a Pipe
================= =================

View file

@ -920,7 +920,7 @@ struct k_pipe {
_DEBUG_TRACING_KERNEL_OBJECTS_NEXT_PTR(k_pipe); _DEBUG_TRACING_KERNEL_OBJECTS_NEXT_PTR(k_pipe);
}; };
#define K_PIPE_INITIALIZER(obj, pipe_buffer_size, pipe_buffer) \ #define K_PIPE_INITIALIZER(obj, pipe_buffer, pipe_buffer_size) \
{ \ { \
.buffer = pipe_buffer, \ .buffer = pipe_buffer, \
.size = pipe_buffer_size, \ .size = pipe_buffer_size, \
@ -932,10 +932,11 @@ struct k_pipe {
_DEBUG_TRACING_KERNEL_OBJECTS_INIT \ _DEBUG_TRACING_KERNEL_OBJECTS_INIT \
} }
#define K_PIPE_DEFINE(name, pipe_buffer_size) \ #define K_PIPE_DEFINE(name, pipe_buffer_size, pipe_align) \
static unsigned char __noinit _k_pipe_buf_##name[pipe_buffer_size]; \ static unsigned char __noinit __aligned(pipe_align) \
_k_pipe_buf_##name[pipe_buffer_size]; \
struct k_pipe name = \ struct k_pipe name = \
K_PIPE_INITIALIZER(name, pipe_buffer_size, _k_pipe_buf_##name) K_PIPE_INITIALIZER(name, _k_pipe_buf_##name, pipe_buffer_size)
/** /**
* @brief Runtime initialization of a pipe * @brief Runtime initialization of a pipe
@ -954,48 +955,48 @@ extern void k_pipe_init(struct k_pipe *pipe, unsigned char *buffer,
* *
* This routine synchronously adds a message into the pipe specified by * This routine synchronously adds a message into the pipe specified by
* @a pipe. It will wait up to @a timeout for the pipe to accept * @a pipe. It will wait up to @a timeout for the pipe to accept
* @a num_bytes_to_write bytes of data. If by @a timeout, the pipe could not * @a bytes_to_write bytes of data. If by @a timeout, the pipe could not
* accept @a min_bytes bytes of data, it fails. Fewer than @a min_bytes will * accept @a min_xfer bytes of data, it fails. Fewer than @a min_xfer will
* only ever be written to the pipe if K_NO_WAIT < @a timeout < K_FOREVER. * only ever be written to the pipe if K_NO_WAIT < @a timeout < K_FOREVER.
* *
* @param pipe Pointer to the pipe * @param pipe Pointer to the pipe
* @param buffer Data to put into the pipe * @param data Data to put into the pipe
* @param num_bytes_to_write Desired number of bytes to put into the pipe * @param bytes_to_write Desired number of bytes to put into the pipe
* @param num_bytes_written Number of bytes the pipe accepted * @param bytes_written Number of bytes the pipe accepted
* @param min_bytes Minimum number of bytes accepted for success * @param min_xfer Minimum number of bytes accepted for success
* @param timeout Maximum number of milliseconds to wait * @param timeout Maximum number of milliseconds to wait
* *
* @retval 0 At least @a min_bytes were sent * @retval 0 At least @a min_xfer were sent
* @retval -EIO Request can not be satisfied (@a timeout is K_NO_WAIT) * @retval -EIO Request can not be satisfied (@a timeout is K_NO_WAIT)
* @retval -EAGAIN Fewer than @a min_bytes were sent * @retval -EAGAIN Fewer than @a min_xfer were sent
*/ */
extern int k_pipe_put(struct k_pipe *pipe, void *buffer, extern int k_pipe_put(struct k_pipe *pipe, void *data,
size_t num_bytes_to_write, size_t *num_bytes_written, size_t bytes_to_write, size_t *bytes_written,
size_t min_bytes, int32_t timeout); size_t min_xfer, int32_t timeout);
/** /**
* @brief Get a message from the specified pipe * @brief Get a message from the specified pipe
* *
* This routine synchronously retrieves a message from the pipe specified by * This routine synchronously retrieves a message from the pipe specified by
* @a pipe. It will wait up to @a timeout to retrieve @a num_bytes_to_read * @a pipe. It will wait up to @a timeout to retrieve @a bytes_to_read
* bytes of data from the pipe. If by @a timeout, the pipe could not retrieve * bytes of data from the pipe. If by @a timeout, the pipe could not retrieve
* @a min_bytes bytes of data, it fails. Fewer than @a min_bytes will * @a min_xfer bytes of data, it fails. Fewer than @a min_xfer will
* only ever be retrieved from the pipe if K_NO_WAIT < @a timeout < K_FOREVER. * only ever be retrieved from the pipe if K_NO_WAIT < @a timeout < K_FOREVER.
* *
* @param pipe Pointer to the pipe * @param pipe Pointer to the pipe
* @param buffer Location to place retrieved data * @param data Location to place retrieved data
* @param num_bytes_to_read Desired number of bytes to retrieve from the pipe * @param bytes_to_read Desired number of bytes to retrieve from the pipe
* @param num_bytes_read Number of bytes retrieved from the pipe * @param bytes_read Number of bytes retrieved from the pipe
* @param min_bytes Minimum number of bytes retrieved for success * @param min_xfer Minimum number of bytes retrieved for success
* @param timeout Maximum number of milliseconds to wait * @param timeout Maximum number of milliseconds to wait
* *
* @retval 0 At least @a min_bytes were transferred * @retval 0 At least @a min_xfer were transferred
* @retval -EIO Request can not be satisfied (@a timeout is K_NO_WAIT) * @retval -EIO Request can not be satisfied (@a timeout is K_NO_WAIT)
* @retval -EAGAIN Fewer than @a min_bytes were retrieved * @retval -EAGAIN Fewer than @a min_xfer were retrieved
*/ */
extern int k_pipe_get(struct k_pipe *pipe, void *buffer, extern int k_pipe_get(struct k_pipe *pipe, void *data,
size_t num_bytes_to_read, size_t *num_bytes_read, size_t bytes_to_read, size_t *bytes_read,
size_t min_bytes, int32_t timeout); size_t min_xfer, int32_t timeout);
/** /**
* @brief Send a message to the specified pipe * @brief Send a message to the specified pipe

View file

@ -567,7 +567,7 @@ static inline int task_pipe_block_put(kpipe_t id, struct k_block block,
} }
#define DEFINE_PIPE(name, pipe_buffer_size) \ #define DEFINE_PIPE(name, pipe_buffer_size) \
K_PIPE_DEFINE(_k_pipe_obj_##name, pipe_buffer_size); \ K_PIPE_DEFINE(_k_pipe_obj_##name, pipe_buffer_size, 4); \
struct k_pipe * const name = &_k_pipe_obj_##name struct k_pipe * const name = &_k_pipe_obj_##name
#define nano_fifo k_fifo #define nano_fifo k_fifo

View file

@ -523,7 +523,7 @@ int _k_pipe_put_internal(struct k_pipe *pipe, struct k_pipe_async *async_desc,
bytes_to_write); bytes_to_write);
} }
int k_pipe_get(struct k_pipe *pipe, void *buffer, size_t bytes_to_read, int k_pipe_get(struct k_pipe *pipe, void *data, size_t bytes_to_read,
size_t *bytes_read, size_t min_xfer, int32_t timeout) size_t *bytes_read, size_t min_xfer, int32_t timeout)
{ {
struct k_thread *writer; struct k_thread *writer;
@ -554,7 +554,7 @@ int k_pipe_get(struct k_pipe *pipe, void *buffer, size_t bytes_to_read,
k_sched_lock(); k_sched_lock();
irq_unlock(key); irq_unlock(key);
num_bytes_read = _pipe_buffer_get(pipe, buffer, bytes_to_read); num_bytes_read = _pipe_buffer_get(pipe, data, bytes_to_read);
/* /*
* 1. 'xfer_list' currently contains a list of writer threads that can * 1. 'xfer_list' currently contains a list of writer threads that can
@ -574,7 +574,7 @@ int k_pipe_get(struct k_pipe *pipe, void *buffer, size_t bytes_to_read,
sys_dlist_get(&xfer_list); sys_dlist_get(&xfer_list);
while (thread && (num_bytes_read < bytes_to_read)) { while (thread && (num_bytes_read < bytes_to_read)) {
desc = (struct k_pipe_desc *)thread->swap_data; desc = (struct k_pipe_desc *)thread->swap_data;
bytes_copied = _pipe_xfer(buffer + num_bytes_read, bytes_copied = _pipe_xfer(data + num_bytes_read,
bytes_to_read - num_bytes_read, bytes_to_read - num_bytes_read,
desc->buffer, desc->bytes_to_xfer); desc->buffer, desc->bytes_to_xfer);
@ -598,7 +598,7 @@ int k_pipe_get(struct k_pipe *pipe, void *buffer, size_t bytes_to_read,
if (writer && (num_bytes_read < bytes_to_read)) { if (writer && (num_bytes_read < bytes_to_read)) {
desc = (struct k_pipe_desc *)writer->swap_data; desc = (struct k_pipe_desc *)writer->swap_data;
bytes_copied = _pipe_xfer(buffer + num_bytes_read, bytes_copied = _pipe_xfer(data + num_bytes_read,
bytes_to_read - num_bytes_read, bytes_to_read - num_bytes_read,
desc->buffer, desc->bytes_to_xfer); desc->buffer, desc->bytes_to_xfer);
@ -647,7 +647,7 @@ int k_pipe_get(struct k_pipe *pipe, void *buffer, size_t bytes_to_read,
struct k_pipe_desc pipe_desc; struct k_pipe_desc pipe_desc;
pipe_desc.buffer = buffer + num_bytes_read; pipe_desc.buffer = data + num_bytes_read;
pipe_desc.bytes_to_xfer = bytes_to_read - num_bytes_read; pipe_desc.bytes_to_xfer = bytes_to_read - num_bytes_read;
if (timeout != K_NO_WAIT) { if (timeout != K_NO_WAIT) {

View file

@ -724,7 +724,7 @@ def kernel_main_c_pipes():
for pipe in pipe_list: for pipe in pipe_list:
name = pipe[0] name = pipe[0]
size = pipe[1] size = pipe[1]
kernel_main_c_out("K_PIPE_DEFINE(_k_pipe_obj_%s, %d);\n" % kernel_main_c_out("K_PIPE_DEFINE(_k_pipe_obj_%s, %d, 4);\n" %
(name, size)) (name, size))