Loading...
Searching...
No Matches
Pipe IPC

Generic pipe implementation. More...

Detailed Description

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.

Files

file  pipe.h
 

Data Structures

struct  riot_pipe
 A generic pipe. More...
 

Macros

#define PIPE_BUF   (128)
 Size of a dynamically malloc'd pipe.
 

Typedefs

typedef struct riot_pipe pipe_t
 A generic pipe.
 

Functions

void pipe_init (pipe_t *pipe, ringbuffer_t *rb, void(*free)(void *))
 Initialize a pipe.
 
ssize_t pipe_read (pipe_t *pipe, void *buf, size_t n)
 Read from a pipe.
 
ssize_t pipe_write (pipe_t *pipe, const void *buf, size_t n)
 Write to a pipe.
 
pipe_tpipe_malloc (unsigned size)
 Dynamically allocate a pipe with room for size bytes.
 
void pipe_free (pipe_t *rp)
 Free a pipe.
 

Macro Definition Documentation

◆ PIPE_BUF

#define PIPE_BUF   (128)

Size of a dynamically malloc'd pipe.

Definition at line 49 of file pipe.h.

Function Documentation

◆ pipe_free()

void pipe_free ( pipe_t rp)

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
rpPipe to free.

◆ pipe_init()

void pipe_init ( pipe_t pipe,
ringbuffer_t rb,
void(*)(void *)  free 
)

Initialize a pipe.

Parameters
[out]pipeDatum to initialize.
rbRingbuffer to use. Needs to be initialized!
freeFunction 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
sizeSize 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]pipePipe to read from.
[out]bufBuffer to write into
nSize 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]pipePipe to write to.
[out]bufBuffer to read from.
nSize of buffer.
Returns
> 0 if data could be written. == 0 if the pipe is full and isISR().