aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--os/hal/include/rtc.h3
-rw-r--r--os/hal/platforms/STM32/rtc_lld.c22
-rw-r--r--os/hal/platforms/STM32/rtc_lld.h3
-rw-r--r--os/hal/src/rtc.c18
4 files changed, 20 insertions, 26 deletions
diff --git a/os/hal/include/rtc.h b/os/hal/include/rtc.h
index e0a2c50c5..5adf9559c 100644
--- a/os/hal/include/rtc.h
+++ b/os/hal/include/rtc.h
@@ -75,8 +75,7 @@ extern "C" {
#endif /* RTC_SUPPORTS_CALLBACKS */
void rtcSetTime(uint32_t tv_sec);
- uint32_t rtcGetSec(void);
- uint16_t rtcGetMsec(void);
+ uint32_t rtcGetTime(uint16_t *msec);
void rtcSetAlarm(uint32_t tv_alarm);
uint32_t rtcGetAlarm(void);
#ifdef __cplusplus
diff --git a/os/hal/platforms/STM32/rtc_lld.c b/os/hal/platforms/STM32/rtc_lld.c
index 465f2f02e..6ae2a4aee 100644
--- a/os/hal/platforms/STM32/rtc_lld.c
+++ b/os/hal/platforms/STM32/rtc_lld.c
@@ -125,6 +125,7 @@ void rtc_lld_init(void){
#if STM32_RTC == STM32_RTC_LSE
if (! ((RCC->BDCR & RCC_BDCR_RTCEN) || (RCC->BDCR & RCC_BDCR_LSEON))){
RCC->BDCR |= RCC_BDCR_LSEON;
+ /* Note: cold start time of LSE oscillator on STM32 is about 3 seconds. */
while(!(RCC->BDCR & RCC_BDCR_LSERDY))
;
RCC->BDCR |= RCC_BDCR_RTCEN;
@@ -262,23 +263,20 @@ void rtc_lld_set_time(uint32_t tv_sec){
}
/**
- * @brief Return current time in UNIX notation.
+ * @brief Return return seconds since UNIX epoch.
*
- * @notapi
- */
-inline uint32_t rtc_lld_get_sec(void){
- return ((RTC->CNTH << 16) + RTC->CNTL);
-}
-
-/**
- * @brief Return fractional part of current time (milliseconds).
+ * @param[in] msec pointer to variable for storing fractional part of
+ * time (milliseconds).
*
* @notapi
*/
-inline uint16_t rtc_lld_get_msec(void){
+inline uint32_t rtc_lld_get_time(uint16_t *msec){
uint32_t time_frac = 0;
- time_frac = (((uint32_t)RTC->DIVH) << 16) + (RTC->DIVL);
- return(((STM32_LSECLK - time_frac) * 1000) / STM32_LSECLK);
+ if(msec != NULL){
+ time_frac = (((uint32_t)RTC->DIVH) << 16) + (RTC->DIVL);
+ *msec = (uint16_t)(((STM32_LSECLK - time_frac) * 1000) / STM32_LSECLK);
+ }
+ return ((RTC->CNTH << 16) + RTC->CNTL);
}
/**
diff --git a/os/hal/platforms/STM32/rtc_lld.h b/os/hal/platforms/STM32/rtc_lld.h
index 7d7d703f0..d73d35091 100644
--- a/os/hal/platforms/STM32/rtc_lld.h
+++ b/os/hal/platforms/STM32/rtc_lld.h
@@ -100,8 +100,7 @@ extern "C" {
void rtc_lld_set_callback(RTCDriver *rtcp, rtccb_t overflow_cb,
rtccb_t second_cb, rtccb_t alarm_cb);
void rtc_lld_set_time(uint32_t tv_sec);
- uint32_t rtc_lld_get_sec(void);
- uint16_t rtc_lld_get_msec(void);
+ uint32_t rtc_lld_get_time(uint16_t *msec);
uint32_t rtc_lld_get_alarm(void);
void rtc_lld_set_alarm(uint32_t);
#ifdef __cplusplus
diff --git a/os/hal/src/rtc.c b/os/hal/src/rtc.c
index ab916cf52..3b4b5824b 100644
--- a/os/hal/src/rtc.c
+++ b/os/hal/src/rtc.c
@@ -90,17 +90,15 @@ void rtcSetTime(uint32_t tv_sec){
}
/**
- * @brief Return current time in UNIX notation.
- */
-inline uint32_t rtcGetSec(void){
- return rtc_lld_get_sec();
-}
-
-/**
- * @brief Return fractional part of current time (milliseconds).
+ * @brief Return return seconds since UNIX epoch.
+ *
+ * @param[in] msec pointer to variable for storing fractional part of
+ * time (milliseconds).
+ *
+ * @notapi
*/
-inline uint16_t rtcGetMsec(void){
- return rtc_lld_get_msec();
+inline uint32_t rtcGetTime(uint16_t *msec){
+ return rtc_lld_get_time(msec);
}
/**