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 <peter.bigot@nordicsemi.no>
This commit is contained in:
parent
1b617a368f
commit
e812ee6c21
4 changed files with 3 additions and 10 deletions
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -7,12 +7,7 @@
|
|||
#include <shell/shell_fprintf.h>
|
||||
#include <shell/shell.h>
|
||||
|
||||
#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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue