Zephyr API Documentation 4.0.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
Pipe APIs

Data Structures

struct  k_pipe
 

Macros

#define K_PIPE_DEFINE(name, pipe_buffer_size, pipe_align)
 Statically define and initialize a pipe.
 

Enumerations

enum  pipe_flags { PIPE_FLAG_OPEN = BIT(0) , PIPE_FLAG_RESET = BIT(1) }
 

Functions

void k_pipe_init (struct k_pipe *pipe, uint8_t *buffer, size_t buffer_size)
 initialize a pipe
 
int k_pipe_write (struct k_pipe *pipe, const uint8_t *data, size_t len, k_timeout_t timeout)
 Write data to a pipe.
 
int k_pipe_read (struct k_pipe *pipe, uint8_t *data, size_t len, k_timeout_t timeout)
 Read data from a pipe This routine reads up to len bytes of data from pipe.
 
void k_pipe_reset (struct k_pipe *pipe)
 Reset a pipe This routine resets the pipe, discarding any unread data and unblocking any threads waiting to write or read, causing the waiting threads to return with -ECANCELED.
 
void k_pipe_close (struct k_pipe *pipe)
 Close a pipe.
 

Detailed Description

Macro Definition Documentation

◆ K_PIPE_DEFINE

#define K_PIPE_DEFINE ( name,
pipe_buffer_size,
pipe_align )

#include <zephyr/kernel.h>

Value:
static unsigned char __noinit __aligned(pipe_align) \
_k_pipe_buf_##name[pipe_buffer_size]; \
STRUCT_SECTION_ITERABLE(k_pipe, name) = \
Z_PIPE_INITIALIZER(name, _k_pipe_buf_##name, pipe_buffer_size)
Definition kernel.h:5211

Statically define and initialize a pipe.

The pipe can be accessed outside the module where it is defined using:

extern struct k_pipe <name>;
Parameters
nameName of the pipe.
pipe_buffer_sizeSize of the pipe's ring buffer (in bytes).
pipe_alignAlignment of the pipe's ring buffer (power of 2).

Enumeration Type Documentation

◆ pipe_flags

enum pipe_flags

#include <zephyr/kernel.h>

Enumerator
PIPE_FLAG_OPEN 
PIPE_FLAG_RESET 

Function Documentation

◆ k_pipe_close()

void k_pipe_close ( struct k_pipe * pipe)

#include <zephyr/kernel.h>

Close a pipe.

This routine closes a pipe. Any threads that were blocked on the pipe will be unblocked and receive an error code.

Parameters
pipeAddress of the pipe.

◆ k_pipe_init()

void k_pipe_init ( struct k_pipe * pipe,
uint8_t * buffer,
size_t buffer_size )

#include <zephyr/kernel.h>

initialize a pipe

This routine initializes a pipe object, prior to its first use.

Parameters
pipeAddress of the pipe.
bufferAddress of the pipe's buffer.
buffer_sizeSize of the pipe's buffer.

◆ k_pipe_read()

int k_pipe_read ( struct k_pipe * pipe,
uint8_t * data,
size_t len,
k_timeout_t timeout )

#include <zephyr/kernel.h>

Read data from a pipe This routine reads up to len bytes of data from pipe.

If the pipe is empty, the routine will block until the data can be read or the timeout expires.

Parameters
pipeAddress of the pipe.
dataAddress to place the data read from pipe.
lenRequested number of bytes to read.
timeoutWaiting period to wait for the data to be read.
Return values
numberof bytes read on success
-EAGAINif no data could be read before the timeout expired
-ECANCELEDif the read was interrupted by k_pipe_reset(..)
-EPIPEif the pipe was closed

◆ k_pipe_reset()

void k_pipe_reset ( struct k_pipe * pipe)

#include <zephyr/kernel.h>

Reset a pipe This routine resets the pipe, discarding any unread data and unblocking any threads waiting to write or read, causing the waiting threads to return with -ECANCELED.

Calling k_pipe_read(..) or k_pipe_write(..) when the pipe is resetting but not yet reset will return -ECANCELED. The pipe is left open after a reset and can be used as normal.

Parameters
pipeAddress of the pipe.

◆ k_pipe_write()

int k_pipe_write ( struct k_pipe * pipe,
const uint8_t * data,
size_t len,
k_timeout_t timeout )

#include <zephyr/kernel.h>

Write data to a pipe.

This routine writes up to len bytes of data to pipe. If the pipe is full, the routine will block until the data can be written or the timeout expires.

Parameters
pipeAddress of the pipe.
dataAddress of data to write.
lenSize of data (in bytes).
timeoutWaiting period to wait for the data to be written.
Return values
numberof bytes written on success
-EAGAINif no data could be written before the timeout expired
-ECANCELEDif the write was interrupted by k_pipe_reset(..)
-EPIPEif the pipe was closed