diff options
author | Dawid Niedzwiecki <dn@semihalf.com> | 2021-06-28 15:24:17 +0200 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2021-07-09 19:45:07 +0000 |
commit | 107738848df07a66ae4d7c5af8f73a98ca555224 (patch) | |
tree | c7176ca63a5111d3e5a0202b3d6da1cd95c240eb /common/printf.c | |
parent | 7dea3f0835af95710717b9370b703bdb53ce0ee3 (diff) | |
download | chrome-ec-107738848df07a66ae4d7c5af8f73a98ca555224.tar.gz |
zephyr: switch to using shell_*, not printk
Reimplement the printf functions for Zephyr to use shell_* functions
instead of printk.
The main differences are:
-UART output is buffered by the shell layer. The size of the buffer
should be adjusted per board (SHELL_BACKEND_SERIAL_TX_RING_BUFFER_SIZE)
-The shell uses non-blocking UART FIFO operations while printk waits
actively for every sent byte.
-The shell prints can not be split by the other shell prints so it
should increase the quality of the output. However the shell_* functions
can not be used in interrupts, so use printk instead which can divide
the shell output. The output may be messy for boards that have a lot
of prints in interrupts e.g. volteer.
EC uses unusual print format e.g. "%pT" to print a timestamp, so use the
CrosEC's vfnprintf function and then pass the generated string to the
shell_* print. Use the sprintf function for that purpose.
Long term, the EC codebase should switch to a usual print format,
so shell_* can be used directly and not 2 versions of vfnprintf.
This change should also help to pass tests that wait for a certain
pattern on output e.g. ECBootTime.
BUG=b:191724484, b:178033156
BRANCH=none
TEST=Verify the console output works
Signed-off-by: Dawid Niedzwiecki <dn@semihalf.com>
Change-Id: Ifaed2093ab8c43038c7d3e0ded1449a93f7f7da5
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2988194
Reviewed-by: Keith Short <keithshort@chromium.org>
Commit-Queue: Keith Short <keithshort@chromium.org>
Diffstat (limited to 'common/printf.c')
-rw-r--r-- | common/printf.c | 13 |
1 files changed, 3 insertions, 10 deletions
diff --git a/common/printf.c b/common/printf.c index 14226800b6..be06d34dd8 100644 --- a/common/printf.c +++ b/common/printf.c @@ -463,12 +463,6 @@ int vfnprintf(int (*addchar)(void *context, int c), void *context, return EC_SUCCESS; } -/* - * These symbols are already defined by the Zephyr OS kernel, and we - * don't want to use the EC implementation. - */ -#ifndef CONFIG_ZEPHYR - /* Context for snprintf() */ struct snprintf_context { char *str; @@ -494,19 +488,19 @@ static int snprintf_addchar(void *context, int c) return 0; } -int snprintf(char *str, size_t size, const char *format, ...) +int crec_snprintf(char *str, size_t size, const char *format, ...) { va_list args; int rv; va_start(args, format); - rv = vsnprintf(str, size, format, args); + rv = crec_vsnprintf(str, size, format, args); va_end(args); return rv; } -int vsnprintf(char *str, size_t size, const char *format, va_list args) +int crec_vsnprintf(char *str, size_t size, const char *format, va_list args) { struct snprintf_context ctx; int rv; @@ -525,4 +519,3 @@ int vsnprintf(char *str, size_t size, const char *format, va_list args) return (rv == EC_SUCCESS) ? (ctx.str - str) : -rv; } -#endif /* !CONFIG_ZEPHYR */ |