summaryrefslogtreecommitdiff
path: root/nuttx/arch/arm/src
diff options
context:
space:
mode:
authorGregory Nutt <gnutt@nuttx.org>2015-02-16 07:18:09 -0600
committerGregory Nutt <gnutt@nuttx.org>2015-02-16 07:18:09 -0600
commit20ec3d5e91a6c2b52baaf992c373fd5fc2259fa5 (patch)
tree9cb2f0cf63e6d81a754ffc3e82720a87a6703863 /nuttx/arch/arm/src
parent2eba8afab5e8bdc32a0f6365de070eaa7f383149 (diff)
downloadnuttx-20ec3d5e91a6c2b52baaf992c373fd5fc2259fa5.tar.gz
nuttx-20ec3d5e91a6c2b52baaf992c373fd5fc2259fa5.tar.bz2
nuttx-20ec3d5e91a6c2b52baaf992c373fd5fc2259fa5.zip
STM32 RTC: Extend the RTC interface to support reading subseconds. From Jussi Kivilinna
Diffstat (limited to 'nuttx/arch/arm/src')
-rw-r--r--nuttx/arch/arm/src/stm32/Kconfig1
-rw-r--r--nuttx/arch/arm/src/stm32/stm32_rtc.h26
-rw-r--r--nuttx/arch/arm/src/stm32/stm32_rtcc.c71
3 files changed, 94 insertions, 4 deletions
diff --git a/nuttx/arch/arm/src/stm32/Kconfig b/nuttx/arch/arm/src/stm32/Kconfig
index 06852173f..12f8c262c 100644
--- a/nuttx/arch/arm/src/stm32/Kconfig
+++ b/nuttx/arch/arm/src/stm32/Kconfig
@@ -608,6 +608,7 @@ config STM32_STM32L15XX
default n
select STM32_HAVE_SPI2
select STM32_HAVE_SPI3
+ select STM32_HAVE_RTC_SUBSECONDS if !STM32_LOWDENSITY
config STM32_ENERGYLITE
bool
diff --git a/nuttx/arch/arm/src/stm32/stm32_rtc.h b/nuttx/arch/arm/src/stm32/stm32_rtc.h
index b90c2b11c..9cd0cc131 100644
--- a/nuttx/arch/arm/src/stm32/stm32_rtc.h
+++ b/nuttx/arch/arm/src/stm32/stm32_rtc.h
@@ -99,6 +99,32 @@ extern "C"
************************************************************************************/
/************************************************************************************
+ * Name: stm32_rtc_getdatetime_with_subseconds
+ *
+ * Description:
+ * Get the current date and time from the date/time RTC. This interface
+ * is only supported by the date/time RTC hardware implementation.
+ * It is used to replace the system timer. It is only used by the RTOS during
+ * initialization to set up the system time when CONFIG_RTC and CONFIG_RTC_DATETIME
+ * are selected (and CONFIG_RTC_HIRES is not).
+ *
+ * NOTE: Some date/time RTC hardware is capability of sub-second accuracy. That
+ * sub-second accuracy is returned through 'nsec'.
+ *
+ * Input Parameters:
+ * tp - The location to return the high resolution time value.
+ * nsec - The location to return the subsecond time value.
+ *
+ * Returned Value:
+ * Zero (OK) on success; a negated errno on failure
+ *
+ ************************************************************************************/
+
+#ifdef CONFIG_STM32_HAVE_RTC_SUBSECONDS
+int stm32_rtc_getdatetime_with_subseconds(FAR struct tm *tp, FAR long *nsec);
+#endif
+
+/************************************************************************************
* Name: stm32_rtc_setdatetime
*
* Description:
diff --git a/nuttx/arch/arm/src/stm32/stm32_rtcc.c b/nuttx/arch/arm/src/stm32/stm32_rtcc.c
index ed2e2f06d..d484db821 100644
--- a/nuttx/arch/arm/src/stm32/stm32_rtcc.c
+++ b/nuttx/arch/arm/src/stm32/stm32_rtcc.c
@@ -741,7 +741,7 @@ int up_rtcinitialize(void)
}
/************************************************************************************
- * Name: up_rtc_getdatetime
+ * Name: stm32_rtc_getdatetime_with_subseconds
*
* Description:
* Get the current date and time from the date/time RTC. This interface
@@ -751,20 +751,26 @@ int up_rtcinitialize(void)
* are selected (and CONFIG_RTC_HIRES is not).
*
* NOTE: Some date/time RTC hardware is capability of sub-second accuracy. That
- * sub-second accuracy is lost in this interface. However, since the system time
- * is reinitialized on each power-up/reset, there will be no timing inaccuracy in
- * the long run.
+ * sub-second accuracy is returned through 'nsec'.
*
* Input Parameters:
* tp - The location to return the high resolution time value.
+ * nsec - The location to return the subsecond time value.
*
* Returned Value:
* Zero (OK) on success; a negated errno on failure
*
************************************************************************************/
+#ifdef CONFIG_STM32_HAVE_RTC_SUBSECONDS
+int stm32_rtc_getdatetime_with_subseconds(FAR struct tm *tp, FAR long *nsec)
+#else
int up_rtc_getdatetime(FAR struct tm *tp)
+#endif
{
+#ifdef CONFIG_STM32_HAVE_RTC_SUBSECONDS
+ uint32_t ssr;
+#endif
uint32_t dr;
uint32_t tr;
uint32_t tmp;
@@ -778,6 +784,9 @@ int up_rtc_getdatetime(FAR struct tm *tp)
{
dr = getreg32(STM32_RTC_DR);
tr = getreg32(STM32_RTC_TR);
+#ifdef CONFIG_STM32_HAVE_RTC_SUBSECONDS
+ ssr = getreg32(STM32_RTC_SSR);
+#endif
tmp = getreg32(STM32_RTC_DR);
}
while (tmp != dr);
@@ -816,11 +825,65 @@ int up_rtc_getdatetime(FAR struct tm *tp)
tmp = (dr & (RTC_DR_YU_MASK|RTC_DR_YT_MASK)) >> RTC_DR_YU_SHIFT;
tp->tm_year = rtc_bcd2bin(tmp) + 100;
+#ifdef CONFIG_STM32_HAVE_RTC_SUBSECONDS
+ /* Return RTC sub-seconds if no configured and if a non-NULL value
+ * of nsec has been provided to receive the sub-second value.
+ */
+
+ if (nsec)
+ {
+ uint32_t prediv_s;
+ uint32_t usecs;
+
+ prediv_s = getreg32(STM32_RTC_PRER) & RTC_PRER_PREDIV_S_MASK;
+ prediv_s >>= RTC_PRER_PREDIV_S_SHIFT;
+
+ ssr &= RTC_SSR_MASK;
+
+ /* Maximum prediv_s is 0x7fff, thus we can multiply by 100000 and
+ * still fit 32-bit unsigned integer. */
+
+ usecs = (((prediv_s - ssr) * 100000) / (prediv_s + 1)) * 10;
+
+ *nsec = usecs * 1000;
+ }
+#endif /* CONFIG_STM32_HAVE_RTC_SUBSECONDS */
+
rtc_dumptime(tp, "Returning");
return OK;
}
/************************************************************************************
+ * Name: up_rtc_getdatetime
+ *
+ * Description:
+ * Get the current date and time from the date/time RTC. This interface
+ * is only supported by the date/time RTC hardware implementation.
+ * It is used to replace the system timer. It is only used by the RTOS during
+ * initialization to set up the system time when CONFIG_RTC and CONFIG_RTC_DATETIME
+ * are selected (and CONFIG_RTC_HIRES is not).
+ *
+ * NOTE: Some date/time RTC hardware is capability of sub-second accuracy. That
+ * sub-second accuracy is lost in this interface. However, since the system time
+ * is reinitialized on each power-up/reset, there will be no timing inaccuracy in
+ * the long run.
+ *
+ * Input Parameters:
+ * tp - The location to return the high resolution time value.
+ *
+ * Returned Value:
+ * Zero (OK) on success; a negated errno on failure
+ *
+ ************************************************************************************/
+
+#ifdef CONFIG_STM32_HAVE_RTC_SUBSECONDS
+int up_rtc_getdatetime(FAR struct tm *tp)
+{
+ return stm32_rtc_getdatetime_with_subseconds(tp, NULL);
+}
+#endif
+
+/************************************************************************************
* Name: stm32_rtc_setdatetime
*
* Description: