diff options
author | Gregory Nutt <gnutt@nuttx.org> | 2014-03-31 10:01:03 -0600 |
---|---|---|
committer | Gregory Nutt <gnutt@nuttx.org> | 2014-03-31 10:01:03 -0600 |
commit | e782d4d4fb8f0ab8c353fc57bbb6cf8296f079f7 (patch) | |
tree | 567f20983da5c6248a2771c10c371ddb53378597 | |
parent | b4b12a6653bf66340b0b62357d07a2655bbb0c2e (diff) | |
download | nuttx-e782d4d4fb8f0ab8c353fc57bbb6cf8296f079f7.tar.gz nuttx-e782d4d4fb8f0ab8c353fc57bbb6cf8296f079f7.tar.bz2 nuttx-e782d4d4fb8f0ab8c353fc57bbb6cf8296f079f7.zip |
Add CONFIG_CLOCK_MONTONIC
-rw-r--r-- | nuttx/ChangeLog | 3 | ||||
-rw-r--r-- | nuttx/include/time.h | 4 | ||||
-rw-r--r-- | nuttx/sched/Kconfig | 14 | ||||
-rw-r--r-- | nuttx/sched/clock_gettime.c | 7 |
4 files changed, 25 insertions, 3 deletions
diff --git a/nuttx/ChangeLog b/nuttx/ChangeLog index 50e4f7be5..744214a97 100644 --- a/nuttx/ChangeLog +++ b/nuttx/ChangeLog @@ -7095,3 +7095,6 @@ * libc/stdio/lib_ftell.c: Fix a logic error in ftell(). It was simply using the file offset and did not take into account data buffered in memory. From Macs N (2013-3-31). + * Add CONFIG_CLOCK_MONOTONIC that case used to disable CLOCK_MONOTONIC + for a smaller footprint (2013-3-31). + diff --git a/nuttx/include/time.h b/nuttx/include/time.h index a3b5731e2..e8853ef89 100644 --- a/nuttx/include/time.h +++ b/nuttx/include/time.h @@ -99,7 +99,9 @@ * system time-of-day clock. */ -#define CLOCK_MONOTONIC 2 +#ifdef CLOCK_MONOTONIC +# define CLOCK_MONOTONIC 2 +#endif /* This is a flag that may be passed to the timer_settime() function */ diff --git a/nuttx/sched/Kconfig b/nuttx/sched/Kconfig index cd6b200e7..eb98f2f15 100644 --- a/nuttx/sched/Kconfig +++ b/nuttx/sched/Kconfig @@ -53,6 +53,20 @@ config SYSTEM_TIME64 and/or if a very long "uptime" is required, then this option can be selected to support a 64-bit wide timer. +config CLOCK_MONOTONIC + bool "Support CLOCK_MONOTONIC" + default n + ---help--- + CLOCK_MONOTONIC is an optional standard POSIX clock. Unlike + CLOCK_REALTIME which can move forward and backward when the + time-of-day changes, CLOCK_MONOTONIC is the elapsed time since some + arbitrary point in the post (the system start-up time for NuttX) + and, hence, is always monotonically increasing. CLOCK_MONOTONIC + is, hence, the more appropriate clock for determining time + differences. + + The value of the CLOCK_MONOTONIC clock cannot be set via clock_settime(). + config RR_INTERVAL int "Round robin timeslice (MSEC)" default 0 diff --git a/nuttx/sched/clock_gettime.c b/nuttx/sched/clock_gettime.c index 6aa8b44d1..e4b938539 100644 --- a/nuttx/sched/clock_gettime.c +++ b/nuttx/sched/clock_gettime.c @@ -107,6 +107,7 @@ int clock_gettime(clockid_t clock_id, struct timespec *tp) sdbg("clock_id=%d\n", clock_id); DEBUGASSERT(tp != NULL); +#ifdef CLOCK_MONOTONIC /* CLOCK_MONOTONIC is an optional under POSIX: "If the Monotonic Clock * option is supported, all implementations shall support a clock_id * of CLOCK_MONOTONIC defined in <time.h>. This clock represents the @@ -139,6 +140,8 @@ int clock_gettime(clockid_t clock_id, struct timespec *tp) tp->tv_sec = (time_t)secs; tp->tv_nsec = (long)nsecs; } + else +#endif /* CLOCK_REALTIME - POSIX demands this to be present. CLOCK_REALTIME * represents the machine's best-guess as to the current wall-clock, @@ -152,9 +155,9 @@ int clock_gettime(clockid_t clock_id, struct timespec *tp) */ #ifdef CONFIG_RTC - else if (clock_id == CLOCK_REALTIME || clock_id == CLOCK_ACTIVETIME) + if (clock_id == CLOCK_REALTIME || clock_id == CLOCK_ACTIVETIME) #else - else if (clock_id == CLOCK_REALTIME) + if (clock_id == CLOCK_REALTIME) #endif { /* Do we have a high-resolution RTC that can provide us with the time? */ |