2018-01-17 15:39:42 +08:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2018 Intel Corporation
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*/
|
|
|
|
#ifndef __POSIX_TIME_H__
|
|
|
|
#define __POSIX_TIME_H__
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
|
|
|
struct timespec {
|
2018-02-21 18:45:26 +08:00
|
|
|
signed int tv_sec;
|
|
|
|
signed int tv_nsec;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct itimerspec {
|
|
|
|
struct timespec it_interval; /* Timer interval */
|
|
|
|
struct timespec it_value; /* Timer expiration */
|
2018-01-17 15:39:42 +08:00
|
|
|
};
|
2018-02-21 18:45:26 +08:00
|
|
|
|
2018-01-17 15:39:42 +08:00
|
|
|
#include <kernel.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include "sys/types.h"
|
2018-02-21 18:45:26 +08:00
|
|
|
#include "signal.h"
|
|
|
|
|
|
|
|
#ifndef CLOCK_REALTIME
|
|
|
|
#define CLOCK_REALTIME 0
|
|
|
|
#endif
|
2018-01-17 15:39:42 +08:00
|
|
|
|
2018-02-21 18:45:26 +08:00
|
|
|
#ifndef CLOCK_MONOTONIC
|
2018-01-17 15:39:42 +08:00
|
|
|
#define CLOCK_MONOTONIC 1
|
2018-02-21 18:45:26 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#define NSEC_PER_MSEC (NSEC_PER_USEC * USEC_PER_MSEC)
|
|
|
|
|
|
|
|
#ifndef TIMER_ABSTIME
|
|
|
|
#define TIMER_ABSTIME 4
|
|
|
|
#endif
|
2018-01-17 15:39:42 +08:00
|
|
|
|
|
|
|
static inline s32_t _ts_to_ms(const struct timespec *to)
|
|
|
|
{
|
2018-02-21 18:45:26 +08:00
|
|
|
return (to->tv_sec * MSEC_PER_SEC) + (to->tv_nsec / NSEC_PER_MSEC);
|
2018-01-17 15:39:42 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Set clock time.
|
|
|
|
*
|
|
|
|
* See IEEE 1003.1
|
|
|
|
*/
|
|
|
|
static inline int clock_settime(clockid_t clock_id, const struct timespec *ts)
|
|
|
|
{
|
|
|
|
errno = ENOSYS;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int clock_gettime(clockid_t clock_id, struct timespec *ts);
|
2018-02-21 18:45:26 +08: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);
|
2018-01-17 15:39:42 +08:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif /* __POSIX_TIME_H__ */
|