2017-12-18 15:41:03 +08:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2017 Intel Corporation
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <kernel.h>
|
2018-04-06 01:11:15 +08:00
|
|
|
#include <ksched.h>
|
|
|
|
#include <wait_q.h>
|
|
|
|
#include <posix/time.h>
|
2017-12-18 15:41:03 +08:00
|
|
|
|
2018-03-19 22:25:42 +08:00
|
|
|
s64_t timespec_to_timeoutms(const struct timespec *abstime)
|
|
|
|
{
|
2018-04-30 16:42:01 +08:00
|
|
|
s64_t milli_secs, secs, nsecs;
|
2018-03-19 22:25:42 +08:00
|
|
|
struct timespec curtime;
|
|
|
|
|
|
|
|
/* FIXME: Zephyr does have CLOCK_REALTIME to get time.
|
|
|
|
* As per POSIX standard time should be calculated wrt CLOCK_REALTIME.
|
|
|
|
* Zephyr deviates from POSIX 1003.1 standard on this aspect.
|
|
|
|
*/
|
|
|
|
clock_gettime(CLOCK_MONOTONIC, &curtime);
|
|
|
|
secs = abstime->tv_sec - curtime.tv_sec;
|
|
|
|
nsecs = abstime->tv_nsec - curtime.tv_nsec;
|
|
|
|
|
|
|
|
if (secs < 0 || (secs == 0 && nsecs < NSEC_PER_MSEC)) {
|
|
|
|
milli_secs = K_NO_WAIT;
|
|
|
|
} else {
|
|
|
|
milli_secs = secs * MSEC_PER_SEC + nsecs / NSEC_PER_MSEC;
|
|
|
|
}
|
|
|
|
|
|
|
|
return milli_secs;
|
|
|
|
}
|