diff options
author | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2011-05-06 21:10:00 +0000 |
---|---|---|
committer | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2011-05-06 21:10:00 +0000 |
commit | bbbdceb9d13441f4b96257718ed090b8998759f7 (patch) | |
tree | 6bb4e7cbc0c05dc47f8d7de2848b67b189bd5279 /nuttx/sched/clock_settime.c | |
parent | 4c3a7673e9a391302a0e2417d8846bfdf7d9171f (diff) | |
download | px4-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_settime.c')
-rw-r--r-- | nuttx/sched/clock_settime.c | 49 |
1 files changed, 40 insertions, 9 deletions
diff --git a/nuttx/sched/clock_settime.c b/nuttx/sched/clock_settime.c index 2af27acf1..72fb8276e 100644 --- a/nuttx/sched/clock_settime.c +++ b/nuttx/sched/clock_settime.c @@ -38,6 +38,7 @@ ************************************************************************/ #include <nuttx/config.h> +#include <nuttx/rtc.h> #include <time.h> #include <errno.h> @@ -90,16 +91,13 @@ int clock_settime(clockid_t clock_id, const 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 || !tp) - { - sdbg("Returning ERROR\n"); - *get_errno_ptr() = EINVAL; - ret = ERROR; - } - else + if (clock_id == CLOCK_REALTIME && tp) { +#ifndef CONFIG_SYSTEM_UTC /* Save the new base time. */ g_basetime.tv_sec = tp->tv_sec; @@ -110,11 +108,44 @@ int clock_settime(clockid_t clock_id, const struct timespec *tp) */ g_tickbias = clock_systimer(); + +#else /* if CONFIG_SYSTEM_UTC=y */ + + /* We ignore everything below one second in time configuration */ + +#ifdef CONFIG_RTC + if (g_rtc_enabled) + { + up_rtc_settime( tp->tv_sec ); + } + else +#endif + g_system_utc = tp->tv_sec; + +#endif sdbg("basetime=(%d,%d) tickbias=%d\n", (int)g_basetime.tv_sec, (int)g_basetime.tv_nsec, (int)g_tickbias); - } + } + + /* 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) + { + g_system_utc = tp->tv_sec; + } +#endif + + else + { + sdbg("Returning ERROR\n"); + *get_errno_ptr() = EINVAL; + ret = ERROR; + } return ret; } |