Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: TYBLE16_simple_data_logger TYBLE16_MP3_Air
Fnet_serial
Data Structures | |
struct | fnet_serial_stream |
Stream control structure. More... | |
Typedefs | |
typedef struct fnet_serial_stream * | fnet_serial_stream_t |
Serial stream descriptor. | |
Functions | |
void | fnet_serial_putchar (fnet_serial_stream_t stream, fnet_char_t character) |
Writes character to the stream. | |
fnet_int32_t | fnet_serial_getchar (fnet_serial_stream_t stream) |
Reads character from the stream. | |
void | fnet_serial_flush (fnet_serial_stream_t stream) |
Sends data from the internal stream buffer to the stream client. | |
void | fnet_putchar (fnet_char_t character) |
Writes character to the default stream. | |
fnet_int32_t | fnet_getchar (void) |
Reads character from the default stream. | |
fnet_size_t | fnet_serial_printf (fnet_serial_stream_t stream, const fnet_char_t *format,...) |
Prints formatted text to the stream. | |
fnet_size_t | fnet_serial_vprintf (fnet_serial_stream_t stream, const fnet_char_t *format, va_list arg) |
Prints formatted variable argument list to the stream. | |
fnet_size_t | fnet_printf (const fnet_char_t *format,...) |
Prints formatted text to the default stream. | |
fnet_size_t | fnet_println (const fnet_char_t *format,...) |
Prints formatted text to the default stream and terminates the printed text by the line separator string. | |
fnet_size_t | fnet_sprintf (fnet_char_t *str, const fnet_char_t *format,...) |
Prints formatted text to the buffer. | |
fnet_size_t | fnet_snprintf (fnet_char_t *str, fnet_size_t size, const fnet_char_t *format,...) |
Prints formatted text to the buffer. The length of the buffer is given, that prevents the buffer overflows. |
Detailed Description
The Serial Input/Output (I/O) library provides commonly used I/O functions like printf(), putchar() and getchar().
It uses stream abstraction to allow reading and writing data in an uniform way. There are three standard streams allocated automatically that are associated with physical serial ports (one per UART module).
For the serial library usage example, refer to FNET demo application source code.
NOTE: The HW serial ports associated with I/O streams are not initialized by the serial library and should be initialized by the application. It can be inialized by the fnet_cpu_serial_init() function.
Configuration parameters:
- FNET_CFG_SERIAL_PRINTF_N_TO_RN
Typedef Documentation
typedef struct fnet_serial_stream* fnet_serial_stream_t |
Serial stream descriptor.
Definition at line 131 of file fnet_serial.h.
Function Documentation
fnet_int32_t fnet_getchar | ( | void | ) |
Reads character from the default stream.
- Returns:
- This function returns:
- character from the default stream.
- FNET_ERR if no character is available in the default stream.
- See also:
- fnet_putchar()
This function reads a single character from the default stream.
If no character is available in the stream the FNET_ERR is returned.
fnet_size_t fnet_printf | ( | const fnet_char_t * | format, |
... | |||
) |
Prints formatted text to the default stream.
- Parameters:
-
format Format string.
- Returns:
- This function returns the number of characters that were successfully written, excluding the trailing null.
- See also:
- fnet_sprintf()
This function outputs formatted text to the default stream, its descriptor is defined by FNET_SERIAL_STREAM_DEFAULT.
The function takes one or more arguments. The first argument is a string parameter called the "format string". The optional arguments following format
are items (integers, characters or strings) that are to be converted to character strings and inserted into the output of format
at specified placeholders. The number of arguments following the format
parameters should at least be as much as the number of format placeholders.
The syntax for a format placeholder is "%[Flags][Width][Length]Type".
- Flags can be omitted or be any of:
-
: Left justify.+
: Right justify.0
: Pad with leading zeros.- space : Print space if no sign.
- Width is minimum field width. It can be omitted.
- Length is conversion character. It can be omitted or by any of:
h
: Short integer.l
: Long integer.
- Type can by any of:
d
,i
: Integer.u
: Unsigned.x
,X
: Hexadecimal.o
: Octal.b
: Binary.p
: Pointer.c
: Single char.s
: Char string.n
: Nothing.
- Note:
- To save some bytes from all the hard coded strings the fnet_(s)printf() functions will expand all line feeds ("\n") inside the format string to CR LF ("\r\n"). So do not use "\r\n" in the format string - it will be expanded to "\r\r\n". It is save to add it via a parameter though, e.g. fnet_printf("%s", "\r\n");
This feature can be disable/enabled by the FNET_CFG_SERIAL_PRINTF_N_TO_RN configuration parameter.
fnet_size_t fnet_println | ( | const fnet_char_t * | format, |
... | |||
) |
Prints formatted text to the default stream and terminates the printed text by the line separator string.
- Parameters:
-
format Format string.
- Returns:
- This function returns the number of characters that were successfully written, excluding the trailing null.
- See also:
- fnet_sprintf()
This function outputs formatted text to the default stream and terminates the printed text by the line separator string. Its descriptor is defined by FNET_SERIAL_STREAM_DEFAULT.
The function takes one or more arguments. The first argument is a string parameter called the "format string". The optional arguments following format
are items (integers, characters or strings) that are to be converted to character strings and inserted into the output of format
at specified placeholders. The number of arguments following the format
parameters should at least be as much as the number of format placeholders.
The syntax for a format placeholder is "%[Flags][Width][Length]Type".
- Flags can be omitted or be any of:
-
: Left justify.+
: Right justify.0
: Pad with leading zeros.- space : Print space if no sign.
- Width is minimum field width. It can be omitted.
- Length is conversion character. It can be omitted or by any of:
h
: Short integer.l
: Long integer.
- Type can by any of:
d
,i
: Integer.u
: Unsigned.x
,X
: Hexadecimal.o
: Octal.b
: Binary.p
: Pointer.c
: Single char.s
: Char string.n
: Nothing.
- Note:
- To save some bytes from all the hard coded strings the fnet_(s)printf() functions will expand all line feeds ("\n") inside the format string to CR LF ("\r\n"). So do not use "\r\n" in the format string - it will be expanded to "\r\r\n". It is save to add it via a parameter though, e.g. fnet_printf("%s", "\r\n");
This feature can be disable/enabled by the FNET_CFG_SERIAL_PRINTF_N_TO_RN configuration parameter.
void fnet_putchar | ( | fnet_char_t | character ) |
Writes character to the default stream.
- Parameters:
-
character Character to be written.
- See also:
- fnet_getchar()
This function writes a single character
to the default stream.
void fnet_serial_flush | ( | fnet_serial_stream_t | stream ) |
Sends data from the internal stream buffer to the stream client.
- Parameters:
-
stream Stream descriptor.
This function immediately sends data from the internal stream buffer to the stream client.
If you do not explicitly call the flush function, stream sends data to the client after the internal buffer is full.
The function only has meaning for buffered streams.
UART stream does not have internal buffer and does not use this flush function.
fnet_int32_t fnet_serial_getchar | ( | fnet_serial_stream_t | stream ) |
Reads character from the stream.
- Parameters:
-
stream Stream descriptor.
- Returns:
- This function returns:
- character from the stream.
- FNET_ERR if no character is available in the stream.
- See also:
- fnet_serial_putchar()
This function reads a single character from the stream.
If no character is available in the stream the FNET_ERR is returned.
fnet_size_t fnet_serial_printf | ( | fnet_serial_stream_t | stream, |
const fnet_char_t * | format, | ||
... | |||
) |
Prints formatted text to the stream.
- Parameters:
-
stream Stream descriptor. format Format string.
- Returns:
- This function returns the number of characters that were successfully written, excluding the trailing null.
- See also:
- fnet_serial_putchar(), fnet_serial_vprintf()
This function outputs formatted text to the stream
.
The function takes one or more arguments. The first argument is a string parameter called the "format string". The optional arguments following format
are items (integers, characters or strings) that are to be converted to character strings and inserted into the output of format
at specified placeholders. The number of arguments following the format
parameters should at least be as much as the number of format placeholders.
The syntax for a format placeholder is "%[Flags][Width][Length]Type".
- Flags can be omitted or be any of:
-
: Left justify.+
: Right justify.0
: Pad with leading zeros.- space : Print space if no sign.
- Width is minimum field width. It can be omitted.
- Length is conversion character. It can be omitted or by any of:
h
: Short integer.l
: Long integer.
- Type can by any of:
d
,i
: Integer.u
: Unsigned.x
,X
: Hexadecimal.o
: Octal.b
: Binary.p
: Pointer.c
: Single char.s
: Char string.n
: Nothing.
- Note:
- To save some bytes from all the hard coded strings the fnet_(s)printf() functions will expand all line feeds ("\n") inside the format string to CR LF ("\r\n"). So do not use "\r\n" in the format string - it will be expanded to "\r\r\n". It is save to add it via a parameter though, e.g. fnet_printf("%s", "\r\n");
This feature can be disable/enabled by the FNET_CFG_SERIAL_PRINTF_N_TO_RN configuration parameter.
void fnet_serial_putchar | ( | fnet_serial_stream_t | stream, |
fnet_char_t | character | ||
) |
Writes character to the stream.
- Parameters:
-
stream Stream descriptor. character Character to be written.
- See also:
- fnet_serial_getchar()
This function writes a single character
to the stream.
fnet_size_t fnet_serial_vprintf | ( | fnet_serial_stream_t | stream, |
const fnet_char_t * | format, | ||
va_list | arg | ||
) |
Prints formatted variable argument list to the stream.
- Parameters:
-
stream Stream descriptor. format Format string. arg Variable arguments list. It shall have been initialized by va_start()
macro
- Returns:
- This function returns the number of characters that were successfully written, excluding the trailing null.
- See also:
- fnet_serial_printf()
This function outputs formatted text to the stream
, expanding the format placeholders with the value of the argument list arg
.
This function behaves exactly as printf
except that the variable argument list is passed as a va_list
instead of a succession of arguments, which becomes specially useful when the argument list to be passed comes itself from a variable argument list in the calling function.
The syntax for a format placeholder is "%[Flags][Width][Length]Type".
- Flags can be omitted or be any of:
-
: Left justify.+
: Right justify.0
: Pad with leading zeros.- space : Print space if no sign.
- Width is minimum field width. It can be omitted.
- Length is conversion character. It can be omitted or by any of:
h
: Short integer.l
: Long integer.
- Type can by any of:
d
,i
: Integer.u
: Unsigned.x
,X
: Hexadecimal.o
: Octal.b
: Binary.p
: Pointer.c
: Single char.s
: Char string.n
: Nothing.
- Note:
- To save some bytes from all the hard coded strings the fnet_(s)printf() functions will expand all line feeds ("\n") inside the format string to CR LF ("\r\n"). So do not use "\r\n" in the format string - it will be expanded to "\r\r\n". It is save to add it via a parameter though, e.g. fnet_printf("%s", "\r\n");
This feature can be disable/enabled by the FNET_CFG_SERIAL_PRINTF_N_TO_RN configuration parameter.
fnet_size_t fnet_snprintf | ( | fnet_char_t * | str, |
fnet_size_t | size, | ||
const fnet_char_t * | format, | ||
... | |||
) |
Prints formatted text to the buffer. The length of the buffer is given, that prevents the buffer overflows.
- Parameters:
-
str Pointer to buffer where the resulting string is stored. size Maximum number of characters to produce. The trailing null character is counted towards this limit format Format string.
- Returns:
- This function returns the number of characters that were successfully written, excluding the trailing null.
- See also:
- fnet_sprintf()
This function is just like fnet_sprintf(), except that the length of the buffer is given. This prevents buffer overflows.
The format
string contains the text to be written to the str
buffer. The optional arguments following format
are items (integers, characters or strings) that are to be converted to character strings and inserted into the output of format
at specified placeholders. The number of arguments following the format
parameters should at least be as much as the number of format placeholders.
The syntax for a format placeholder is "%[Flags][Width][Length]Type".
- Flags can be omitted or be any of:
-
: Left justify.+
: Right justify.0
: Pad with leading zeros.- space : Print space if no sign.
- Width is minimum field width. It can be omitted.
- Length is conversion character. It can be omitted or by any of:
h
: Short integer.l
: Long integer.
- Type can by any of:
d
,i
: Integer.u
: Unsigned.x
,X
: Hexadecimal.o
: Octal.b
: Binary.p
: Pointer.c
: Single char.s
: Char string.n
: Nothing.
- Note:
- To save some bytes from all the hard coded strings the fnet_(s)printf() functions will expand all line feeds ("\n") inside the format string to CR LF ("\r\n"). So do not use "\r\n" in the format string - it will be expanded to "\r\r\n". It is save to add it via a parameter though, e.g. fnet_printf("%s", "\r\n");
This feature can be disable/enabled by the FNET_CFG_SERIAL_PRINTF_N_TO_RN configuration parameter.
fnet_size_t fnet_sprintf | ( | fnet_char_t * | str, |
const fnet_char_t * | format, | ||
... | |||
) |
Prints formatted text to the buffer.
- Parameters:
-
str Pointer to buffer where the resulting string is stored. format Format string.
- Returns:
- This function returns the number of characters that were successfully written, excluding the trailing null.
- See also:
- fnet_snprintf()
The format
string contains the text to be written to the str
buffer. The optional arguments following format
are items (integers, characters or strings) that are to be converted to character strings and inserted into the output of format
at specified placeholders. The number of arguments following the format
parameters should at least be as much as the number of format placeholders.
The syntax for a format placeholder is "%[Flags][Width][Length]Type".
- Flags can be omitted or be any of:
-
: Left justify.+
: Right justify.0
: Pad with leading zeros.- space : Print space if no sign.
- Width is minimum field width. It can be omitted.
- Length is conversion character. It can be omitted or by any of:
h
: Short integer.l
: Long integer.
- Type can by any of:
d
,i
: Integer.u
: Unsigned.x
,X
: Hexadecimal.o
: Octal.b
: Binary.p
: Pointer.c
: Single char.s
: Char string.n
: Nothing.
The fnet_sprintf() function is just like fnet_printf(), except that the output is sent to buffer.
This function does not check the bounds of the buffer and therefore creates the risk of a buffer overflow. It is recommended to use fnet_snprintf() that doesn't suffer from buffer overruns.
- Note:
- To save some bytes from all the hard coded strings the fnet_(s)printf() functions will expand all line feeds ("\n") inside the format string to CR LF ("\r\n"). So do not use "\r\n" in the format string - it will be expanded to "\r\r\n". It is save to add it via a parameter though, e.g. fnet_printf("%s", "\r\n");
This feature can be disable/enabled by the FNET_CFG_SERIAL_PRINTF_N_TO_RN configuration parameter.
Generated on Tue Jul 12 2022 13:55:26 by
