summaryrefslogtreecommitdiff
path: root/nuttx
diff options
context:
space:
mode:
authorpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2011-10-03 12:21:20 +0000
committerpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2011-10-03 12:21:20 +0000
commit459c337817e461bc5aed4d14fab869e7d699b6f1 (patch)
tree4c0d7f6d3cc19316ac79767b000f7005c442d015 /nuttx
parent5246751cb564522530b70b4f171dbd3d09a6eb4b (diff)
downloadpx4-nuttx-459c337817e461bc5aed4d14fab869e7d699b6f1.tar.gz
px4-nuttx-459c337817e461bc5aed4d14fab869e7d699b6f1.tar.bz2
px4-nuttx-459c337817e461bc5aed4d14fab869e7d699b6f1.zip
Restore CLOCK_ACTIVETIME
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@4009 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'nuttx')
-rw-r--r--nuttx/arch/arm/src/stm32/stm32_rtc.c12
-rw-r--r--nuttx/configs/README.txt17
-rwxr-xr-xnuttx/configs/stm3210e-eval/README.txt33
-rw-r--r--nuttx/configs/vsn/src/sif.c2
-rw-r--r--nuttx/include/time.h21
-rw-r--r--nuttx/sched/clock_gettime.c6
-rw-r--r--nuttx/sched/clock_settime.c8
7 files changed, 93 insertions, 6 deletions
diff --git a/nuttx/arch/arm/src/stm32/stm32_rtc.c b/nuttx/arch/arm/src/stm32/stm32_rtc.c
index c9811171c..fc40a61b6 100644
--- a/nuttx/arch/arm/src/stm32/stm32_rtc.c
+++ b/nuttx/arch/arm/src/stm32/stm32_rtc.c
@@ -80,6 +80,18 @@
* Pre-processor Definitions
************************************************************************************/
/* Configuration ********************************************************************/
+/* In hi-res mode, the RTC operates at 16384Hz. Overflow interrupts are handled
+ * when the 32-bit RTC counter overflows every 3 days and 43 minutes. A BKP register
+ * is incremented on each overflow interrupt creating, effectively, a 48-bit RTC
+ * counter.
+ *
+ * In the lo-res mode, the RTC operates at 1Hz. Overflow interrupts are not handled
+ * (because the next overflow is not expected until the year 2106.
+ *
+ * WARNING: Overflow interrupts are lost whenever the STM32 is powered down. The
+ * overflow interrupt may be lost even if the STM32 is powered down only momentarily.
+ * Therefor hi-res solution is only useful in systems where the power is always on.
+ */
#ifdef CONFIG_RTC_HIRES
# ifndef CONFIG_RTC_FREQUENCY
diff --git a/nuttx/configs/README.txt b/nuttx/configs/README.txt
index 6cb302d24..c18bde321 100644
--- a/nuttx/configs/README.txt
+++ b/nuttx/configs/README.txt
@@ -607,6 +607,23 @@ defconfig -- This is a configuration file similar to the Linux
option will enable a limited form of memory mapping that is
implemented by copying whole files into memory.
+ RTC
+
+ CONFIG_RTC - Enables general support for a hardware RTC. Specific
+ architectures may require other specific settings.
+ CONFIG_RTC_HIRES - The typical RTC keeps time to resolution of 1
+ second, usually supporting a 32-bit time_t value. In this case,
+ the RTC is used to &quot;seed&quot; the normal NuttX timer and the
+ NuttX timer provides for higher resoution time. If CONFIG_RTC_HIRES
+ is enabled in the NuttX configuration, then the RTC provides higher
+ resolution time and completely replaces the system timer for purpose of
+ date and time.
+ CONFIG_RTC_FREQUENCY - If CONFIG_RTC_HIRES is defined, then the
+ frequency of the high resolution RTC must be provided. If CONFIG_RTC_HIRES
+ is not defined, CONFIG_RTC_FREQUENCY is assumed to be one.
+ CONFIG_RTC_ALARM - Enable if the RTC hardware supports setting of an alarm.
+ A callback function will be executed when the alarm goes off
+
SPI driver
CONFIG_SPI_OWNBUS - Set if there is only one active device
diff --git a/nuttx/configs/stm3210e-eval/README.txt b/nuttx/configs/stm3210e-eval/README.txt
index 3f260e9a8..f82c2243b 100755
--- a/nuttx/configs/stm3210e-eval/README.txt
+++ b/nuttx/configs/stm3210e-eval/README.txt
@@ -14,6 +14,7 @@ Contents
- DFU
- LEDs
- Temperature Sensor
+ - RTC
- STM3210E-EVAL-specific Configuration Options
- Configurations
@@ -264,6 +265,38 @@ commands enumerated in include/nuttx/sensors/lm75.h. Also read the descriptions
of the stm32_lm75initialize() and stm32_lm75attach() interfaces in the
arch/board/board.h file (sames as configs/stm3210e-eval/include/board.h).
+RTC
+===
+
+ The STM32 RTC may configured using the following settings.
+
+ CONFIG_RTC - Enables general support for a hardware RTC. Specific
+ architectures may require other specific settings.
+ CONFIG_RTC_HIRES - The typical RTC keeps time to resolution of 1
+ second, usually supporting a 32-bit time_t value. In this case,
+ the RTC is used to &quot;seed&quot; the normal NuttX timer and the
+ NuttX timer provides for higher resoution time. If CONFIG_RTC_HIRES
+ is enabled in the NuttX configuration, then the RTC provides higher
+ resolution time and completely replaces the system timer for purpose of
+ date and time.
+ CONFIG_RTC_FREQUENCY - If CONFIG_RTC_HIRES is defined, then the
+ frequency of the high resolution RTC must be provided. If CONFIG_RTC_HIRES
+ is not defined, CONFIG_RTC_FREQUENCY is assumed to be one.
+ CONFIG_RTC_ALARM - Enable if the RTC hardware supports setting of an alarm.
+ A callback function will be executed when the alarm goes off
+
+ In hi-res mode, the STM32 RTC operates only at 16384Hz. Overflow interrupts
+ are handled when the 32-bit RTC counter overflows every 3 days and 43 minutes.
+ A BKP register is incremented on each overflow interrupt creating, effectively,
+ a 48-bit RTC counter.
+
+ In the lo-res mode, the RTC operates at 1Hz. Overflow interrupts are not handled
+ (because the next overflow is not expected until the year 2106.
+
+ WARNING: Overflow interrupts are lost whenever the STM32 is powered down. The
+ overflow interrupt may be lost even if the STM32 is powered down only momentarily.
+ Therefore hi-res solution is only useful in systems where the power is always on.
+
STM3210E-EVAL-specific Configuration Options
============================================
diff --git a/nuttx/configs/vsn/src/sif.c b/nuttx/configs/vsn/src/sif.c
index 3c304a3b2..e185d8d0d 100644
--- a/nuttx/configs/vsn/src/sif.c
+++ b/nuttx/configs/vsn/src/sif.c
@@ -712,7 +712,7 @@ int sif_main(int argc, char *argv[])
fprintf(stderr, "%s:\tinit\n\tgpio\tA B\n\tpwr\tval\n", argv[0]);
struct timespec t_active;
- clock_gettime(CLOCK_REALTIME, &t_active);
+ clock_gettime(CLOCK_ACTIVETIME, &t_active);
fprintf(stderr, "rtc time = %u, active = %u / %u, time / systick = %u / %u\n",
up_rtc_time(), t_active.tv_sec, t_active.tv_nsec,
diff --git a/nuttx/include/time.h b/nuttx/include/time.h
index 69b62f4eb..623f9afb2 100644
--- a/nuttx/include/time.h
+++ b/nuttx/include/time.h
@@ -67,12 +67,29 @@
# define CLOCKS_PER_SEC (100)
#endif
-/* This is the only clock_id supported by the "Clock and Timer
- * Functions."
+/* CLOCK_REALTIME refers to the standard time source. For most implementations,
+ * the standard time source is the system timer interrupt. However, if the
+ * platform supports an RTC, then the standard time source will be the RTC
+ * for the clock_gettime() and clock_settime() interfaces (the system timer
+ * is still the time source for all of the interfaces).
*/
#define CLOCK_REALTIME 0
+/* If an RTC is supported, then the non-standard CLOCK_ACTIVETIME is also
+ * supported to manage time based on the system timer interrupt separately from
+ * the RTC. This may be necessary, for example, in certain cases where the
+ * system timer interrupt has been stopped in low power modes.
+ *
+ * CLOCK_ACTIVETIME is only recognized by clock_gettime() and clock_settime().
+ */
+
+#ifdef CONFIG_RTC
+# define CLOCK_ACTIVETIME 1
+#else
+# define CLOCK_ACTIVETIME CLOCK_REALTIME
+#endif
+
/* This is a flag that may be passed to the timer_settime() function */
#define TIMER_ABSTIME 1
diff --git a/nuttx/sched/clock_gettime.c b/nuttx/sched/clock_gettime.c
index d7707f379..9a84d320f 100644
--- a/nuttx/sched/clock_gettime.c
+++ b/nuttx/sched/clock_gettime.c
@@ -110,12 +110,16 @@ int clock_gettime(clockid_t clock_id, struct timespec *tp)
* time clock.
*/
+#ifdef CONFIG_RTC
+ if (clock_id == CLOCK_REALTIME || clockid == CLOCK_ACTIVETIME)
+#else
if (clock_id == CLOCK_REALTIME)
+#endif
{
/* Do we have a high-resolution RTC that can provie us with the time? */
#ifdef CONFIG_RTC_HIRES
- if (g_rtc_enabled)
+ if (g_rtc_enabled && clockid != CLOCK_ACTIVETIME)
{
/* Yes.. Get the hi-resolution time from the RTC */
diff --git a/nuttx/sched/clock_settime.c b/nuttx/sched/clock_settime.c
index 9db3112df..fdb6a6c57 100644
--- a/nuttx/sched/clock_settime.c
+++ b/nuttx/sched/clock_settime.c
@@ -100,7 +100,11 @@ int clock_settime(clockid_t clock_id, FAR const struct timespec *tp)
* time clock.
*/
- if (clock_id == CLOCK_REALTIME)
+#ifdef CONFIG_RTC
+ if (clock_id == CLOCK_REALTIME || clockid == CLOCK_ACTIVETIME)
+#else
+ if (clock_id == CLOCK_REALTIME)
+#endif
{
/* Interrupts are disabled here so that the in-memory time
* representation and the RTC setting will be as close as
@@ -123,7 +127,7 @@ int clock_settime(clockid_t clock_id, FAR const struct timespec *tp)
/* Setup the RTC (lo- or high-res) */
#ifdef CONFIG_RTC
- if (g_rtc_enabled)
+ if (g_rtc_enabled && clockid != CLOCK_ACTIVETIME)
{
up_rtc_settime(tp);
}