I/O Stream#
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 STDLIB Configuration
Enumerations#
Enumeration representing the possible types of iostream instances.
Functions#
Set the stream as default I/O Stream.
Get the default I/O Stream configured.
Configure the systemwide default stream.
Output data on a stream.
Get data from a stream.
Print a character on stream.
Print a character on stream.
Print a formated string on stream.
Print a formated string on stream.
Enumeration Documentation#
sl_iostream_type_t#
sl_iostream_type_t
Enumeration representing the possible types of iostream instances.
Enumerator | |
---|---|
SL_IOSTREAM_TYPE_SWO | SWO Instance. |
SL_IOSTREAM_TYPE_RTT | RTT Instance. |
SL_IOSTREAM_TYPE_UART | USART Instance. |
SL_IOSTREAM_TYPE_VUART | Vuart. |
SL_IOSTREAM_TYPE_DEBUG_OUTPUT | Backchannel output Instance Type. |
SL_IOSTREAM_TYPE_LOOPBACK | Loopback Instance. |
SL_IOSTREAM_TYPE_UNDEFINED | Undefined Instance Type. |
118
of file platform/service/iostream/inc/sl_iostream.h
Variable Documentation#
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.
[in] | stream | I/O Stream to set as default. |
Returns
Status result
152
of file platform/service/iostream/inc/sl_iostream.h
sl_iostream_get_default#
sl_iostream_t * sl_iostream_get_default (void )
Get the default I/O Stream configured.
N/A |
Returns
Status result
159
of file platform/service/iostream/inc/sl_iostream.h
sl_iostream_set_system_default#
sl_status_t sl_iostream_set_system_default (sl_iostream_t * stream)
Configure the systemwide default stream.
[in] | stream | I/O Stream to be used. |
Returns
Status result
169
of file platform/service/iostream/inc/sl_iostream.h
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.
[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
187
of file platform/service/iostream/inc/sl_iostream.h
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.
[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
206
of file platform/service/iostream/inc/sl_iostream.h
sl_iostream_putchar#
sl_status_t sl_iostream_putchar (sl_iostream_t * stream, char c)
Print a character on stream.
[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
223
of file platform/service/iostream/inc/sl_iostream.h
sl_iostream_getchar#
sl_status_t sl_iostream_getchar (sl_iostream_t * stream, char * c)
Print a character on stream.
[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
237
of file platform/service/iostream/inc/sl_iostream.h
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.
[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
254
of file platform/service/iostream/inc/sl_iostream.h
__attribute__#
__attribute__ ((format(printf, 2, 3)) , format, ...)
Print a formated string on stream.
[in] | 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
259
of file platform/service/iostream/inc/sl_iostream.h