diff --git a/include/nuttx/clock.h b/include/nuttx/clock.h index f6fe114c47..31643cc24a 100644 --- a/include/nuttx/clock.h +++ b/include/nuttx/clock.h @@ -445,6 +445,36 @@ EXTERN volatile clock_t g_system_ticks; ((ts1)->tv_sec > (ts2)->tv_sec) ? 1 : \ (ts1)->tv_nsec - (ts2)->tv_nsec) +/**************************************************************************** + * Name: clock_abstime2ticks + * + * Description: + * Convert an absolute timespec delay to system timer ticks. + * + * Input Parameters: + * clockid - The timing source to use in the conversion + * abstime - Convert this absolute time to ticks + * ticks - Return the converted number of ticks here. + * + * Returned Value: + * None + * + * Assumptions: + * Interrupts should be disabled so that the time is not changing during + * the calculation + * + ****************************************************************************/ + +#define clock_abstime2ticks(clockid, abstime, ticks) \ + do \ + { \ + struct timespec _reltime; \ + nxclock_gettime(clockid, &_reltime); \ + clock_timespec_subtract(abstime, &_reltime, &_reltime); \ + *(ticks) = clock_time2ticks(&_reltime); \ + } \ + while (0) + /**************************************************************************** * Name: clock_compare * diff --git a/sched/clock/CMakeLists.txt b/sched/clock/CMakeLists.txt index a2a7a86043..b2cf2117f8 100644 --- a/sched/clock/CMakeLists.txt +++ b/sched/clock/CMakeLists.txt @@ -26,7 +26,6 @@ set(SRCS clock_initialize.c clock_settime.c clock_gettime.c - clock_abstime2ticks.c clock_systime_ticks.c clock_systime_timespec.c) diff --git a/sched/clock/Make.defs b/sched/clock/Make.defs index 789a4370c9..2f306dc166 100644 --- a/sched/clock/Make.defs +++ b/sched/clock/Make.defs @@ -21,7 +21,7 @@ ############################################################################ CSRCS += clock.c clock_initialize.c clock_settime.c clock_gettime.c -CSRCS += clock_abstime2ticks.c clock_systime_ticks.c clock_systime_timespec.c +CSRCS += clock_systime_ticks.c clock_systime_timespec.c CSRCS += clock_perf.c ifeq ($(CONFIG_CLOCK_TIMEKEEPING),y) diff --git a/sched/clock/clock.h b/sched/clock/clock.h index 8899978ee1..366f26d8dd 100644 --- a/sched/clock/clock.h +++ b/sched/clock/clock.h @@ -81,10 +81,6 @@ void clock_timer(void); # define clock_timer() #endif -int clock_abstime2ticks(clockid_t clockid, - FAR const struct timespec *abstime, - FAR sclock_t *ticks); - /**************************************************************************** * perf_init ****************************************************************************/ diff --git a/sched/mqueue/mq_timedreceive.c b/sched/mqueue/mq_timedreceive.c index 36d8f291fc..bc3caa9906 100644 --- a/sched/mqueue/mq_timedreceive.c +++ b/sched/mqueue/mq_timedreceive.c @@ -179,7 +179,7 @@ file_mq_timedreceive_internal(FAR struct file *mq, FAR char *msg, * this time stays valid until the wait begins. */ - ret = clock_abstime2ticks(CLOCK_REALTIME, abstime, &ticks); + clock_abstime2ticks(CLOCK_REALTIME, abstime, &ticks); } /* Handle any time-related errors */ diff --git a/sched/mqueue/mq_timedsend.c b/sched/mqueue/mq_timedsend.c index 76a1f31e64..9ece7d3a9a 100644 --- a/sched/mqueue/mq_timedsend.c +++ b/sched/mqueue/mq_timedsend.c @@ -217,7 +217,7 @@ file_mq_timedsend_internal(FAR struct file *mq, FAR const char *msg, * begins. */ - ret = clock_abstime2ticks(CLOCK_REALTIME, abstime, &ticks); + clock_abstime2ticks(CLOCK_REALTIME, abstime, &ticks); } /* Handle any time-related errors */ diff --git a/sched/semaphore/sem_clockwait.c b/sched/semaphore/sem_clockwait.c index ac8dfdc8e5..f5fb894969 100644 --- a/sched/semaphore/sem_clockwait.c +++ b/sched/semaphore/sem_clockwait.c @@ -95,7 +95,6 @@ int nxsem_clockwait(FAR sem_t *sem, clockid_t clockid, FAR struct tcb_s *rtcb = this_task(); irqstate_t flags; sclock_t ticks; - int status; int ret = ERROR; DEBUGASSERT(sem != NULL && abstime != NULL); @@ -140,24 +139,16 @@ int nxsem_clockwait(FAR sem_t *sem, clockid_t clockid, * value on failure. */ - status = clock_abstime2ticks(clockid, abstime, &ticks); + clock_abstime2ticks(clockid, abstime, &ticks); /* If the time has already expired return immediately. */ - if (status == OK && ticks <= 0) + if (ticks <= 0) { ret = -ETIMEDOUT; goto out; } - /* Handle any time-related errors */ - - if (status != OK) - { - ret = -status; - goto out; - } - /* Start the watchdog */ wd_start(&rtcb->waitdog, ticks, nxsem_timeout, nxsched_gettid()); diff --git a/sched/timer/timer_settime.c b/sched/timer/timer_settime.c index 1db3bbcfb5..b0a386bc67 100644 --- a/sched/timer/timer_settime.c +++ b/sched/timer/timer_settime.c @@ -294,7 +294,7 @@ int timer_settime(timer_t timerid, int flags, { /* Calculate a delay corresponding to the absolute time in 'value' */ - ret = clock_abstime2ticks(timer->pt_clock, &value->it_value, &delay); + clock_abstime2ticks(timer->pt_clock, &value->it_value, &delay); } else { @@ -306,11 +306,6 @@ int timer_settime(timer_t timerid, int flags, delay = clock_time2ticks(&value->it_value); } - if (ret < 0) - { - goto errout; - } - /* If the specified time has already passed, the function shall succeed * and the expiration notification shall be made. */ @@ -327,7 +322,6 @@ int timer_settime(timer_t timerid, int flags, ret = wd_start(&timer->pt_wdog, delay, timer_timeout, (wdparm_t)timer); } -errout: leave_critical_section(intflags); if (ret < 0)