mirror of
https://github.com/espressif/esp-idf.git
synced 2026-10-02 11:10:54 +03:00
fix(esp_libc): provide picolibc timespec_get
The Picolibc headers in the ESP-IDF v6.0 toolchain declare the C11 timespec_get API, but the corresponding archives do not define it. Provide the missing compatibility implementation through esp_libc and cover valid and invalid time bases.
This commit is contained in:
@@ -77,6 +77,7 @@ else()
|
|||||||
list(APPEND srcs
|
list(APPEND srcs
|
||||||
"src/picolibc/picolibc_init.c"
|
"src/picolibc/picolibc_init.c"
|
||||||
"src/picolibc/rand.c"
|
"src/picolibc/rand.c"
|
||||||
|
"src/picolibc/timespec_get.c"
|
||||||
"src/picolibc/open_memstream.c"
|
"src/picolibc/open_memstream.c"
|
||||||
"src/picolibc/errno.c"
|
"src/picolibc/errno.c"
|
||||||
"src/picolibc/bufio_setvbuf.c") # TODO IDF-15494: remove this and the following lines
|
"src/picolibc/bufio_setvbuf.c") # TODO IDF-15494: remove this and the following lines
|
||||||
|
|||||||
@@ -0,0 +1,15 @@
|
|||||||
|
/*
|
||||||
|
* SPDX-FileCopyrightText: 2026 Espressif Systems (Shanghai) CO LTD
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <time.h>
|
||||||
|
|
||||||
|
int timespec_get(struct timespec *ts, int base)
|
||||||
|
{
|
||||||
|
if (base != TIME_UTC || clock_gettime(CLOCK_REALTIME, ts) < 0) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return base;
|
||||||
|
}
|
||||||
@@ -548,6 +548,17 @@ TEST_CASE("test posix_timers clock_... functions", "[newlib]")
|
|||||||
test_posix_timers_clock();
|
test_posix_timers_clock();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_CASE("timespec_get returns UTC time", "[newlib]")
|
||||||
|
{
|
||||||
|
struct timespec ts = {0};
|
||||||
|
|
||||||
|
TEST_ASSERT_EQUAL_INT(TIME_UTC, timespec_get(&ts, TIME_UTC));
|
||||||
|
TEST_ASSERT_GREATER_OR_EQUAL_INT64(0, ts.tv_sec);
|
||||||
|
TEST_ASSERT_GREATER_OR_EQUAL_INT32(0, ts.tv_nsec);
|
||||||
|
TEST_ASSERT_LESS_THAN_INT32(1000000000L, ts.tv_nsec);
|
||||||
|
TEST_ASSERT_EQUAL_INT(0, timespec_get(&ts, -1));
|
||||||
|
}
|
||||||
|
|
||||||
#define TEST_USE_CPU_CYCLES 1
|
#define TEST_USE_CPU_CYCLES 1
|
||||||
#if TEST_USE_CPU_CYCLES && CONFIG_ESP_SYSTEM_SINGLE_CORE_MODE
|
#if TEST_USE_CPU_CYCLES && CONFIG_ESP_SYSTEM_SINGLE_CORE_MODE
|
||||||
#include "esp_cpu.h"
|
#include "esp_cpu.h"
|
||||||
|
|||||||
Reference in New Issue
Block a user