This is an automated email from the ASF dual-hosted git repository. xiaoxiang pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git
commit c79d2067c7cbdce92a708ccfb9cf32cdb28b5296 Author: Jukka Laitinen <[email protected]> AuthorDate: Thu Nov 4 13:18:38 2021 +0200 Move timespec calculations from sched into libc/sched Allow using these functions also outside sched, where systick related calculations are performed Signed-off-by: Jukka Laitinen <[email protected]> --- include/nuttx/clock.h | 45 ++++++++++++++++++++++ libs/libc/sched/Make.defs | 2 + .../clock => libs/libc/sched}/clock_ticks2time.c | 4 +- .../clock => libs/libc/sched}/clock_time2ticks.c | 4 +- .../clock => libs/libc/sched}/clock_timespec_add.c | 4 +- .../libc/sched}/clock_timespec_subtract.c | 4 +- sched/clock/Make.defs | 6 +-- sched/clock/clock.h | 3 -- 8 files changed, 58 insertions(+), 14 deletions(-) diff --git a/include/nuttx/clock.h b/include/nuttx/clock.h index b11b1cf..7790f68 100644 --- a/include/nuttx/clock.h +++ b/include/nuttx/clock.h @@ -395,6 +395,51 @@ clock_t clock_systime_ticks(void); #endif /**************************************************************************** + * Name: clock_time2ticks + * + * Description: + * Return the given struct timespec as systime ticks. + * + * NOTE: This is an internal OS interface and should not be called from + * application code. + * + * Input Parameters: + * reltime - Pointer to the time presented as struct timespec + * + * Output Parameters: + * ticks - Pointer to receive the time value presented as systime ticks + * + * Returned Value: + * Always returns OK (0) + * + ****************************************************************************/ + +int clock_time2ticks(FAR const struct timespec *reltime, + FAR sclock_t *ticks); + +/**************************************************************************** + * Name: clock_ticks2time + * + * Description: + * Return the given systime ticks as a struct timespec. + * + * NOTE: This is an internal OS interface and should not be called from + * application code. + * + * Input Parameters: + * ticks - Time presented as systime ticks + * + * Output Parameters: + * reltime - Pointer to receive the time value presented as struct timespec + * + * Returned Value: + * Always returns OK (0) + * + ****************************************************************************/ + +int clock_ticks2time(sclock_t ticks, FAR struct timespec *reltime); + +/**************************************************************************** * Name: clock_systime_timespec * * Description: diff --git a/libs/libc/sched/Make.defs b/libs/libc/sched/Make.defs index 690d871..a136f48 100644 --- a/libs/libc/sched/Make.defs +++ b/libs/libc/sched/Make.defs @@ -21,6 +21,8 @@ # Add the sched C files to the build CSRCS += sched_getprioritymax.c sched_getprioritymin.c +CSRCS += clock_ticks2time.c clock_time2ticks.c +CSRCS += clock_timespec_add.c clock_timespec_subtract.c ifneq ($(CONFIG_CANCELLATION_POINTS),y) CSRCS += task_setcanceltype.c task_testcancel.c diff --git a/sched/clock/clock_ticks2time.c b/libs/libc/sched/clock_ticks2time.c similarity index 97% rename from sched/clock/clock_ticks2time.c rename to libs/libc/sched/clock_ticks2time.c index 9cb08a8..f2074bd 100644 --- a/sched/clock/clock_ticks2time.c +++ b/libs/libc/sched/clock_ticks2time.c @@ -1,5 +1,5 @@ /**************************************************************************** - * sched/clock/clock_ticks2time.c + * libs/libc/sched/clock_ticks2time.c * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -25,7 +25,7 @@ #include <nuttx/config.h> #include <time.h> -#include "clock/clock.h" +#include <nuttx/clock.h> /**************************************************************************** * Public Functions diff --git a/sched/clock/clock_time2ticks.c b/libs/libc/sched/clock_time2ticks.c similarity index 98% rename from sched/clock/clock_time2ticks.c rename to libs/libc/sched/clock_time2ticks.c index 72e5f79..9bcf832 100644 --- a/sched/clock/clock_time2ticks.c +++ b/libs/libc/sched/clock_time2ticks.c @@ -1,5 +1,5 @@ /**************************************************************************** - * sched/clock/clock_time2ticks.c + * libs/libc/sched/clock_time2ticks.c * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -28,7 +28,7 @@ #include <time.h> #include <assert.h> -#include "clock/clock.h" +#include <nuttx/clock.h> /**************************************************************************** * Public Functions diff --git a/sched/clock/clock_timespec_add.c b/libs/libc/sched/clock_timespec_add.c similarity index 97% rename from sched/clock/clock_timespec_add.c rename to libs/libc/sched/clock_timespec_add.c index 17fa47f..04d8234 100644 --- a/sched/clock/clock_timespec_add.c +++ b/libs/libc/sched/clock_timespec_add.c @@ -1,5 +1,5 @@ /**************************************************************************** - * sched/clock/clock_timespec_add.c + * libs/libc/sched/clock_timespec_add.c * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -27,7 +27,7 @@ #include <stdint.h> #include <time.h> -#include "clock/clock.h" +#include <nuttx/clock.h> /**************************************************************************** * Public Functions diff --git a/sched/clock/clock_timespec_subtract.c b/libs/libc/sched/clock_timespec_subtract.c similarity index 97% rename from sched/clock/clock_timespec_subtract.c rename to libs/libc/sched/clock_timespec_subtract.c index 04d378e..1cfd599 100644 --- a/sched/clock/clock_timespec_subtract.c +++ b/libs/libc/sched/clock_timespec_subtract.c @@ -1,5 +1,5 @@ /**************************************************************************** - * sched/clock/clock_timespec_subtract.c + * libs/libc/sched/clock_timespec_subtract.c * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -27,7 +27,7 @@ #include <stdint.h> #include <time.h> -#include "clock/clock.h" +#include <nuttx/clock.h> /**************************************************************************** * Public Functions diff --git a/sched/clock/Make.defs b/sched/clock/Make.defs index 57a51b6..7ae14e7 100644 --- a/sched/clock/Make.defs +++ b/sched/clock/Make.defs @@ -19,9 +19,9 @@ ############################################################################ CSRCS += clock_initialize.c clock_settime.c clock_gettime.c clock_getres.c -CSRCS += clock_time2ticks.c clock_abstime2ticks.c clock_ticks2time.c -CSRCS += clock_systime_ticks.c clock_systime_timespec.c clock_timespec_add.c -CSRCS += clock_timespec_subtract.c clock.c +CSRCS += clock_abstime2ticks.c +CSRCS += clock_systime_ticks.c clock_systime_timespec.c +CSRCS += clock.c ifeq ($(CONFIG_CLOCK_TIMEKEEPING),y) CSRCS += clock_timekeeping.c diff --git a/sched/clock/clock.h b/sched/clock/clock.h index 874edc2..3f67f0f 100644 --- a/sched/clock/clock.h +++ b/sched/clock/clock.h @@ -84,8 +84,5 @@ void weak_function clock_timer(void); int clock_abstime2ticks(clockid_t clockid, FAR const struct timespec *abstime, FAR sclock_t *ticks); -int clock_time2ticks(FAR const struct timespec *reltime, - FAR sclock_t *ticks); -int clock_ticks2time(sclock_t ticks, FAR struct timespec *reltime); #endif /* __SCHED_CLOCK_CLOCK_H */
