Pipe IPC

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.

struct riot_pipe pipe_t

A generic pipe.

void pipe_init(pipe.h::pipe_t * pipe, ringbuffer_t * rb, void(*)(void *) free)

Initialize a pipe.

Parameters

pipe:Datum to initialize.
rb:Ringbuffer to use. Needs to be initialized!
free:Function to call by pipe.h::pipe_free(). Used like pipe->free(pipe). Should be NULL for statically allocated pipes.

msp430_types.h::ssize_t pipe_read(pipe.h::pipe_t * pipe, void * buf, msp430_types.h::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.h::irq_is_in()) 0 will returned if the pipe is empty.

Parameters

pipe:Pipe to read from.
buf:Buffer to write into
n:Size of buffer.

Return values

  • > 0 if data could be read. == 0 if the pipe is empty and isISR().
msp430_types.h::ssize_t pipe_write(pipe.h::pipe_t * pipe, const void * buf, msp430_types.h::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.h::irq_is_in()) 0 will returned if the pipe is full.

Parameters

pipe:Pipe to write to.
buf:Buffer to read from.
n:Size of buffer.

Return values

  • > 0 if data could be written. == 0 if the pipe is full and isISR().
pipe.h::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.

Return values

  • Newly allocated pipe. NULL if the memory is exhausted.
void pipe_free(pipe.h::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.h::pipe_malloc().

Parameters

rp:Pipe to free.

PIPE_BUF

Size of a dynamically malloc’d pipe.

1
(128)
struct riot_pipe

A generic pipe.

ringbuffer_t * rb

Wrapped ringbuffer.

sched.h::thread_t * read_blocked

A thread that wants to write to this full pipe.

sched.h::thread_t * write_blocked

A thread that wants to read from this empty pipe.

void(* free()

Function to call by pipe.h::pipe_free().

Used like pipe->free(pipe).