Loading...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 | /* microkernel/pipe.h */
/*
* Copyright (c) 1997-2014 Wind River Systems, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef PIPE_H
#define PIPE_H
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief Microkernel Pipes
* @defgroup microkernel_pipe Microkernel Pipes
* @ingroup microkernel_services
* @{
*/
#include <sections.h>
/**
* @cond internal
*/
/**
* @internal
* @brief Initialize a pipe struct.
*
* @param size Size of pipe buffer.
* @param buffer Pointer to the buffer.
* @endinternal
*/
#define __K_PIPE_INITIALIZER(size, buffer) \
{ \
.buffer_size = size, \
.Buffer = buffer, \
}
/**
* @endcond
*/
/**
* @brief Pipe write request.
*
* Attempt to write data from a memory-buffer area to the
* specified pipe with a timeout option.
*
* @param id Pipe ID.
* @param buffer Buffer.
* @param bytes_to_write Number of bytes to write.
* @param bytes_written Pointer to number of bytes written.
* @param options Pipe options.
* @param timeout Determines the action to take when the pipe is already full.
* For TICKS_NONE, return immediately.
* For TICKS_UNLIMITED, wait as long as necessary.
* Otherwise, wait up to the specified number of ticks before timing out.
*
* @retval RC_OK Successfully wrote data to pipe.
* @retval RC_ALIGNMENT Data is improperly aligned.
* @retval RC_INCOMPLETE Only some of the data was written to the pipe when
* @a options = _ALL_N.
* @retval RC_TIME Timed out while waiting to write to pipe.
* @retval RC_FAIL Failed to immediately write to pipe when
* @a timeout = TICKS_NONE
* @sa TICKS_NONE, TICKS_UNLIMITED
*/
extern int task_pipe_put(kpipe_t id, void *buffer, int bytes_to_write,
int *bytes_written, K_PIPE_OPTION options, int32_t timeout);
/**
* @brief Pipe read request.
*
* Attempt to read data into a memory buffer area from the
* specified pipe with a timeout option.
*
* @param id Pipe ID.
* @param buffer Buffer.
* @param bytes_to_read Number of bytes to read.
* @param bytes_read Pointer to number of bytes read.
* @param options Pipe options.
* @param timeout Determines the action to take when the pipe is already full.
* For TICKS_NONE, return immediately.
* For TICKS_UNLIMITED, wait as long as necessary.
* Otherwise, wait up to the specified number of ticks before timing out.
*
* @retval RC_OK Successfully read data from pipe.
* @retval RC_ALIGNMENT Data is improperly aligned.
* @retval RC_INCOMPLETE Only some of the data was read from the pipe when
* @a options = _ALL_N.
* @retval RC_TIME Timed out waiting to read from pipe.
* @retval RC_FAIL Failed to immediately read from pipe when
* @a timeout = TICKS_NONE.
* @sa TICKS_NONE, TICKS_UNLIMITED
*/
extern int task_pipe_get(kpipe_t id, void *buffer, int bytes_to_read,
int *bytes_read, K_PIPE_OPTION options, int32_t timeout);
extern int _task_pipe_block_put(kpipe_t id,
struct k_block block,
int size,
ksem_t sema);
/**
* @brief Asynchronous pipe write request.
*
* This routine attempts to write data from a memory pool block to the
* specified pipe. (Note that partial transfers and timeouts are not
* supported, unlike the case for synchronous write requests.)
*
* @param id Pipe ID.
* @param block Block.
* @param size Size of data to be transferred.
* @param sema Semphore ID.
*
* @return RC_OK, RC_FAIL, or RC_ALIGNMENT
*/
#define task_pipe_block_put(id, block, size, sema) \
_task_pipe_block_put(id, block, size, sema)
/**
* @brief Define a private microkernel pipe.
*
* @param name Name of the pipe.
* @param size Size of the pipe buffer, in bytes.
*/
#define DEFINE_PIPE(name, size) \
char __noinit __pipe_buffer_##name[size]; \
struct _k_pipe_struct _k_pipe_obj_##name = \
__K_PIPE_INITIALIZER(size, __pipe_buffer_##name); \
const kpipe_t name \
__in_section(_k_pipe_ptr, private, pipe) = \
(kpipe_t)&_k_pipe_obj_##name;
/**
* @}
*/
#ifdef __cplusplus
}
#endif
#endif /* PIPE_H */
|