Generic pipe implementation.
More...
Generic pipe implementation.
This pipe implementation is a tight wrapper around a ringbuffer. It sends the calling thread to sleep if the ringbuffer is full or empty, respectively. It can be used in ISRs, too.
|
#define | PIPE_BUF (128) |
| Size of a dynamically malloc'd pipe.
|
|
◆ pipe_free()
Free a pipe.
On statically allocated pipes you do not have to call this function. Most likely you will only need this function in junction with pipe_malloc().
- Parameters
-
◆ pipe_init()
Initialize a pipe.
- Parameters
-
[out] | pipe | Datum to initialize. |
| rb | Ringbuffer to use. Needs to be initialized! |
| free | Function to call by pipe_free(). Used like pipe->free(pipe) . Should be NULL for statically allocated pipes. |
◆ pipe_malloc()
pipe_t* pipe_malloc |
( |
unsigned |
size | ) |
|
Dynamically allocate a pipe with room for size
bytes.
This function uses malloc()
and may break real-time behaviors. Try not to use this function.
- Parameters
-
size | Size of the underlying ringbuffer to allocate. |
- Returns
- Newly allocated pipe. NULL if the memory is exhausted.
◆ pipe_read()
ssize_t pipe_read |
( |
pipe_t * |
pipe, |
|
|
void * |
buf, |
|
|
size_t |
n |
|
) |
| |
Read from a pipe.
Only one thread may access the pipe readingly at once. If the pipe is empty, then the current thread is send sleeping. It gets woken up once there is data ready in the pipe. In an ISR (irq_is_in()) 0 will returned if the pipe is empty.
- Parameters
-
[in] | pipe | Pipe to read from. |
[out] | buf | Buffer to write into |
| n | Size of buffer. |
- Returns
> 0
if data could be read. == 0
if the pipe is empty and isISR().
◆ pipe_write()
ssize_t pipe_write |
( |
pipe_t * |
pipe, |
|
|
const void * |
buf, |
|
|
size_t |
n |
|
) |
| |
Write to a pipe.
Only one thread may access the pipe writingly at once. If the pipe is full, then the current thread is send sleeping. It gets woken up once there is room again in the pipe. In an ISR (irq_is_in()) 0 will returned if the pipe is full.
- Parameters
-
[in] | pipe | Pipe to write to. |
[out] | buf | Buffer to read from. |
| n | Size of buffer. |
- Returns
> 0
if data could be written. == 0
if the pipe is full and isISR().