From e812ee6c213143fdc94c20de1b8d26db38cd0cc0 Mon Sep 17 00:00:00 2001 From: Peter Bigot Date: Tue, 18 Aug 2020 14:03:13 -0500 Subject: [PATCH] shell: support floating point output with newlib shell_fprintf requires that formatted output be emitted with a putchar()-like output function. Newlib does not provide such a capability. Zephyr provides two solutions: z_prf() which is part of minimal libc and handles floating point formatting, and z_vprintk() which is core and does not support floating point. Move z_prf() out of minimal libc into the core lib area, and use it unconditionally in the shell. Signed-off-by: Peter Bigot --- lib/libc/minimal/CMakeLists.txt | 1 - lib/os/CMakeLists.txt | 3 +++ lib/{libc/minimal/source/stdout => os}/prf.c | 0 subsys/shell/shell_fprintf.c | 9 --------- 4 files changed, 3 insertions(+), 10 deletions(-) rename lib/{libc/minimal/source/stdout => os}/prf.c (100%) diff --git a/lib/libc/minimal/CMakeLists.txt b/lib/libc/minimal/CMakeLists.txt index 036a4f139c0..2eeffadeac1 100644 --- a/lib/libc/minimal/CMakeLists.txt +++ b/lib/libc/minimal/CMakeLists.txt @@ -14,7 +14,6 @@ zephyr_library_sources( source/string/strstr.c source/string/string.c source/string/strspn.c - source/stdout/prf.c source/stdout/stdout_console.c source/stdout/sprintf.c source/stdout/fprintf.c diff --git a/lib/os/CMakeLists.txt b/lib/os/CMakeLists.txt index 8b3cd1bbdfc..c19cc83cf2b 100644 --- a/lib/os/CMakeLists.txt +++ b/lib/os/CMakeLists.txt @@ -23,6 +23,9 @@ zephyr_sources( heap-validate.c ) +zephyr_sources_ifdef(CONFIG_MINIMAL_LIBC prf.c) +zephyr_sources_ifdef(CONFIG_SHELL prf.c) + zephyr_sources_ifdef(CONFIG_JSON_LIBRARY json.c) zephyr_sources_ifdef(CONFIG_RING_BUFFER ring_buffer.c) diff --git a/lib/libc/minimal/source/stdout/prf.c b/lib/os/prf.c similarity index 100% rename from lib/libc/minimal/source/stdout/prf.c rename to lib/os/prf.c diff --git a/subsys/shell/shell_fprintf.c b/subsys/shell/shell_fprintf.c index 1f6e8b0b165..5f59ea57e8e 100644 --- a/subsys/shell/shell_fprintf.c +++ b/subsys/shell/shell_fprintf.c @@ -7,12 +7,7 @@ #include #include -#ifdef CONFIG_NEWLIB_LIBC -typedef int (*out_func_t)(int c, void *ctx); -extern void z_vprintk(out_func_t out, void *ctx, const char *fmt, va_list ap); -#else extern int z_prf(int (*func)(), void *dest, char *format, va_list vargs); -#endif static int out_func(int c, void *ctx) { @@ -39,11 +34,7 @@ static int out_func(int c, void *ctx) void shell_fprintf_fmt(const struct shell_fprintf *sh_fprintf, const char *fmt, va_list args) { -#if !defined(CONFIG_NEWLIB_LIBC) && !defined(CONFIG_ARCH_POSIX) (void)z_prf(out_func, (void *)sh_fprintf, (char *)fmt, args); -#else - z_vprintk(out_func, (void *)sh_fprintf, fmt, args); -#endif if (sh_fprintf->ctrl_blk->autoflush) { shell_fprintf_buffer_flush(sh_fprintf);