1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

Merge pull request #14840 from benpicco/picolibc_unbuffered

picolibc: only enable stdout buffering for CDC ACM, ethos, semihosting & SLIP
This commit is contained in:
benpicco 2020-09-01 15:15:01 +02:00 committed by GitHub
commit 61334d55d6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 33 additions and 3 deletions

View File

@ -86,6 +86,7 @@ PSEUDOMODULES += newlib_gnu_source
PSEUDOMODULES += newlib_nano
PSEUDOMODULES += openthread
PSEUDOMODULES += picolibc
PSEUDOMODULES += picolibc_stdout_buffered
PSEUDOMODULES += pktqueue
PSEUDOMODULES += posix_headers
PSEUDOMODULES += printf_float

View File

@ -55,3 +55,10 @@ ifneq (,$(filter stdio_semihosting,$(USEMODULE)))
USEMODULE += xtimer
FEATURES_REQUIRED += cpu_core_cortexm
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)))
USEMODULE += picolibc_stdout_buffered
endif
endif

View File

@ -165,10 +165,12 @@ int kill(pid_t pid, int sig)
#include "mutex.h"
static mutex_t picolibc_put_mutex = MUTEX_INIT;
#ifndef PICOLIBC_STDOUT_BUFSIZE
#define PICOLIBC_STDOUT_BUFSIZE 64
#endif
#ifdef MODULE_PICOLIBC_STDOUT_BUFFERED
static mutex_t picolibc_put_mutex = MUTEX_INIT;
static char picolibc_stdout[PICOLIBC_STDOUT_BUFSIZE];
static int picolibc_stdout_queued;
@ -183,10 +185,14 @@ static void _picolibc_flush(void)
static int picolibc_put(char c, FILE *file)
{
(void)file;
mutex_lock(&picolibc_put_mutex);
picolibc_stdout[picolibc_stdout_queued++] = c;
if (picolibc_stdout_queued == PICOLIBC_STDOUT_BUFSIZE || c == '\n')
if (picolibc_stdout_queued == PICOLIBC_STDOUT_BUFSIZE || c == '\n') {
_picolibc_flush();
}
mutex_unlock(&picolibc_put_mutex);
return 1;
}
@ -200,6 +206,22 @@ static int picolibc_flush(FILE *file)
return 0;
}
#else
int picolibc_put(char c, FILE *file)
{
(void)file;
stdio_write(&c, 1);
return 1;
}
static int picolibc_flush(FILE *file)
{
(void)file;
return 0;
}
#endif
static int picolibc_get(FILE *file)
{
(void)file;