I/O Stream
Description
I/O Stream can be used to read/write different formats of data to various streams. The source files for I/O Stream platform software module are present under platform/services/iostream.
Overview
I/O Stream is a platform module software that provides Input/Output functionalities by creating streams. Streams are abstractions allowing a uniform way to read/write data regardless of the physical communication interface.
I/O Stream offers many interfaces, see submodules for a list of all types available and their specificities.You can load multiple streams in the project and you can select the interface that must be used at runtime.Some interface type can also be instantiated, meaning that you can have multiple instances of an interface type which will be normally bound to a hardware peripheral.
Initialization
The I/O Stream core doesn't require any initialization. Instead each stream type has their own initialization and their own configuration. See I/O Stream specific type to know more about how to initialize a stream.
Note that most stream will set itself as the default stream during their initialization. Thus the initial default stream will be the last stream initialized.
Default system-wide stream
Multiple streams can be initialized in your application and you can configure a default stream that must be used when no stream is specified. Also note that the default stream will be used when calling printf and you can change the default stream at runtime. The following defines should be used for the default stream:
SL_IOSTREAM_STDIN SL_IOSTREAM_STDOUT SL_IOSTREAM_STDERR
RTOS - Task's default stream
In the case of an RTOS environment, each task can set its own stream. By default, the task stream will be set to the system_wide default stream. From your task, you can change the default stream assigned to your task without affecting the other tasks' stream.
Printf
I/O Stream provides third-party printf integrations. It can work with toolchain implementation or with the tiny printf implementation for embedded system. The printf API doesn't have an argument for specifying the stream to be used, so I/O Stream provides a printf API that takes a stream as an argument and calls the configured third-party implementation of printf.
Modules |
|
I/O Stream CPC | |
I/O Stream CPC.
|
|
I/O Stream EUSART | |
I/O Stream EUSART.
|
|
I/O Stream LEUART | |
I/O Stream LEUART.
|
|
I/O Stream RTT | |
I/O Stream RTT.
|
|
I/O Stream STDLIB Configuration | |
I/O Stream STDLIB Configuration.
|
|
I/O Stream SWO | |
I/O Stream SWO.
|
|
I/O Stream UART | |
I/O Stream UART.
|
|
I/O Stream USART | |
I/O Stream USART.
|
|
Data Structures |
|
struct | sl_iostream_t |
Struct representing iostream operations.
|
|
struct | sl_iostream_instance_info_t |
Struct representing an I/O Stream instance.
|
|
Functions |
|
sl_status_t | sl_iostream_set_default ( sl_iostream_t *stream) |
Set the stream as default I/O Stream.
|
|
sl_iostream_t * | sl_iostream_get_default (void) |
Get the default I/O Stream configured.
|
|
sl_status_t | sl_iostream_set_system_default ( sl_iostream_t *stream) |
Configure the systemwide default stream.
|
|
sl_status_t | sl_iostream_write ( sl_iostream_t *stream, const void *buffer, size_t buffer_length) |
Output data on a stream.
|
|
sl_status_t | sl_iostream_read ( sl_iostream_t *stream, void *buffer, size_t buffer_length, size_t *bytes_read) |
Get data from a stream.
|
|
sl_status_t | sl_iostream_putchar ( sl_iostream_t *stream, char c) |
Print a character on stream.
|
|
sl_status_t | sl_iostream_getchar ( sl_iostream_t *stream, char *c) |
Print a character on stream.
|
|
sl_status_t | sl_iostream_vprintf ( sl_iostream_t *stream, const char *format, va_list argp) |
Print a formated string on stream.
|
|
__attribute__ ((format(printf, 2, 3))) sl_status_t sl_iostream_printf( sl_iostream_t *stream | |
Print a formated string on stream.
|
|
Enumerations |
|
enum |
sl_iostream_type_t
{
SL_IOSTREAM_TYPE_SWO = 0, SL_IOSTREAM_TYPE_RTT = 1, SL_IOSTREAM_TYPE_UART = 2, SL_IOSTREAM_TYPE_VUART = 3, SL_IOSTREAM_TYPE_DEBUG_OUTPUT = 4, SL_IOSTREAM_TYPE_LOOPBACK = 5, SL_IOSTREAM_TYPE_UNDEFINED = 6 } |
Enumeration representing the possible types of iostream instances.
|
|
Variables |
|
const char * | format |
Function Documentation
◆ sl_iostream_set_default()
sl_status_t sl_iostream_set_default | ( | sl_iostream_t * |
stream
|
) |
Set the stream as default I/O Stream.
- Parameters
-
[in] stream
I/O Stream to set as default.
- Returns
- Status result
◆ sl_iostream_get_default()
sl_iostream_t * sl_iostream_get_default | ( | void |
|
) |
Get the default I/O Stream configured.
- Returns
- Status result
◆ sl_iostream_set_system_default()
sl_status_t sl_iostream_set_system_default | ( | sl_iostream_t * |
stream
|
) |
Configure the systemwide default stream.
- Parameters
-
[in] stream
I/O Stream to be used.
- Returns
- Status result
◆ sl_iostream_write()
sl_status_t sl_iostream_write | ( | sl_iostream_t * |
stream,
|
const void * |
buffer,
|
||
size_t |
buffer_length
|
||
) |
Output data on a stream.
- Parameters
-
[in] stream
I/O Stream to be used. SL_IOSTREAM_STDOUT; Default output stream will be used. Pointer to specific stream; Specific stream will be used. [in] buffer
Buffer that contains the data to output. [in] buffer_length
Data length contained in the buffer.
- Returns
- Status result
◆ sl_iostream_read()
sl_status_t sl_iostream_read | ( | sl_iostream_t * |
stream,
|
void * |
buffer,
|
||
size_t |
buffer_length,
|
||
size_t * |
bytes_read
|
||
) |
Get data from a stream.
- Parameters
-
[in] stream
I/O Stream to be used. SL_IOSTREAM_STDOUT; Default output stream will be used. Pointer to specific stream; Specific stream will be used. [out] buffer
Buffer that contains the data to output. [in] buffer_length
Data length contained in the buffer. [out] bytes_read
Data length copied to the buffer.
- Returns
- Status result
◆ sl_iostream_putchar()
sl_status_t sl_iostream_putchar | ( | sl_iostream_t * |
stream,
|
char |
c
|
||
) |
Print a character on stream.
- Parameters
-
[in] stream
I/O Stream to be used: SL_IOSTREAM_STDOUT; Default output stream will be used. SL_IOSTREAM_STDERR; Default error output stream will be used. Pointer to specific stream; Specific stream will be used. [in] c
Character to print
- Returns
- Status result
◆ sl_iostream_getchar()
sl_status_t sl_iostream_getchar | ( | sl_iostream_t * |
stream,
|
char * |
c
|
||
) |
Print a character on stream.
- Parameters
-
[in] stream
I/O Stream to be used. SL_IOSTREAM_STDIN; Default input stream will be used. Pointer to specific stream; Specific stream will be used. [out] c
Pointer to variable that will receive the character.
- Returns
- Status result
◆ sl_iostream_vprintf()
sl_status_t sl_iostream_vprintf | ( | sl_iostream_t * |
stream,
|
const char * |
format,
|
||
va_list |
argp
|
||
) |
Print a formated string on stream.
- Parameters
-
[in] stream
I/O Stream to be used: SL_IOSTREAM_STDOUT; Default output stream will be used. SL_IOSTREAM_STDERR; Default error output stream will be used. Pointer to specific stream; Specific stream will be used. [in] format
String that contains the text to be written. [in] argp
A value identifying a variable arguments list.
- Returns
- Status result
◆ __attribute__()
__attribute__ | ( | (format(printf, 2, 3)) |
|
) |
Print a formated string on stream.
- Parameters
-
[in] stream
I/O Stream to be used: SL_IOSTREAM_STDOUT; Default output stream will be used. SL_IOSTREAM_STDERR; Default error output stream will be used. Pointer to specific stream; Specific stream will be used. [in] format
String that contains the text to be written. [in] ...
Additional arguments.
- Returns
- Status result
Enumeration Type Documentation
◆ sl_iostream_type_t
enum sl_iostream_type_t |
Enumeration representing the possible types of iostream instances.