zephyr/include/zephyr/posix/time.h

118 lines
2.8 KiB
C
Raw Permalink Normal View History

/*
* Copyright (c) 2018 Intel Corporation
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef ZEPHYR_INCLUDE_POSIX_TIME_H_
#define ZEPHYR_INCLUDE_POSIX_TIME_H_
/* Read standard header. This may find <posix/time.h> since they
* refer to the same file when include/posix is in the search path.
*/
#include <time.h>
#ifdef CONFIG_NEWLIB_LIBC
/* Kludge to support outdated newlib version as used in SDK 0.10 for Xtensa */
#include <newlib.h>
#ifdef __NEWLIB__
/* Newever Newlib 3.x+ */
#include <sys/timespec.h>
#else /* __NEWLIB__ */
/* Workaround for older Newlib 2.x, as used by Xtensa. It lacks sys/_timeval.h,
* so mimic it here.
*/
#include <sys/types.h>
#ifndef __timespec_defined
#ifdef __cplusplus
extern "C" {
#endif
struct timespec {
time_t tv_sec;
long tv_nsec;
};
struct itimerspec {
struct timespec it_interval; /* Timer interval */
struct timespec it_value; /* Timer expiration */
};
#ifdef __cplusplus
}
#endif
#endif /* __timespec_defined */
#endif /* __NEWLIB__ */
#else /* CONFIG_NEWLIB_LIBC */
/* Not Newlib */
# if defined(CONFIG_ARCH_POSIX) && defined(CONFIG_EXTERNAL_LIBC)
# include <bits/types/struct_timespec.h>
# include <bits/types/struct_itimerspec.h>
# else
# include <sys/timespec.h>
# endif
#endif /* CONFIG_NEWLIB_LIBC */
#include <zephyr/kernel.h>
#include <errno.h>
#include "posix_types.h"
#include <zephyr/posix/signal.h>
#ifdef __cplusplus
extern "C" {
#endif
#ifndef CLOCK_REALTIME
#define CLOCK_REALTIME 1
#endif
#ifndef CLOCK_PROCESS_CPUTIME_ID
#define CLOCK_PROCESS_CPUTIME_ID 2
#endif
posix: timers: deprecate CONFIG_POSIX_CLOCK and TIMER The POSIX_CLOCK option does not correspond to any standard option. It was used to active features of several distinct POSIX Options and Option Groups, which complicated API and application configuration as a result. POSIX_CLOCK is being deprecated in order to ensure that Zephyr's POSIX Kconfig variables correspond to those defined in the specification, as of IEEE 1003.1-2017. Additionally, CONFIG_TIMER is being deprecated because it does not match the corresponding POSIX Option (_POSIX_TIMERS). With this deprecation, we introduce the following Kconfig options that map directly to standard POSIX Option Groups by simply removing "CONFIG_": * CONFIG_POSIX_TIMERS Similarly, we introduce the following Kconfig options that map directly to standard POSIX Options by simply removing "CONFIG": * CONFIG_POSIX_CLOCK_SELECTION * CONFIG_POSIX_CPUTIME * CONFIG_POSIX_DELAYTIMER_MAX * CONFIG_POSIX_MONOTONIC_CLOCK * CONFIG_POSIX_TIMEOUTS * CONFIG_POSIX_TIMER_MAX In order to maintain parity with the current feature set, we introduce the following Kconfig options that map directly to standard POSIX Option Groups by simply removing "CONFIG_": * CONFIG_POSIX_MULTI_PROCESS - sleep() Similarly, in order to maintain parity with the current feature set, we introduce the following additional Kconfig options that map directly to standard POSIX Options by simply removing "CONFIG": * CONFIG_XSI_SINGLE_PROCESS - gettimeofday() Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
2024-05-20 18:23:58 +02:00
#ifndef CLOCK_THREAD_CPUTIME_ID
#define CLOCK_THREAD_CPUTIME_ID 3
#endif
#ifndef CLOCK_MONOTONIC
#define CLOCK_MONOTONIC 4
#endif
#ifndef TIMER_ABSTIME
#define TIMER_ABSTIME 4
#endif
static inline int32_t _ts_to_ms(const struct timespec *to)
{
return (int32_t)(to->tv_sec * MSEC_PER_SEC) + (int32_t)(to->tv_nsec / NSEC_PER_MSEC);
}
int clock_gettime(clockid_t clock_id, struct timespec *ts);
int clock_getres(clockid_t clock_id, struct timespec *ts);
int clock_settime(clockid_t clock_id, const struct timespec *ts);
int clock_getcpuclockid(pid_t pid, clockid_t *clock_id);
/* Timer APIs */
int timer_create(clockid_t clockId, struct sigevent *evp, timer_t *timerid);
int timer_delete(timer_t timerid);
int timer_gettime(timer_t timerid, struct itimerspec *its);
int timer_settime(timer_t timerid, int flags, const struct itimerspec *value,
struct itimerspec *ovalue);
int timer_getoverrun(timer_t timerid);
int nanosleep(const struct timespec *rqtp, struct timespec *rmtp);
int clock_nanosleep(clockid_t clock_id, int flags,
const struct timespec *rqtp, struct timespec *rmtp);
#ifdef __cplusplus
}
#endif
#else /* ZEPHYR_INCLUDE_POSIX_TIME_H_ */
/* Read the toolchain header when <posix/time.h> finds itself on the
* first attempt.
*/
#include_next <time.h>
#endif /* ZEPHYR_INCLUDE_POSIX_TIME_H_ */