1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00
19250: sys/fmt: use `fflush(); stdio_write()` instead of `fwrite()` r=benpicco a=kaspar030



19260: sys/stdio: mark stdio_tinyusb_cdc_acm as buffered r=benpicco a=benpicco





Co-authored-by: Kaspar Schleiser <kaspar@schleiser.de>
Co-authored-by: Benjamin Valentin <benjamin.valentin@bht-berlin.de>
This commit is contained in:
bors[bot] 2023-02-07 22:28:43 +00:00 committed by GitHub
commit 5bdf2d38dc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 18 deletions

View File

@ -82,7 +82,7 @@ endif
# enable stdout buffering for modules that benefit from sending out buffers in larger chunks
ifneq (,$(filter picolibc,$(USEMODULE)))
ifneq (,$(filter stdio_cdc_acm stdio_ethos slipdev_stdio stdio_semihosting,$(USEMODULE)))
ifneq (,$(filter stdio_cdc_acm stdio_ethos slipdev_stdio stdio_semihosting stdio_tinyusb_cdc_acm,$(USEMODULE)))
USEMODULE += picolibc_stdout_buffered
endif
endif

View File

@ -27,6 +27,7 @@
#include "kernel_defines.h"
#include "fmt.h"
#include "stdio_base.h"
static const char _hex_chars[16] = "0123456789ABCDEF";
@ -506,25 +507,24 @@ uint32_t scn_u32_hex(const char *str, size_t n)
return res;
}
/* native gets special treatment as native's stdio code is ... special.
* And when not building for RIOT, there's no `stdio_write()`.
* In those cases, just defer to `printf()`.
*/
#if IS_USED(MODULE_STDIO_NATIVE) || !defined(RIOT_VERSION)
void print(const char *s, size_t n)
{
if (IS_USED(MODULE_STDIO_NATIVE)) {
/* native gets special treatment as native's stdio code is ...
* special */
printf("%.*s", (int)n, s);
return;
}
while (n > 0) {
ssize_t written;
written = fwrite(s, 1, n, stdout);
if (written < 0) {
break;
}
n -= written;
s += written;
}
printf("%.*s", (int)n, s);
}
#else
void print(const char *s, size_t n)
{
/* flush the libc's output buffer so output is not intermingled. */
fflush(stdout);
stdio_write(s, n);
}
#endif
void print_u32_dec(uint32_t val)
{

View File

@ -26,7 +26,11 @@
#include <stdio.h>
#endif
#if MODULE_FMT
# define MIN_SIZE (THREAD_STACKSIZE_TINY)
#else
# define MIN_SIZE (THREAD_STACKSIZE_TINY + THREAD_EXTRA_STACKSIZE_PRINTF)
#endif
void print_stack_usage_metric(const char *name, void *stack, unsigned max_size)
{
@ -37,7 +41,7 @@ void print_stack_usage_metric(const char *name, void *stack, unsigned max_size)
#if MODULE_FMT
print_str("{ \"threads\": [{ \"name\": \"");
print_str(name);
print_str(", \"stack_size\": ");
print_str("\", \"stack_size\": ");
print_u32_dec(max_size);
print_str(", \"stack_used\": ");
print_u32_dec(max_size - free);