1 /* 2 * Copyright (c) 2017 Intel Corporation 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 7 #include "posix_clock.h" 8 9 #include <limits.h> 10 #include <stdint.h> 11 #include <time.h> 12 13 #include <zephyr/sys/clock.h> 14 #include <zephyr/sys/util.h> 15 timespec_to_timeoutms(int clock_id,const struct timespec * abstime)16uint32_t timespec_to_timeoutms(int clock_id, const struct timespec *abstime) 17 { 18 struct timespec curtime; 19 20 if (sys_clock_gettime(sys_clock_from_clockid(clock_id), &curtime) < 0) { 21 return 0; 22 } 23 24 return CLAMP(tp_diff(abstime, &curtime) / NSEC_PER_MSEC, 0, UINT32_MAX); 25 } 26