10#ifndef STK_C_TIME_POSIX_H_
11#define STK_C_TIME_POSIX_H_
35#ifndef _SYS__PTHREADTYPES_H_
36 #define _SYS__PTHREADTYPES_H_
37 #define STK_C_PTHREADTYPES_GUARD
40#ifndef STK_C_SYSTEM_TIME_H
41 #if defined(__GNUC__) || defined(__clang__)
42 #include_next <time.h>
44 #error "Define STK_C_SYSTEM_TIME_H to the toolchain's time.h (e.g. <../inc/c/time.h>) for this compiler"
47 #include STK_C_SYSTEM_TIME_H
57#if defined(__NEWLIB__) || defined(__GLIBC__)
58 #ifndef STK_C_NO_TIMER_T
59 #define STK_C_NO_TIMER_T
61 #ifndef STK_C_NO_ITIMERSPEC
62 #define STK_C_NO_ITIMERSPEC
65 #ifndef STK_C_DEFINE_SIGEVENT
66 #define STK_C_DEFINE_SIGEVENT (0)
69#if defined(_SYS_TIMESPEC_H) && !defined(STK_C_NO_ITIMERSPEC)
70 #define STK_C_NO_ITIMERSPEC
89 #define CLOCK_REALTIME (0)
91#ifndef CLOCK_MONOTONIC
92 #define CLOCK_MONOTONIC (1)
95 #define TIMER_ABSTIME (1)
101#ifndef STK_C_NO_TIME_DECLS
114int clock_getres(clockid_t clk_id,
struct timespec *res);
125int nanosleep(
const struct timespec *req,
struct timespec *rem);
130int clock_nanosleep(clockid_t clk_id,
int flags,
const struct timespec *req,
struct timespec *rem);
134#ifndef STK_C_NO_SLEEP_DECLS
139int usleep(useconds_t usec);
144unsigned int sleep(
unsigned int seconds);
156#ifndef STK_C_NO_TIMER_T
165#ifndef STK_C_DEFINE_SIGEVENT
166 #define STK_C_DEFINE_SIGEVENT (1)
169#if STK_C_DEFINE_SIGEVENT && !defined(SIGEV_NONE)
185 #define SIGEV_NONE (0)
186 #define SIGEV_SIGNAL (1)
187 #define SIGEV_THREAD (2)
190#if !STK_C_DEFINE_SIGEVENT
195#ifndef STK_C_NO_ITIMERSPEC
206#ifndef STK_C_TIMERS_MAX
207 #define STK_C_TIMERS_MAX (8U)
225#ifndef STK_C_NO_TIMER_DECLS
int timer_settime(timer_t timerid, int flags, const struct itimerspec *new_value, struct itimerspec *old_value)
Arm (it_value != 0) or disarm (it_value == 0) a timer.
int nanosleep(const struct timespec *req, struct timespec *rem)
Suspend the calling task for a relative time (rounded UP to whole ticks). Cancellation point.
void stk_posix_set_wall_time(int64_t unix_seconds)
Set the current wall time used by time() and gettimeofday() (see sys/time.h).
int clock_nanosleep(clockid_t clk_id, int flags, const struct timespec *req, struct timespec *rem)
Suspend for a relative time or until an absolute time (flags = TIMER_ABSTIME). Cancellation point.
int clock_getres(clockid_t clk_id, struct timespec *res)
Get the resolution (one kernel tick) of a clock.
unsigned int sleep(unsigned int seconds)
Suspend for seconds seconds. Cancellation point.
int timespec_get(struct timespec *ts, int base)
C11 timespec_get(): base must be TIME_UTC (reports the same STK timeline).
void stk_posix_timer_bind_host(void *timer_host)
Provide the timer host which runs POSIX timers.
int timer_create(clockid_t clk_id, struct sigevent *sevp, timer_t *timerid)
Create a timer.
int clock_gettime(clockid_t clk_id, struct timespec *ts)
Get the current time of a clock.
int timer_gettime(timer_t timerid, struct itimerspec *curr_value)
Get the time until the next expiration and the period.
int usleep(useconds_t usec)
Suspend for usec microseconds. Cancellation point.
int timer_delete(timer_t timerid)
Delete a timer (waits until a running notification has returned).
int timer_getoverrun(timer_t timerid)
Get the overrun count. STK does not track overruns.
void * sigev_notify_attributes
void(* sigev_notify_function)(union sigval)
struct timespec it_interval