Zephyr API Documentation  3.7.0
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
time.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2018 Intel Corporation
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6#ifndef ZEPHYR_INCLUDE_POSIX_TIME_H_
7#define ZEPHYR_INCLUDE_POSIX_TIME_H_
8
9/* Read standard header. This may find <posix/time.h> since they
10 * refer to the same file when include/posix is in the search path.
11 */
12#include <time.h>
13
14#ifdef CONFIG_NEWLIB_LIBC
15/* Kludge to support outdated newlib version as used in SDK 0.10 for Xtensa */
16#include <newlib.h>
17
18#ifdef __NEWLIB__
19/* Newever Newlib 3.x+ */
20#include <sys/timespec.h>
21#else /* __NEWLIB__ */
22/* Workaround for older Newlib 2.x, as used by Xtensa. It lacks sys/_timeval.h,
23 * so mimic it here.
24 */
25#include <sys/types.h>
26#ifndef __timespec_defined
27
28#ifdef __cplusplus
29extern "C" {
30#endif
31
32struct timespec {
34 long tv_nsec;
35};
36
37struct itimerspec {
38 struct timespec it_interval; /* Timer interval */
39 struct timespec it_value; /* Timer expiration */
40};
41
42#ifdef __cplusplus
43}
44#endif
45
46#endif /* __timespec_defined */
47#endif /* __NEWLIB__ */
48
49#else /* CONFIG_NEWLIB_LIBC */
50/* Not Newlib */
51# if defined(CONFIG_ARCH_POSIX) && defined(CONFIG_EXTERNAL_LIBC)
52# include <bits/types/struct_timespec.h>
53# include <bits/types/struct_itimerspec.h>
54# else
55# include <sys/timespec.h>
56# endif
57#endif /* CONFIG_NEWLIB_LIBC */
58
59#include <zephyr/kernel.h>
60#include <errno.h>
61#include "posix_types.h"
62#include <zephyr/posix/signal.h>
63
64#ifdef __cplusplus
65extern "C" {
66#endif
67
68#ifndef CLOCK_REALTIME
69#define CLOCK_REALTIME 1
70#endif
71
72#ifndef CLOCK_PROCESS_CPUTIME_ID
73#define CLOCK_PROCESS_CPUTIME_ID 2
74#endif
75
76#ifndef CLOCK_THREAD_CPUTIME_ID
77#define CLOCK_THREAD_CPUTIME_ID 3
78#endif
79
80#ifndef CLOCK_MONOTONIC
81#define CLOCK_MONOTONIC 4
82#endif
83
84#ifndef TIMER_ABSTIME
85#define TIMER_ABSTIME 4
86#endif
87
88static inline int32_t _ts_to_ms(const struct timespec *to)
89{
90 return (int32_t)(to->tv_sec * MSEC_PER_SEC) + (int32_t)(to->tv_nsec / NSEC_PER_MSEC);
91}
92
93int clock_gettime(clockid_t clock_id, struct timespec *ts);
94int clock_getres(clockid_t clock_id, struct timespec *ts);
95int clock_settime(clockid_t clock_id, const struct timespec *ts);
97/* Timer APIs */
98int timer_create(clockid_t clockId, struct sigevent *evp, timer_t *timerid);
99int timer_delete(timer_t timerid);
100int timer_gettime(timer_t timerid, struct itimerspec *its);
101int timer_settime(timer_t timerid, int flags, const struct itimerspec *value,
102 struct itimerspec *ovalue);
104int nanosleep(const struct timespec *rqtp, struct timespec *rmtp);
106 const struct timespec *rqtp, struct timespec *rmtp);
107
108#ifdef __cplusplus
109}
110#endif
111
112#else /* ZEPHYR_INCLUDE_POSIX_TIME_H_ */
113/* Read the toolchain header when <posix/time.h> finds itself on the
114 * first attempt.
115 */
116#include_next <time.h>
117#endif /* ZEPHYR_INCLUDE_POSIX_TIME_H_ */
_TIME_T_ time_t
Definition: _timespec.h:14
System error numbers.
#define MSEC_PER_SEC
number of milliseconds per second
Definition: sys_clock.h:92
#define NSEC_PER_MSEC
number of nanoseconds per millisecond
Definition: sys_clock.h:86
int timer_gettime(timer_t timerid, struct itimerspec *its)
int clock_gettime(clockid_t clock_id, struct timespec *ts)
int timer_settime(timer_t timerid, int flags, const struct itimerspec *value, struct itimerspec *ovalue)
int clock_getres(clockid_t clock_id, struct timespec *ts)
int clock_nanosleep(clockid_t clock_id, int flags, const struct timespec *rqtp, struct timespec *rmtp)
int nanosleep(const struct timespec *rqtp, struct timespec *rmtp)
int clock_getcpuclockid(pid_t pid, clockid_t *clock_id)
int timer_create(clockid_t clockId, struct sigevent *evp, timer_t *timerid)
int timer_delete(timer_t timerid)
int timer_getoverrun(timer_t timerid)
int clock_settime(clockid_t clock_id, const struct timespec *ts)
Public kernel APIs.
flags
Definition: parser.h:96
int pid_t
Definition: posix_types.h:25
unsigned long timer_t
Definition: posix_types.h:39
uint32_t clockid_t
Definition: posix_types.h:35
__INT32_TYPE__ int32_t
Definition: stdint.h:74
Definition: timespec.h:12
struct timespec it_interval
Definition: timespec.h:13
struct timespec it_value
Definition: timespec.h:14
Definition: signal.h:87
Definition: _timespec.h:22
long tv_nsec
Definition: _timespec.h:24
time_t tv_sec
Definition: _timespec.h:23