ChibiOS 21.11.4

Detailed Description

Collaboration diagram for Pipes:

Data Structures

struct  pipe_t
 Structure representing a pipe object. More...

Macros

#define PC_INIT(p)
#define PC_LOCK(p)
#define PC_UNLOCK(p)
#define PW_INIT(p)
#define PW_LOCK(p)
#define PW_UNLOCK(p)
#define PR_INIT(p)
#define PR_LOCK(p)
#define PR_UNLOCK(p)
#define __PIPE_DATA(name, buffer, size)
 Data part of a static pipe initializer.
#define PIPE_DECL(name, buffer, size)
 Static pipe initializer.

Functions

static size_t pipe_write (pipe_t *pp, const uint8_t *bp, size_t n)
 Non-blocking pipe write.
static size_t pipe_read (pipe_t *pp, uint8_t *bp, size_t n)
 Non-blocking pipe read.
void chPipeObjectInit (pipe_t *pp, uint8_t *buf, size_t n)
 Initializes a mailbox_t object.
void chPipeReset (pipe_t *pp)
 Resets a pipe_t object.
size_t chPipeWriteTimeout (pipe_t *pp, const uint8_t *bp, size_t n, sysinterval_t timeout)
 Pipe write with timeout.
size_t chPipeReadTimeout (pipe_t *pp, uint8_t *bp, size_t n, sysinterval_t timeout)
 Pipe read with timeout.
static size_t chPipeGetSize (const pipe_t *pp)
 Returns the pipe buffer size as number of bytes.
static size_t chPipeGetUsedCount (const pipe_t *pp)
 Returns the number of used byte slots into a pipe.
static size_t chPipeGetFreeCount (const pipe_t *pp)
 Returns the number of free byte slots into a pipe.
static void chPipeResume (pipe_t *pp)
 Terminates the reset state.

Macro Definition Documentation

◆ PC_INIT

#define PC_INIT ( p)
Value:
chMtxObjectInit(&(p)->cmtx)
void chMtxObjectInit(mutex_t *mp)
Initializes s mutex_t structure.
Definition chmtx.c:103

Definition at line 54 of file chpipes.c.

Referenced by chPipeObjectInit().

◆ PC_LOCK

#define PC_LOCK ( p)
Value:
chMtxLock(&(p)->cmtx)
void chMtxLock(mutex_t *mp)
Locks the specified mutex.
Definition chmtx.c:123

Definition at line 55 of file chpipes.c.

Referenced by chPipeReset(), pipe_read(), and pipe_write().

◆ PC_UNLOCK

#define PC_UNLOCK ( p)
Value:
chMtxUnlock(&(p)->cmtx)
void chMtxUnlock(mutex_t *mp)
Unlocks the specified mutex.
Definition chmtx.c:326

Definition at line 56 of file chpipes.c.

Referenced by chPipeReset(), pipe_read(), and pipe_write().

◆ PW_INIT

#define PW_INIT ( p)
Value:
chMtxObjectInit(&(p)->wmtx)

Definition at line 57 of file chpipes.c.

Referenced by chPipeObjectInit().

◆ PW_LOCK

#define PW_LOCK ( p)
Value:
chMtxLock(&(p)->wmtx)

Definition at line 58 of file chpipes.c.

Referenced by chPipeWriteTimeout().

◆ PW_UNLOCK

#define PW_UNLOCK ( p)
Value:
chMtxUnlock(&(p)->wmtx)

Definition at line 59 of file chpipes.c.

Referenced by chPipeWriteTimeout().

◆ PR_INIT

#define PR_INIT ( p)
Value:
chMtxObjectInit(&(p)->rmtx)

Definition at line 60 of file chpipes.c.

Referenced by chPipeObjectInit().

◆ PR_LOCK

#define PR_LOCK ( p)
Value:
chMtxLock(&(p)->rmtx)

Definition at line 61 of file chpipes.c.

Referenced by chPipeReadTimeout().

◆ PR_UNLOCK

#define PR_UNLOCK ( p)
Value:
chMtxUnlock(&(p)->rmtx)

Definition at line 62 of file chpipes.c.

Referenced by chPipeReadTimeout().

◆ __PIPE_DATA

#define __PIPE_DATA ( name,
buffer,
size )
Value:
{ \
(uint8_t *)(buffer), \
(uint8_t *)(buffer) + size, \
(uint8_t *)(buffer), \
(uint8_t *)(buffer), \
(size_t)0, \
false, \
NULL, \
NULL, \
__MUTEX_DATA(name.cmtx), \
__MUTEX_DATA(name.wmtx), \
__MUTEX_DATA(name.rmtx), \
}
#define __MUTEX_DATA(name)
Data part of a static mutex initializer.
Definition chmtx.h:81

Data part of a static pipe initializer.

This macro should be used when statically initializing a pipe that is part of a bigger structure.

Parameters
[in]namethe name of the pipe variable
[in]bufferpointer to the pipe buffer array of uint8_t
[in]sizenumber of uint8_t elements in the buffer array

Definition at line 88 of file chpipes.h.

◆ PIPE_DECL

#define PIPE_DECL ( name,
buffer,
size )
Value:
pipe_t name = __PIPE_DATA(name, buffer, size)
#define __PIPE_DATA(name, buffer, size)
Data part of a static pipe initializer.
Definition chpipes.h:88
Structure representing a pipe object.
Definition chpipes.h:52

Static pipe initializer.

Statically initialized pipes require no explicit initialization using chPipeObjectInit().

Parameters
[in]namethe name of the pipe variable
[in]bufferpointer to the pipe buffer array of uint8_t
[in]sizenumber of uint8_t elements in the buffer array

Definition at line 126 of file chpipes.h.

Function Documentation

◆ pipe_write()

size_t pipe_write ( pipe_t * pp,
const uint8_t * bp,
size_t n )
static

Non-blocking pipe write.

The function writes data from a buffer to a pipe. The operation completes when the specified amount of data has been transferred or when the pipe buffer has been filled.

Parameters
[in]ppthe pointer to an initialized pipe_t object
[in]bppointer to the data buffer
[in]nthe maximum amount of data to be transferred, the value 0 is reserved
Returns
The number of bytes effectively transferred.
Function Class:
Not an API, this function is for internal use only.

Definition at line 105 of file chpipes.c.

References pipe_t::buffer, chPipeGetFreeCount(), pipe_t::cnt, PC_LOCK, PC_UNLOCK, pipe_t::top, and pipe_t::wrptr.

Referenced by chPipeWriteTimeout().

Here is the call graph for this function:

◆ pipe_read()

size_t pipe_read ( pipe_t * pp,
uint8_t * bp,
size_t n )
static

Non-blocking pipe read.

The function reads data from a pipe into a buffer. The operation completes when the specified amount of data has been transferred or when the pipe buffer has been emptied.

Parameters
[in]ppthe pointer to an initialized pipe_t object
[out]bppointer to the data buffer
[in]nthe maximum amount of data to be transferred, the value 0 is reserved
Returns
The number of bytes effectively transferred.
Function Class:
Not an API, this function is for internal use only.

Definition at line 156 of file chpipes.c.

References pipe_t::buffer, chPipeGetUsedCount(), pipe_t::cnt, PC_LOCK, PC_UNLOCK, pipe_t::rdptr, and pipe_t::top.

Referenced by chPipeReadTimeout().

Here is the call graph for this function:

◆ chPipeObjectInit()

void chPipeObjectInit ( pipe_t * pp,
uint8_t * buf,
size_t n )

Initializes a mailbox_t object.

Parameters
[out]ppthe pointer to the pipe_t structure to be initialized
[in]bufpointer to the pipe buffer as an array of uint8_t
[in]nnumber of elements in the buffer array
Function Class:
Object or module nitializer function.

Definition at line 207 of file chpipes.c.

References pipe_t::buffer, chDbgCheck, pipe_t::cnt, PC_INIT, PR_INIT, PW_INIT, pipe_t::rdptr, pipe_t::reset, pipe_t::rtr, pipe_t::top, pipe_t::wrptr, and pipe_t::wtr.

Referenced by chFactoryCreatePipe().

◆ chPipeReset()

void chPipeReset ( pipe_t * pp)

Resets a pipe_t object.

All the waiting threads are resumed with status MSG_RESET and the queued data is lost.

Postcondition
The pipe is in reset state, all operations will fail and return MSG_RESET until the mailbox is enabled again using chPipeResumeX().
Parameters
[in]ppthe pointer to an initialized pipe_t object
Function Class:
Normal API, this function can be invoked by regular system threads but not from within a lock zone.

Definition at line 236 of file chpipes.c.

References pipe_t::buffer, chDbgCheck, chSchRescheduleS(), chSysLock, chSysUnlock, chThdResumeI(), pipe_t::cnt, MSG_RESET, PC_LOCK, PC_UNLOCK, pipe_t::rdptr, pipe_t::reset, pipe_t::rtr, pipe_t::wrptr, and pipe_t::wtr.

Here is the call graph for this function:

◆ chPipeWriteTimeout()

size_t chPipeWriteTimeout ( pipe_t * pp,
const uint8_t * bp,
size_t n,
sysinterval_t timeout )

Pipe write with timeout.

The function writes data from a buffer to a pipe. The operation completes when the specified amount of data has been transferred or after the specified timeout or if the pipe has been reset.

Parameters
[in]ppthe pointer to an initialized pipe_t object
[in]bppointer to the data buffer
[in]nthe number of bytes to be written, the value 0 is reserved
[in]timeoutthe number of ticks before the operation timeouts, the following special values are allowed:
  • TIME_IMMEDIATE immediate timeout.
  • TIME_INFINITE no timeout.
Returns
The number of bytes effectively transferred. A number lower than n means that a timeout occurred or the pipe went in reset state.
Function Class:
Normal API, this function can be invoked by regular system threads but not from within a lock zone.

Definition at line 278 of file chpipes.c.

References chDbgCheck, chSysLock, chSysUnlock, chThdResume(), chThdSuspendTimeoutS(), MSG_OK, pipe_write(), PW_LOCK, PW_UNLOCK, pipe_t::reset, pipe_t::rtr, and pipe_t::wtr.

Here is the call graph for this function:

◆ chPipeReadTimeout()

size_t chPipeReadTimeout ( pipe_t * pp,
uint8_t * bp,
size_t n,
sysinterval_t timeout )

Pipe read with timeout.

The function reads data from a pipe into a buffer. The operation completes when the specified amount of data has been transferred or after the specified timeout or if the pipe has been reset.

Parameters
[in]ppthe pointer to an initialized pipe_t object
[out]bppointer to the data buffer
[in]nthe number of bytes to be read, the value 0 is reserved
[in]timeoutthe number of ticks before the operation timeouts, the following special values are allowed:
  • TIME_IMMEDIATE immediate timeout.
  • TIME_INFINITE no timeout.
Returns
The number of bytes effectively transferred. A number lower than n means that a timeout occurred or the pipe went in reset state.
Function Class:
Normal API, this function can be invoked by regular system threads but not from within a lock zone.

Definition at line 343 of file chpipes.c.

References chDbgCheck, chSysLock, chSysUnlock, chThdResume(), chThdSuspendTimeoutS(), MSG_OK, pipe_read(), PR_LOCK, PR_UNLOCK, pipe_t::reset, pipe_t::rtr, and pipe_t::wtr.

Here is the call graph for this function:

◆ chPipeGetSize()

size_t chPipeGetSize ( const pipe_t * pp)
inlinestatic

Returns the pipe buffer size as number of bytes.

Parameters
[in]ppthe pointer to an initialized pipe_t object
Returns
The size of the pipe.
Function Class:
Normal API, this function can be invoked by regular system threads but not from within a lock zone.

Definition at line 158 of file chpipes.h.

References pipe_t::buffer, and pipe_t::top.

Referenced by chPipeGetFreeCount().

◆ chPipeGetUsedCount()

size_t chPipeGetUsedCount ( const pipe_t * pp)
inlinestatic

Returns the number of used byte slots into a pipe.

Parameters
[in]ppthe pointer to an initialized pipe_t object
Returns
The number of queued bytes.
Function Class:
Normal API, this function can be invoked by regular system threads but not from within a lock zone.

Definition at line 174 of file chpipes.h.

References pipe_t::cnt.

Referenced by chPipeGetFreeCount(), and pipe_read().

◆ chPipeGetFreeCount()

size_t chPipeGetFreeCount ( const pipe_t * pp)
inlinestatic

Returns the number of free byte slots into a pipe.

Parameters
[in]ppthe pointer to an initialized pipe_t object
Returns
The number of empty byte slots.
Function Class:
Normal API, this function can be invoked by regular system threads but not from within a lock zone.

Definition at line 187 of file chpipes.h.

References chPipeGetSize(), and chPipeGetUsedCount().

Referenced by pipe_write().

Here is the call graph for this function:

◆ chPipeResume()

void chPipeResume ( pipe_t * pp)
inlinestatic

Terminates the reset state.

Parameters
[in]ppthe pointer to an initialized pipe_t object
Function Class:
Normal API, this function can be invoked by regular system threads but not from within a lock zone.

Definition at line 199 of file chpipes.h.

References pipe_t::reset.