summaryrefslogtreecommitdiff
path: root/nuttx/sched
diff options
context:
space:
mode:
authorpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2011-10-02 14:16:30 +0000
committerpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2011-10-02 14:16:30 +0000
commitbbadecee80cf2f48a43097328bb24b73f236934c (patch)
treee3a769b2f63c911bbc57c0e60b863aa996ea9dbb /nuttx/sched
parent078ff53de7f505ba714be768a94c1e52e7261b3e (diff)
downloadpx4-nuttx-bbadecee80cf2f48a43097328bb24b73f236934c.tar.gz
px4-nuttx-bbadecee80cf2f48a43097328bb24b73f236934c.tar.bz2
px4-nuttx-bbadecee80cf2f48a43097328bb24b73f236934c.zip
Remove support for UTC time; add support for 64-bit time
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@4006 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'nuttx/sched')
-rw-r--r--nuttx/sched/clock_gettime.c133
-rw-r--r--nuttx/sched/clock_initialize.c84
-rw-r--r--nuttx/sched/clock_internal.h18
-rw-r--r--nuttx/sched/clock_settime.c51
-rw-r--r--nuttx/sched/clock_systimer.c64
5 files changed, 111 insertions, 239 deletions
diff --git a/nuttx/sched/clock_gettime.c b/nuttx/sched/clock_gettime.c
index fc3a1593a..b146949fb 100644
--- a/nuttx/sched/clock_gettime.c
+++ b/nuttx/sched/clock_gettime.c
@@ -91,127 +91,78 @@
int clock_gettime(clockid_t clock_id, struct timespec *tp)
{
-#ifndef CONFIG_SYSTEM_UTC
+#ifdef CONFIG_SYSTEM_TIME64
+ uint64_t msecs;
+ uint64_t secs;
+ uint64_t nsecs;
+#else
uint32_t msecs;
uint32_t secs;
uint32_t nsecs;
-#else
- uint32_t system_utc;
- uint32_t tickcount;
-#endif
-#if defined(CONFIG_RTC) || defined(CONFIG_SYSTEM_UTC)
- irqstate_t flags;
#endif
-
int ret = OK;
sdbg("clock_id=%d\n", clock_id);
+ DEBUGASSERT(tp != NULL);
/* CLOCK_REALTIME - POSIX demands this to be present. This is the wall
* time clock.
*/
- if (clock_id == CLOCK_REALTIME && tp)
+ if (clock_id == CLOCK_REALTIME)
{
- /* If CONFIG_SYSTEM_UTC is not defined, then we have to get the time
- * from g_system_timer.
- */
-
-#ifndef CONFIG_SYSTEM_UTC
-
- /* Get the elapsed time since power up (in milliseconds) biased
- * as appropriate.
- */
-
- msecs = MSEC_PER_TICK * (clock_systimer() - g_tickbias);
-
- sdbg("msecs = %d g_tickbias=%d\n",
- (int)msecs, (int)g_tickbias);
-
- /* Get the elapsed time in seconds and nanoseconds. */
-
- secs = msecs / MSEC_PER_SEC;
- nsecs = (msecs - (secs * MSEC_PER_SEC)) * NSEC_PER_MSEC;
-
- sdbg("secs = %d + %d nsecs = %d + %d\n",
- (int)msecs, (int)g_basetime.tv_sec,
- (int)nsecs, (int)g_basetime.tv_nsec);
-
- /* Add the base time to this. */
-
- secs += (uint32_t)g_basetime.tv_sec;
- nsecs += (uint32_t)g_basetime.tv_nsec;
-
- /* Handle carry to seconds. */
-
- if (nsecs > NSEC_PER_SEC)
- {
- uint32_t dwCarrySecs = nsecs / NSEC_PER_SEC;
- secs += dwCarrySecs;
- nsecs -= (dwCarrySecs * NSEC_PER_SEC);
- }
-
- /* And return the result to the caller. */
-
- tp->tv_sec = (time_t)secs;
- tp->tv_nsec = (long)nsecs;
-
-#else /* CONFIG_SYSTEM_UTC */
-
- /* CONFIG_SYSTEM_UTC is defined. But we might be able to get the time
- * from the hardware if a high resolution RTC is available.
- */
+ /* Do we have a high-resolution RTC that can provie us with the time? */
#ifdef CONFIG_RTC_HIRES
if (g_rtc_enabled)
{
- /* Get the hi-resolution time from the RTC */
+ /* Yes.. Get the hi-resolution time from the RTC */
ret = up_rtc_gettime(tp);
}
else
#endif
{
- /* Disable interrupts while g_system_utc and g_tickcount are sampled
- * so that we can be assured that g_system_utc and g_tickcount are based
- * at the same point in time.
+ /* Get the elapsed time since power up (in milliseconds) biased
+ * as appropriate.
*/
- flags = irqsave();
- system_utc = g_system_utc;
- tickcount = g_tickcount;
- irqrestore(flags);
+ msecs = MSEC_PER_TICK * (g_system_timer - g_tickbias);
- tp->tv_sec = system_utc;
- tp->tv_nsec = tickcount * (1000000000/TICK_PER_SEC);
- }
-#endif /* CONFIG_SYSTEM_UTC */
+ sdbg("msecs = %d g_tickbias=%d\n",
+ (int)msecs, (int)g_tickbias);
- sdbg("Returning tp=(%d,%d)\n", (int)tp->tv_sec, (int)tp->tv_nsec);
- }
+ /* Get the elapsed time in seconds and nanoseconds. */
- /* CLOCK_ACTIVETIME is non-standard. Returns active UTC time, which is
- * disabled during power down modes. Unit is 1 second.
- */
+ secs = msecs / MSEC_PER_SEC;
+ nsecs = (msecs - (secs * MSEC_PER_SEC)) * NSEC_PER_MSEC;
-#ifdef CONFIG_SYSTEM_UTC
- else if (clock_id == CLOCK_ACTIVETIME && g_rtc_enabled && tp)
- {
- /* Disable interrupts while g_system_utc and g_tickcount are sampled
- * so that we can be assured that g_system_utc and g_tickcount are based
- * at the same point in time.
- */
-
- flags = irqsave();
- system_utc = g_system_utc;
- tickcount = g_tickcount;
- irqrestore(flags);
-
- tp->tv_sec = system_utc;
- tp->tv_nsec = tickcount * (1000000000/TICK_PER_SEC);
- }
-#endif
+ sdbg("secs = %d + %d nsecs = %d + %d\n",
+ (int)msecs, (int)g_basetime.tv_sec,
+ (int)nsecs, (int)g_basetime.tv_nsec);
+
+ /* Add the base time to this. */
+ secs += (uint32_t)g_basetime.tv_sec;
+ nsecs += (uint32_t)g_basetime.tv_nsec;
+
+ /* Handle carry to seconds. */
+
+ if (nsecs > NSEC_PER_SEC)
+ {
+ uint32_t dwCarrySecs = nsecs / NSEC_PER_SEC;
+ secs += dwCarrySecs;
+ nsecs -= (dwCarrySecs * NSEC_PER_SEC);
+ }
+
+ /* And return the result to the caller. */
+
+ tp->tv_sec = (time_t)secs;
+ tp->tv_nsec = (long)nsecs;
+ }
+
+ sdbg("Returning tp=(%d,%d)\n", (int)tp->tv_sec, (int)tp->tv_nsec);
+ }
else
{
sdbg("Returning ERROR\n");
diff --git a/nuttx/sched/clock_initialize.c b/nuttx/sched/clock_initialize.c
index ed3a25828..2ffdd5819 100644
--- a/nuttx/sched/clock_initialize.c
+++ b/nuttx/sched/clock_initialize.c
@@ -38,6 +38,7 @@
****************************************************************************/
#include <nuttx/config.h>
+#include <nuttx/compiler.h>
#include <stdint.h>
#include <time.h>
@@ -53,27 +54,12 @@
/****************************************************************************
* Definitions
****************************************************************************/
-
-#ifdef CONFIG_RTC
-# ifndef CONFIG_SYSTEM_UTC
-# error "In order to support hardware RTC system must have set the CONFIG_SYSTEM_UTC=y"
-# endif
-#endif
-
/* Standard time definitions (in units of seconds) */
#define SEC_PER_MIN ((time_t)60)
#define SEC_PER_HOUR ((time_t)60 * SEC_PER_MIN)
#define SEC_PER_DAY ((time_t)24 * SEC_PER_HOUR)
-/* Macro to increment the system timer -- or not */
-
-#ifndef CONFIG_SYSTEM_UTC
-# define incr_systimer() g_system_timer++
-#else
-# define incr_systimer()
-#endif
-
/****************************************************************************
* Private Type Declarations
****************************************************************************/
@@ -90,59 +76,23 @@
* Public Variables
****************************************************************************/
-#if CONFIG_SYSTEM_UTC
-volatile time_t g_system_utc;
+#ifdef CONFIG_SYSTEM_TIME64
+volatile uint64_t g_system_timer;
+uint64_t g_tickbias;
#else
-volatile clock_t g_system_timer;
-struct timespec g_basetime;
-uint32_t g_tickbias;
+volatile uint32_t g_system_timer;
+uint32_t g_tickbias;
#endif
+struct timespec g_basetime;
+
/**************************************************************************
* Private Variables
**************************************************************************/
-/* This variable is used to count ticks and to increment the one-second
- * UTC variable.
- */
-
-#if CONFIG_SYSTEM_UTC
-#if TICK_PER_SEC > 32767
-volatile uint32_t g_tickcount;
-#elif TICK_PER_SEC > 255
-volatile uint16_t g_tickcount;
-#else
-volatile uint8_t g_tickcount;
-#endif
-#endif /* CONFIG_SYSTEM_UTC */
-
/**************************************************************************
* Private Functions
**************************************************************************/
-/****************************************************************************
- * Function: incr_utc
- *
- * Description:
- * This function must be called once every time the real
- * time clock interrupt occurs. The interval of this
- * clock interrupt must be MSEC_PER_TICK
- *
- ****************************************************************************/
-
-#if CONFIG_SYSTEM_UTC
-static inline void incr_utc(void)
-{
- g_tickcount++;
-
- if (g_tickcount >= TICK_PER_SEC)
- {
- g_system_utc++;
- g_tickcount -= TICK_PER_SEC;
- }
-}
-#else
-# define incr_utc()
-#endif
/****************************************************************************
* Function: clock_inittime
@@ -210,27 +160,17 @@ static inline void clock_inittime(FAR struct timespec *tp)
void clock_initialize(void)
{
-#ifdef CONFIG_SYSTEM_UTC
- struct timespec ts;
-#endif
-
/* Initialize the RTC hardware */
#ifdef CONFIG_RTC
up_rtcinitialize();
#endif
- /* Initialize the time value */
+ /* Initialize the time value to match */
-#ifdef CONFIG_SYSTEM_UTC
- clock_inittime(&ts);
- g_system_utc = ts.tv_sec;
- g_tickcount = ((ts.tv_nsec > 10) * CLOCKS_PER_SEC) / (1000000000 >> 10);
-#else
clock_inittime(&g_basetime);
g_system_timer = 0;
g_tickbias = 0;
-#endif
}
/****************************************************************************
@@ -247,9 +187,5 @@ void clock_timer(void)
{
/* Increment the per-tick system counter */
- incr_systimer();
-
- /* Increment the per-second UTC counter */
-
- incr_utc();
+ g_system_timer++;
}
diff --git a/nuttx/sched/clock_internal.h b/nuttx/sched/clock_internal.h
index 1752aae7b..dadf5d66a 100644
--- a/nuttx/sched/clock_internal.h
+++ b/nuttx/sched/clock_internal.h
@@ -43,12 +43,21 @@
#include <nuttx/config.h>
#include <stdint.h>
+
#include <nuttx/clock.h>
#include <nuttx/compiler.h>
/********************************************************************************
- * Definitions
+ * Pre-processor Definitions
********************************************************************************/
+/* Configuration ************************************************************/
+/* If CONFIG_SYSTEM_TIME64 is selected and the CPU supports long long types,
+ * then a 64-bit system time will be used.
+ */
+
+#ifndef CONFIG_HAVE_LONG_LONG
+# undef CONFIG_SYSTEM_TIME64
+#endif
/********************************************************************************
* Public Type Definitions
@@ -58,8 +67,13 @@
* Global Variables
********************************************************************************/
-extern struct timespec g_basetime;
+#ifdef CONFIG_SYSTEM_TIME64
+extern uint64_t g_tickbias;
+#else
extern uint32_t g_tickbias;
+#endif
+
+extern struct timespec g_basetime;
/********************************************************************************
* Public Function Prototypes
diff --git a/nuttx/sched/clock_settime.c b/nuttx/sched/clock_settime.c
index 299e8c65b..f8bff78e3 100644
--- a/nuttx/sched/clock_settime.c
+++ b/nuttx/sched/clock_settime.c
@@ -89,17 +89,25 @@
int clock_settime(clockid_t clock_id, FAR const struct timespec *tp)
{
+ irqstate_t flags;
int ret = OK;
sdbg("clock_id=%d\n", clock_id);
+ DEBUGASSERT(tp != NULL);
/* CLOCK_REALTIME - POSIX demands this to be present. This is the wall
* time clock.
*/
- if (clock_id == CLOCK_REALTIME && tp)
+ if (clock_id == CLOCK_REALTIME)
{
-#ifndef CONFIG_SYSTEM_UTC
+ /* Interrupts are disabled here so that the in-memory time
+ * representation and the RTC setting will be as close as
+ * possible.
+ */
+
+ flags = irqsave();
+
/* Save the new base time. */
g_basetime.tv_sec = tp->tv_sec;
@@ -109,55 +117,22 @@ int clock_settime(clockid_t clock_id, FAR const struct timespec *tp)
* as appropriate.
*/
- g_tickbias = clock_systimer();
-
-#else /* if CONFIG_SYSTEM_UTC=y */
+ g_tickbias = g_system_timer;
- /* We ignore everything below one second in time configuration */
+ /* Setup the RTC (lo- or high-res) */
#ifdef CONFIG_RTC
if (g_rtc_enabled)
{
up_rtc_settime(tp);
}
- else
-#endif
- {
- g_system_utc = tp->tv_sec;
- }
#endif
+ irqrestore(flags);
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_SYSTEM_UTC
- else if (clock_id == CLOCK_ACTIVETIME && tp)
- {
- irqstate_t flags;
- uint32_t tickcount;
-
- /* Calculate the number of ticks correspond to the nanosecond count...
- * exercising care to avoid overflows. This could still overflow
- * if CLOCKS_PER_SEC is very large (something like 4096).
- */
-
- tickcount = ((tp->tv_nsec >> 10) * CLOCKS_PER_SEC) / (1000000000 >> 10);
-
- /* Then set the UTC time (seconds) plus the tickcount (fractional seconds */
-
- flags = irqsave();
- g_system_utc = tp->tv_sec;
- g_tickcount = tickcount;
- irqrestore(flags);
- }
-#endif
-
else
{
sdbg("Returning ERROR\n");
diff --git a/nuttx/sched/clock_systimer.c b/nuttx/sched/clock_systimer.c
index 2061b1de6..6a2a9e24e 100644
--- a/nuttx/sched/clock_systimer.c
+++ b/nuttx/sched/clock_systimer.c
@@ -42,12 +42,8 @@
#include <stdint.h>
#include <nuttx/clock.h>
-#include <nuttx/rtc.h>
-#include <nuttx/time.h>
-#include <arch/irq.h>
-
-#if !defined(clock_systimer) /* See nuttx/clock.h */
+#include "clock_internal.h"
/****************************************************************************
* Pre-processor Definitions
@@ -65,7 +61,7 @@
* Function: clock_systimer
*
* Description:
- * Return the current value of the system timer counter
+ * Return the current value of the 32-bit system timer counter
*
* Parameters:
* None
@@ -77,38 +73,38 @@
*
****************************************************************************/
+#if !defined(clock_systimer) /* See nuttx/clock.h */
uint32_t clock_systimer(void)
{
-#ifdef CONFIG_SYSTEM_UTC
- irqstate_t flags;
- uint32_t system_utc;
- uint32_t tickcount;
-#endif
-
-#ifdef CONFIG_RTC_HIRES
- /* Fetch the g_system_timer value from timer hardware, if available.
- *
- * Note that the unit of the g_system_timer and and up_rtc_gettime() do
- * not have the same unit.
- */
-#endif
-
-#ifndef CONFIG_SYSTEM_UTC
- return g_system_timer;
+#ifdef CONFIG_SYSTEM_TIME64
+ return (uint32_t)(g_system_timer & 0x00000000ffffffff);
#else
- /* Disable interrupts while g_system_utc and g_tickcount are sampled
- * so that we can be assured that g_system_utc and g_tickcount are based
- * at the same point in time.
- */
-
- flags = irqsave();
- system_utc = g_system_utc;
- tickcount = g_tickcount;
- irqrestore(flags);
-
- return system_utc * TICK_PER_SEC + tickcount;
+ return g_system_timer;
#endif
}
+#endif
-#endif /* !clock_systtimer */
+/****************************************************************************
+ * Function: clock_systimer64
+ *
+ * Description:
+ * Return the current value of the 64-bit system timer counter
+ *
+ * Parameters:
+ * None
+ *
+ * Return Value:
+ * The current value of the system timer counter
+ *
+ * Assumptions:
+ *
+ ****************************************************************************/
+#if !defined(clock_systimer) /* See nuttx/clock.h */
+#ifdef CONFIG_SYSTEM_TIME64
+uint64_t clock_systimer64(void)
+{
+ return g_system_timer;
+}
+#endif
+#endif