2018-01-17 08:39:42 +01:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2018 Intel Corporation
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*/
|
2018-09-14 19:43:44 +02:00
|
|
|
#ifndef ZEPHYR_INCLUDE_POSIX_TIME_H_
|
|
|
|
#define ZEPHYR_INCLUDE_POSIX_TIME_H_
|
2018-01-17 08:39:42 +01:00
|
|
|
|
2020-04-28 16:31:37 +02:00
|
|
|
/* 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>
|
|
|
|
|
2019-06-05 13:54:37 +02:00
|
|
|
#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+ */
|
lib: posix, minlibc: struct itimerspec is defined by sys/timespec.h
Newlib has it defined in sys/timespec.h, and thus per the established
conventions, everything else relies on it being there. Specifically,
minimal libc acquires sys/timespec.h with a similar definition, and
POSIX headers rely on that header. Still with a workaround for old
Newlib version as used by Xtensa (but all infrastructure for that is
already there; actually, this patch removes duplicate similar-infra,
which apparently didn't work as expected by now, so now we have a
single workaround, not 2 different once).
To emphasize a point, now there 2 headers:
sys/_timespec.h, defining struct timespec, and
sys/timespec.h, defining struct itimerspec
That's how Newlib has it, and what we faithfully embrace and follow,
because otherwise, there will be header conflicts depending on
various libc and POSIX subsys options.
Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2019-09-02 23:22:51 +02:00
|
|
|
#include <sys/timespec.h>
|
2019-08-12 19:55:06 +02:00
|
|
|
#else /* __NEWLIB__ */
|
2019-06-05 13:54:37 +02:00
|
|
|
/* 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
|
2019-08-12 19:55:06 +02:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2019-06-05 13:54:37 +02:00
|
|
|
struct timespec {
|
|
|
|
time_t tv_sec;
|
|
|
|
long tv_nsec;
|
|
|
|
};
|
2019-08-12 19:55:06 +02:00
|
|
|
|
lib: posix, minlibc: struct itimerspec is defined by sys/timespec.h
Newlib has it defined in sys/timespec.h, and thus per the established
conventions, everything else relies on it being there. Specifically,
minimal libc acquires sys/timespec.h with a similar definition, and
POSIX headers rely on that header. Still with a workaround for old
Newlib version as used by Xtensa (but all infrastructure for that is
already there; actually, this patch removes duplicate similar-infra,
which apparently didn't work as expected by now, so now we have a
single workaround, not 2 different once).
To emphasize a point, now there 2 headers:
sys/_timespec.h, defining struct timespec, and
sys/timespec.h, defining struct itimerspec
That's how Newlib has it, and what we faithfully embrace and follow,
because otherwise, there will be header conflicts depending on
various libc and POSIX subsys options.
Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2019-09-02 23:22:51 +02:00
|
|
|
struct itimerspec {
|
|
|
|
struct timespec it_interval; /* Timer interval */
|
|
|
|
struct timespec it_value; /* Timer expiration */
|
|
|
|
};
|
|
|
|
|
2019-08-12 19:55:06 +02:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
2019-06-05 13:54:37 +02:00
|
|
|
#endif
|
|
|
|
|
2019-08-12 19:55:06 +02:00
|
|
|
#endif /* __timespec_defined */
|
|
|
|
#endif /* __NEWLIB__ */
|
|
|
|
|
|
|
|
#else /* CONFIG_NEWLIB_LIBC */
|
2019-06-05 13:54:37 +02:00
|
|
|
/* Not Newlib */
|
2020-03-03 14:25:21 +01:00
|
|
|
# ifdef CONFIG_ARCH_POSIX
|
|
|
|
# include <bits/types/struct_timespec.h>
|
|
|
|
# include <bits/types/struct_itimerspec.h>
|
|
|
|
# else
|
|
|
|
# include <sys/timespec.h>
|
|
|
|
# endif
|
2019-06-05 13:54:37 +02:00
|
|
|
#endif /* CONFIG_NEWLIB_LIBC */
|
2018-02-21 11:45:26 +01:00
|
|
|
|
2018-01-17 08:39:42 +01:00
|
|
|
#include <kernel.h>
|
|
|
|
#include <errno.h>
|
2019-02-19 19:49:04 +01:00
|
|
|
#include "posix_types.h"
|
2018-10-08 23:48:26 +02:00
|
|
|
#include <posix/signal.h>
|
2018-02-21 11:45:26 +01:00
|
|
|
|
2019-08-12 19:55:06 +02:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2018-02-21 11:45:26 +01:00
|
|
|
#ifndef CLOCK_REALTIME
|
2019-10-15 23:36:40 +02:00
|
|
|
#define CLOCK_REALTIME 1
|
2018-02-21 11:45:26 +01:00
|
|
|
#endif
|
2018-01-17 08:39:42 +01:00
|
|
|
|
2018-02-21 11:45:26 +01:00
|
|
|
#ifndef CLOCK_MONOTONIC
|
2019-10-15 23:36:40 +02:00
|
|
|
#define CLOCK_MONOTONIC 4
|
2018-02-21 11:45:26 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#define NSEC_PER_MSEC (NSEC_PER_USEC * USEC_PER_MSEC)
|
|
|
|
|
|
|
|
#ifndef TIMER_ABSTIME
|
|
|
|
#define TIMER_ABSTIME 4
|
|
|
|
#endif
|
2018-01-17 08:39:42 +01:00
|
|
|
|
2020-05-27 18:26:57 +02:00
|
|
|
static inline int32_t _ts_to_ms(const struct timespec *to)
|
2018-01-17 08:39:42 +01:00
|
|
|
{
|
2018-02-21 11:45:26 +01:00
|
|
|
return (to->tv_sec * MSEC_PER_SEC) + (to->tv_nsec / NSEC_PER_MSEC);
|
2018-01-17 08:39:42 +01:00
|
|
|
}
|
|
|
|
|
2020-03-24 08:10:56 +01:00
|
|
|
#ifdef CONFIG_ARCH_POSIX
|
2018-01-17 08:39:42 +01:00
|
|
|
int clock_gettime(clockid_t clock_id, struct timespec *ts);
|
2020-03-24 08:10:56 +01:00
|
|
|
#else
|
|
|
|
__syscall int clock_gettime(clockid_t clock_id, struct timespec *ts);
|
|
|
|
#endif /* CONFIG_ARCH_POSIX */
|
2018-06-26 00:43:54 +02:00
|
|
|
int clock_settime(clockid_t clock_id, const struct timespec *ts);
|
2018-02-21 11:45:26 +01:00
|
|
|
/* 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);
|
2020-05-23 12:09:28 +02:00
|
|
|
int nanosleep(const struct timespec *rqtp, struct timespec *rmtp);
|
2018-01-17 08:39:42 +01:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2020-03-24 08:10:56 +01:00
|
|
|
#ifndef CONFIG_ARCH_POSIX
|
|
|
|
#include <syscalls/time.h>
|
|
|
|
#endif /* CONFIG_ARCH_POSIX */
|
|
|
|
|
2020-04-28 16:31:37 +02:00
|
|
|
#else /* ZEPHYR_INCLUDE_POSIX_TIME_H_ */
|
|
|
|
/* Read the toolchain header when <posix/time.h> finds itself on the
|
|
|
|
* first attempt.
|
|
|
|
*/
|
|
|
|
#include_next <time.h>
|
2018-09-14 19:43:44 +02:00
|
|
|
#endif /* ZEPHYR_INCLUDE_POSIX_TIME_H_ */
|