summaryrefslogtreecommitdiff
path: root/nuttx/sched/clock_gettime.c
diff options
context:
space:
mode:
authorpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2011-05-06 21:10:00 +0000
committerpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2011-05-06 21:10:00 +0000
commitbbbdceb9d13441f4b96257718ed090b8998759f7 (patch)
tree6bb4e7cbc0c05dc47f8d7de2848b67b189bd5279 /nuttx/sched/clock_gettime.c
parent4c3a7673e9a391302a0e2417d8846bfdf7d9171f (diff)
downloadpx4-nuttx-bbbdceb9d13441f4b96257718ed090b8998759f7.tar.gz
px4-nuttx-bbbdceb9d13441f4b96257718ed090b8998759f7.tar.bz2
px4-nuttx-bbbdceb9d13441f4b96257718ed090b8998759f7.zip
More timer changes from Uros
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@3572 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'nuttx/sched/clock_gettime.c')
-rw-r--r--nuttx/sched/clock_gettime.c51
1 files changed, 42 insertions, 9 deletions
diff --git a/nuttx/sched/clock_gettime.c b/nuttx/sched/clock_gettime.c
index f3ffe2a6c..59e5b604c 100644
--- a/nuttx/sched/clock_gettime.c
+++ b/nuttx/sched/clock_gettime.c
@@ -38,6 +38,7 @@
************************************************************************/
#include <nuttx/config.h>
+#include <nuttx/rtc.h>
#include <stdint.h>
#include <time.h>
@@ -95,17 +96,13 @@ int clock_gettime(clockid_t clock_id, struct timespec *tp)
sdbg("clock_id=%d\n", clock_id);
- /* Only CLOCK_REALTIME is supported */
+ /* CLOCK_REALTIME - POSIX demands this to be present. This is the wall
+ * time clock.
+ */
- if (clock_id != CLOCK_REALTIME)
- {
- sdbg("Returning ERROR\n");
-
- *get_errno_ptr() = EINVAL;
- ret = ERROR;
- }
- else
+ if (clock_id == CLOCK_REALTIME && tp)
{
+#ifndef CONFIG_SYSTEM_UTC
/* Get the elapsed time since power up (in milliseconds) biased
* as appropriate.
*/
@@ -142,10 +139,46 @@ int clock_gettime(clockid_t clock_id, struct timespec *tp)
tp->tv_sec = (time_t)secs;
tp->tv_nsec = (long)nsecs;
+
+#else /* if CONFIG_SYSTEM_UTC=y */
+
+#ifdef CONFIG_RTC
+ if (g_rtc_enabled)
+ {
+ tp->tv_sec = up_rtc_gettime();
+ tp->tv_nsec = (up_rtc_getclock() & (RTC_CLOCKS_PER_SEC-1) ) * (1000000000/TICK_PER_SEC);
+ }
+ else
+#endif
+ {
+ tp->tv_sec = g_system_utc;
+ tp->tv_nsec = g_tickcount * (1000000000/TICK_PER_SEC);
+ }
+#endif
sdbg("Returning tp=(%d,%d)\n",
(int)tp->tv_sec, (int)tp->tv_nsec);
}
+ /* CLOCK_ACTIVETIME is non-standard. Returns active UTC time, which is
+ * disabled during power down modes. Unit is 1 second.
+ */
+
+#ifdef CONFIG_RTC
+ else if (clock_id == CLOCK_ACTIVETIME && g_rtc_enabled && tp)
+ {
+ tp->tv_sec = g_system_utc;
+ tp->tv_nsec = g_tickcount * (1000000000/TICK_PER_SEC);
+ }
+#endif
+
+ else
+ {
+ sdbg("Returning ERROR\n");
+
+ errno = EINVAL;
+ ret = ERROR;
+ }
+
return ret;
}