summaryrefslogtreecommitdiff
path: root/nuttx/sched
diff options
context:
space:
mode:
authorpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2011-04-15 16:20:25 +0000
committerpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2011-04-15 16:20:25 +0000
commit3a3fe9efb1e3f0fe6a756b8e4d2fa48d5564137b (patch)
tree13d2c82c982b760b250741f7167faf0d509ecbc4 /nuttx/sched
parentf1893cbaf513c7f0fbca77240fc59707ad039734 (diff)
downloadpx4-nuttx-3a3fe9efb1e3f0fe6a756b8e4d2fa48d5564137b.tar.gz
px4-nuttx-3a3fe9efb1e3f0fe6a756b8e4d2fa48d5564137b.tar.bz2
px4-nuttx-3a3fe9efb1e3f0fe6a756b8e4d2fa48d5564137b.zip
Add code changes from Uros
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@3507 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'nuttx/sched')
-rw-r--r--nuttx/sched/clock_initialize.c44
-rw-r--r--nuttx/sched/clock_systimer.c23
-rw-r--r--nuttx/sched/clock_uptime.c15
3 files changed, 61 insertions, 21 deletions
diff --git a/nuttx/sched/clock_initialize.c b/nuttx/sched/clock_initialize.c
index e18b819fa..0079e9f57 100644
--- a/nuttx/sched/clock_initialize.c
+++ b/nuttx/sched/clock_initialize.c
@@ -1,7 +1,7 @@
/****************************************************************************
* sched/clock_initialize.c
*
- * Copyright (C) 2007, 2009 Gregory Nutt. All rights reserved.
+ * Copyright (C) 2007, 2009, 2011 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
*
* Redistribution and use in source and binary forms, with or without
@@ -53,15 +53,15 @@
* Definitions
****************************************************************************/
+/* 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)
-#if __HAVE_SYSTEM_COUNTER
-# define incr_systimer() g_system_timer++
-#else
-# define incr_systimer()
-#endif
+/* Defined just so the uptime counter and system timer look similar */
+
+#define incr_systimer() g_system_timer++
/****************************************************************************
* Private Type Declarations
@@ -79,9 +79,7 @@
* Public Variables
****************************************************************************/
-#if __HAVE_SYSTEM_COUNTER
volatile clock_t g_system_timer = 0;
-#endif
#if CONFIG_UPTIME
volatile time_t g_uptime = 0;
@@ -155,23 +153,39 @@ static inline void incr_uptime(void)
void clock_initialize(void)
{
time_t jdn;
+#ifdef CONFIG_PTIMER
+ bool rtc_enabled = false;
+#endif
- /* Initialize the real time close */
+ /* Initialize the real time close (this should be un-nesssary except on a
+ * restart).
+ */
-#if __HAVE_SYSTEM_COUNTER
g_system_timer = 0;
+#ifdef CONFIG_UPTIME
+ g_uptime = 0;
+#endif
+
+ /* Do we have hardware periodic timer support? */
+
+#ifdef CONFIG_RTC
+ if (up_rtcinitialize() == OK)
+ {
+ rtc_enabled = true;
+ }
#endif
/* Get the EPOCH-relative julian date from the calendar year,
* month, and date
*/
-#ifndef CONFIG_PTIMER
- jdn = clock_calendar2utc(CONFIG_START_YEAR, CONFIG_START_MONTH,
- CONFIG_START_DAY);
-#else /* use UTC as starting date */
- jdn = clock_calendar2utc(1970, 1, 1);
+#ifdef CONFIG_PTIMER
+ if (!rtc_enabled)
#endif
+ {
+ jdn = clock_calendar2utc(CONFIG_START_YEAR, CONFIG_START_MONTH,
+ CONFIG_START_DAY);
+ }
/* Set the base time as seconds into this julian day. */
diff --git a/nuttx/sched/clock_systimer.c b/nuttx/sched/clock_systimer.c
index 5e18f53fd..fde303be6 100644
--- a/nuttx/sched/clock_systimer.c
+++ b/nuttx/sched/clock_systimer.c
@@ -40,9 +40,12 @@
#include <nuttx/config.h>
#include <stdint.h>
+
#include <nuttx/clock.h>
+#include <nuttx/ptimer.h>
+#include <nuttx/time.h>
-#if __HAVE_SYSTEM_COUNTER && !defined(clock_systimer) /* See nuttx/clock.h */
+#if !defined(clock_systimer) /* See nuttx/clock.h */
/****************************************************************************
* Pre-processor Definitions
@@ -74,8 +77,24 @@
uint32_t clock_systimer(void)
{
+ /* Fetch the g_system_timer value from timer hardware, if available */
+
+#ifdef CONFIG_PTIMER
+
+ /* Check if the periodic timer is initialized
+ *
+ * Note that the unit of the g_system_timer and and up_rtc_getclock() must
+ * be the same in order.
+ */
+
+ if (g_rtc_enabled)
+ {
+ up_rtc_getclock();
+ }
+#endif
+
return g_system_timer;
}
-#endif /* __HAVE_SYSTEM_COUNTER */
+#endif /* !clock_systtimer */
diff --git a/nuttx/sched/clock_uptime.c b/nuttx/sched/clock_uptime.c
index ae580ed17..cea3262c8 100644
--- a/nuttx/sched/clock_uptime.c
+++ b/nuttx/sched/clock_uptime.c
@@ -43,14 +43,12 @@
#include <nuttx/clock.h>
#include <nuttx/time.h>
-#if !defined(CONFIG_DISABLE_CLOCK) && defined(CONFIG_UPTIME)
+#if !defined(CONFIG_DISABLE_CLOCK) && defined(CONFIG_UPTIME) && !defined(clock_uptime)
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
-#undef clock_uptime
-
/****************************************************************************
* Private Data
****************************************************************************/
@@ -78,7 +76,16 @@
time_t clock_uptime(void)
{
- return g_uptime;
+#ifdef CONFIG_PTIMER
+ if (g_rtc_enabled)
+ {
+ return up_rtc_gettime();
+ }
+ else
+#endif
+ {
+ return g_uptime;
+ }
}
#endif /* CONFIG_DISABLE_CLOCK && CONFIG_UPTIME */