ChibiOS/HAL 9.0.0
Abstract Streams Interface

Detailed Description

This module define an abstract interface for generic data streams. Note that no code is present, just abstract interfaces-like structures, you should look at the system as to a set of abstract C++ classes (even if written in C). This system has then advantage to make the access to data streams independent from the implementation logic.
The stream interface can be used as base class for high level object types such as files, sockets, serial ports, pipes etc.

Collaboration diagram for Abstract Streams Interface:

Streams return codes

#define STM_OK   MSG_OK
#define STM_TIMEOUT   MSG_TIMEOUT
#define STM_RESET   MSG_RESET

Macro Functions (BaseSequentialStream)

#define streamWrite(ip, bp, n)
 Sequential Stream write.
#define streamRead(ip, bp, n)
 Sequential Stream read.
#define streamPut(ip, b)
 Sequential Stream blocking byte write.
#define streamGet(ip)
 Sequential Stream blocking byte read.

Macro Functions (BaseBufferedStream)

#define streamUnget(ip, b)
 Buffered Stream unget.

Data Structures

struct  BaseSequentialStreamVMT
 BaseSequentialStream virtual methods table. More...
struct  BaseSequentialStream
 Base stream class. More...
struct  BaseBufferedStreamVMT
 BaseBufferedStream virtual methods table. More...
struct  BaseBufferedStream
 Buffered stream class. More...

Macros

#define _base_sequential_stream_methods
 BaseSequentialStream specific methods.
#define _base_sequential_stream_data    _base_object_data
 BaseSequentialStream specific data.
#define _base_buffered_stream_methods
 BaseBufferedStream specific methods.
#define _base_buffered_stream_data    _base_sequential_stream_data
 BaseBufferedStream specific data.

Macro Definition Documentation

◆ STM_OK

#define STM_OK   MSG_OK

Definition at line 49 of file hal_streams.h.

◆ STM_TIMEOUT

#define STM_TIMEOUT   MSG_TIMEOUT

Definition at line 50 of file hal_streams.h.

◆ STM_RESET

#define STM_RESET   MSG_RESET

Definition at line 51 of file hal_streams.h.

Referenced by _unget(), bsaObjectInit(), and chvscanf().

◆ _base_sequential_stream_methods

#define _base_sequential_stream_methods
Value:
/* Stream write buffer method.*/ \
size_t (*write)(void *instance, const uint8_t *bp, size_t n); \
/* Stream read buffer method.*/ \
size_t (*read)(void *instance, uint8_t *bp, size_t n); \
/* Channel put method, blocking.*/ \
msg_t (*put)(void *instance, uint8_t b); \
/* Channel get method, blocking.*/ \
msg_t (*get)(void *instance);
#define _base_object_methods
BaseObject specific methods.
Definition hal_objects.h:39
static msg_t get(void *ip)
Definition nullstreams.c:70
static msg_t put(void *ip, uint8_t b)
Definition nullstreams.c:62

BaseSequentialStream specific methods.

Definition at line 57 of file hal_streams.h.

◆ _base_sequential_stream_data

#define _base_sequential_stream_data    _base_object_data

BaseSequentialStream specific data.

Note
It is empty because BaseSequentialStream is only an interface without implementation.

Definition at line 73 of file hal_streams.h.

◆ streamWrite

#define streamWrite ( ip,
bp,
n )
Value:
((ip)->vmt->write(ip, bp, n))

Sequential Stream write.

The function writes data from a buffer to a stream.

Parameters
[in]ippointer to a BaseSequentialStream or derived class
[in]bppointer to the data buffer
[in]nthe maximum amount of data to be transferred
Returns
The number of bytes transferred. The return value can be less than the specified number of bytes if an end-of-file condition has been met.
Function Class:
Normal API, this function can be invoked by regular system threads but not from within a lock zone.

Definition at line 113 of file hal_streams.h.

◆ streamRead

#define streamRead ( ip,
bp,
n )
Value:
((ip)->vmt->read(ip, bp, n))

Sequential Stream read.

The function reads data from a stream into a buffer.

Parameters
[in]ippointer to a BaseSequentialStream or derived class
[out]bppointer to the data buffer
[in]nthe maximum amount of data to be transferred
Returns
The number of bytes transferred. The return value can be less than the specified number of bytes if an end-of-file condition has been met.
Function Class:
Normal API, this function can be invoked by regular system threads but not from within a lock zone.

Definition at line 128 of file hal_streams.h.

◆ streamPut

#define streamPut ( ip,
b )
Value:
((ip)->vmt->put(ip, b))

Sequential Stream blocking byte write.

This function writes a byte value to a channel. If the channel is not ready to accept data then the calling thread is suspended.

Parameters
[in]ippointer to a BaseChannel or derived class
[in]bthe byte value to be written to the channel
Returns
The operation status.
Return values
STM_OKif the operation succeeded.
STM_RESETif an end-of-file condition has been met.
Function Class:
Normal API, this function can be invoked by regular system threads but not from within a lock zone.

Definition at line 144 of file hal_streams.h.

Referenced by chvprintf().

◆ streamGet

#define streamGet ( ip)
Value:
((ip)->vmt->get(ip))

Sequential Stream blocking byte read.

This function reads a byte value from a channel. If the data is not available then the calling thread is suspended.

Parameters
[in]ippointer to a BaseChannel or derived class
Returns
A byte value from the queue.
Return values
STM_RESETif an end-of-file condition has been met.
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 hal_streams.h.

Referenced by chvscanf().

◆ _base_buffered_stream_methods

#define _base_buffered_stream_methods
Value:
/* Channel unget method */ \
msg_t (*unget)(void *instance, uint8_t b);
static msg_t unget(void *ip, uint8_t b)
Definition nullstreams.c:77
#define _base_sequential_stream_methods
BaseSequentialStream specific methods.
Definition hal_streams.h:57

BaseBufferedStream specific methods.

Definition at line 164 of file hal_streams.h.

◆ _base_buffered_stream_data

#define _base_buffered_stream_data    _base_sequential_stream_data

BaseBufferedStream specific data.

Note
It is empty because BaseBufferedStream is only an interface without implementation.

Definition at line 174 of file hal_streams.h.

◆ streamUnget

#define streamUnget ( ip,
b )
Value:
((ip)->vmt->unget(ip, b))

Buffered Stream unget.

This function replaces a byte value to a stream. streamUnget only guarantees a single byte can be replaced, and multiple calls without intervening calls to streamGet or streamRead may fail

Parameters
[in]ippointer to a BaseBufferedStream or derived class
[in]bthe byte value to be written to the channel
Postcondition
Returns
The operation status.
Return values
STM_OKif the operation succeeded.
STM_RESETif the operation failed
Function Class:
Normal API, this function can be invoked by regular system threads but not from within a lock zone.

Definition at line 220 of file hal_streams.h.

Referenced by chvscanf().