Skip to content

Commit

Permalink
Fixes to picolibc_interface (#1795)
Browse files Browse the repository at this point in the history
* Fixes to picolibc_interface

- Don't include bindings for tinystdio if picolibc was compiled with POSIX_IO.
- Add times() function, which seems to be missed, in the same pattern as settimeofday/gettimeofday.
  • Loading branch information
gneverov authored Nov 18, 2024
1 parent d0db378 commit d6e3fa0
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/rp2_common/pico_clib_interface/picolibc_interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <stdlib.h>
#include <unistd.h>
#include <sys/time.h>
#include <sys/times.h>

#include "pico.h"
#if LIB_PICO_STDIO
Expand Down Expand Up @@ -39,6 +40,7 @@ static int picolibc_getc(__unused FILE *file) {
#if LIB_PICO_STDIO
return stdio_getchar();
#endif
return -1;
}

static int picolibc_flush(__unused FILE *file) {
Expand Down Expand Up @@ -93,6 +95,17 @@ __weak int settimeofday(__unused const struct timeval *tv, __unused const struct
return 0;
}

__weak clock_t times(struct tms *tms) {
#if CLOCKS_PER_SEC >= 1000000
tms->tms_utime = (clock_t)(to_us_since_boot(get_absolute_time()) * (CLOCKS_PER_SEC / 1000000));
#else
tms->tms_utime = (clock_t)(to_us_since_boot(get_absolute_time()) / (1000000 / CLOCKS_PER_SEC));
#endif
tms->tms_stime = 0;
tms->tms_cutime = 0;
tms->tms_cstime = 0;
return 0;
}

void runtime_init(void) {
#ifndef NDEBUG
Expand All @@ -118,9 +131,9 @@ __weak void runtime_init_pre_core_tls_setup(void) {
// for now we just set the same global area on both cores
// note: that this is superfluous with the stock picolibc it seems, since it is itself
// using a version of __aeabi_read_tp that returns the same pointer on both cores
extern void __tls_base;
extern char __tls_base[];
extern void _set_tls(void *tls);
_set_tls(&__tls_base);
_set_tls(__tls_base);
}
#endif

Expand Down

0 comments on commit d6e3fa0

Please sign in to comment.