Skip to content

Commit

Permalink
mbed_retarget: Add an internal class to provide basic console functio…
Browse files Browse the repository at this point in the history
…nality

The retarget code allocates an array of FileHandle* for console and file
handling (filehandles). A tiny target only needs a console (putc/getc).
There is no need for file handling.

The POSIX layer and the array of FileHandle* is not required for small
targets that only need a console ; this code is optionally compiled
out if the configuration parameter platform.stdio-minimal-console-only is
set to `"true"`.
  • Loading branch information
hugueskamba committed Oct 28, 2019
1 parent 734072f commit 51afce6
Show file tree
Hide file tree
Showing 3 changed files with 200 additions and 2 deletions.
5 changes: 5 additions & 0 deletions platform/mbed_lib.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@
"value": false
},

"stdio-minimal-console-only": {
"help": "(Applies if target.console-uart is true. Ignores stdio-buffered-serial) Creates a console for basic unbuffered I/O operations. Enable if your application does not require file handles to access the serial interface.",
"value": true
},

"stdio-baud-rate": {
"help": "(Applies if target.console-uart is true.) Baud rate for stdio",
"value": 9600
Expand Down
12 changes: 12 additions & 0 deletions platform/mbed_retarget.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ namespace mbed {
class FileHandle;
class DirHandle;

#if !(MBED_CONF_PLATFORM_STDIO_MINIMAL_CONSOLE_ONLY)
/** Targets may implement this to change stdin, stdout, stderr.
*
* If the application hasn't provided mbed_override_console, this is called
Expand Down Expand Up @@ -179,6 +180,7 @@ FileHandle *mbed_override_console(int fd);
* possible if it's not open with current implementation).
*/
FileHandle *mbed_file_handle(int fd);
#endif // !(MBED_CONF_PLATFORM_STDIO_MINIMAL_CONSOLE_ONLY)
}

typedef mbed::DirHandle DIR;
Expand Down Expand Up @@ -559,7 +561,9 @@ struct pollfd {
#if __cplusplus
extern "C" {
#endif
#if !(MBED_CONF_PLATFORM_STDIO_MINIMAL_CONSOLE_ONLY)
int open(const char *path, int oflag, ...);
#endif // !(MBED_CONF_PLATFORM_STDIO_MINIMAL_CONSOLE_ONLY)
#ifndef __IAR_SYSTEMS_ICC__ /* IAR provides fdopen itself */
#if __cplusplus
std::FILE *fdopen(int fildes, const char *mode);
Expand All @@ -576,7 +580,9 @@ extern "C" {
int fstat(int fildes, struct stat *st);
int fcntl(int fildes, int cmd, ...);
int poll(struct pollfd fds[], nfds_t nfds, int timeout);
#if !(MBED_CONF_PLATFORM_STDIO_MINIMAL_CONSOLE_ONLY)
int close(int fildes);
#endif // !(MBED_CONF_PLATFORM_STDIO_MINIMAL_CONSOLE_ONLY)
int stat(const char *path, struct stat *st);
int statvfs(const char *path, struct statvfs *buf);
DIR *opendir(const char *);
Expand All @@ -586,6 +592,12 @@ extern "C" {
long telldir(DIR *);
void seekdir(DIR *, long);
int mkdir(const char *name, mode_t n);

#if MBED_CONF_PLATFORM_STDIO_MINIMAL_CONSOLE_ONLY
ssize_t minimal_console_write(const void *buffer, size_t length);
ssize_t minimal_console_read(void *buffer, size_t length);
#endif // MBED_CONF_PLATFORM_STDIO_MINIMAL_CONSOLE_ONLY

#if __cplusplus
}; // extern "C"

Expand Down
Loading

0 comments on commit 51afce6

Please sign in to comment.