aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbarthess <barthess@35acf78f-673a-0410-8e92-d51de3d6d3f4>2011-09-25 10:03:59 +0000
committerbarthess <barthess@35acf78f-673a-0410-8e92-d51de3d6d3f4>2011-09-25 10:03:59 +0000
commit41fd0fb5fb2d446605e7a99c11f46d7c28071500 (patch)
tree36e62fdc404fdbbacf5139a547ff8ac0e4d5bc15
parent5edc2c8b69cd60a1c53b565e529e099c36a243c4 (diff)
downloadChibiOS-41fd0fb5fb2d446605e7a99c11f46d7c28071500.tar.gz
ChibiOS-41fd0fb5fb2d446605e7a99c11f46d7c28071500.tar.bz2
ChibiOS-41fd0fb5fb2d446605e7a99c11f46d7c28071500.zip
RTC. API changes.
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@3405 35acf78f-673a-0410-8e92-d51de3d6d3f4
-rw-r--r--os/hal/include/rtc.h18
-rw-r--r--os/hal/platforms/STM32/RTCv1/rtc_lld.c (renamed from os/hal/platforms/STM32/rtc_lld.c)53
-rw-r--r--os/hal/platforms/STM32/RTCv1/rtc_lld.h (renamed from os/hal/platforms/STM32/rtc_lld.h)25
-rw-r--r--os/hal/platforms/STM32F1xx/platform.mk5
-rw-r--r--os/hal/src/rtc.c38
5 files changed, 93 insertions, 46 deletions
diff --git a/os/hal/include/rtc.h b/os/hal/include/rtc.h
index 5adf9559c..02aec2ceb 100644
--- a/os/hal/include/rtc.h
+++ b/os/hal/include/rtc.h
@@ -74,10 +74,20 @@ extern "C" {
rtccb_t secondcb, rtccb_t alarmcb);
#endif /* RTC_SUPPORTS_CALLBACKS */
- void rtcSetTime(uint32_t tv_sec);
- uint32_t rtcGetTime(uint16_t *msec);
- void rtcSetAlarm(uint32_t tv_alarm);
- uint32_t rtcGetAlarm(void);
+ void rtcSetTime(RTCDateTime *timespec);
+ void rtcGetTime(RTCDateTime *timespec);
+
+
+
+
+ void rtcSetAlarm(RTCDateTime *timespec);
+ void rtcGetAlarm(RTCDateTime *timespec);
+
+
+
+
+
+
#ifdef __cplusplus
}
#endif
diff --git a/os/hal/platforms/STM32/rtc_lld.c b/os/hal/platforms/STM32/RTCv1/rtc_lld.c
index c1163d1a1..a3329544e 100644
--- a/os/hal/platforms/STM32/rtc_lld.c
+++ b/os/hal/platforms/STM32/RTCv1/rtc_lld.c
@@ -245,18 +245,20 @@ void rtc_lld_set_callback(RTCDriver *rtcp, rtccb_t overflowcb,
/**
* @brief Set current time.
*
- * @param[in] tv_sec time value in UNIX notation.
+ * @param[in] timespec pointer to variable storing time.
*
+ * @note Fractional part will be silently ignored. There is no possibility
+ * to change it on STM32F1xx platform.
* @notapi
*/
-void rtc_lld_set_time(uint32_t tv_sec){
+void rtc_lld_set_time(RTCDateTime *timespec){
while(!(RTC->CRL & RTC_CRL_RTOFF))
;
RTC->CRL |= RTC_CRL_CNF; /* switch on configure mode */
- RTC->CNTH = (uint16_t)((tv_sec >> 16) & 0xFFFF); /* write time */
- RTC->CNTL = (uint16_t)(tv_sec & 0xFFFF);
+ RTC->CNTH = (uint16_t)((timespec->tv_sec >> 16) & 0xFFFF);
+ RTC->CNTL = (uint16_t)(timespec->tv_sec & 0xFFFF);
RTC->CRL &= ~RTC_CRL_CNF; /* switch off configure mode */
while(!(RTC->CRL & RTC_CRL_RTOFF)) /* wait for completion */
@@ -264,36 +266,41 @@ void rtc_lld_set_time(uint32_t tv_sec){
}
/**
- * @brief Return return seconds since UNIX epoch.
+ * @brief Get current time.
*
* @param[in] msec pointer to variable for storing fractional part of
* time (milliseconds).
*
* @notapi
*/
-inline uint32_t rtc_lld_get_time(uint16_t *msec){
+inline void rtc_lld_get_time(RTCDateTime *timespec){
uint32_t time_frac = 0;
- 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);
+ time_frac = (((uint32_t)RTC->DIVH) << 16) + (RTC->DIVL);
+
+ timespec->tv_msec = (uint16_t)(((STM32_LSECLK - time_frac) * 1000) / STM32_LSECLK);
+ timespec->tv_sec = (RTC->CNTH << 16) + RTC->CNTL;
}
/**
- * @brief Set alarm date in UNIX notation.
- * @note Default value after BKP domain reset is 0xFFFFFFFF
+ * @brief Set alarm time.
+ *
+ * @param[in] timespec pointer to variable storing time of alarm.
+ *
+ * @note Fractional part will be silently ignored. There is no possibility
+ * to change it on STM32F1xx platform.
+ *
+ * @note Default value after BKP domain reset is 0xFFFFFFFF
*
* @notapi
*/
-void rtc_lld_set_alarm(uint32_t tv_alarm){
+void rtc_lld_set_alarm(RTCDateTime *timespec){
while(!(RTC->CRL & RTC_CRL_RTOFF))
;
RTC->CRL |= RTC_CRL_CNF; /* switch on configure mode */
- RTC->ALRH = (uint16_t)((tv_alarm >> 16) & 0xFFFF); /* write time */
- RTC->ALRL = (uint16_t)(tv_alarm & 0xFFFF);
+ RTC->ALRH = (uint16_t)((timespec->tv_sec >> 16) & 0xFFFF);
+ RTC->ALRL = (uint16_t)(timespec->tv_sec & 0xFFFF);
RTC->CRL &= ~RTC_CRL_CNF; /* switch off configure mode */
#if !(RTC_SUPPORTS_CALLBACKS)
@@ -306,13 +313,19 @@ void rtc_lld_set_alarm(uint32_t tv_alarm){
}
/**
- * @brief Get current alarm date in UNIX notation.
- * @note Default value after BKP domain reset is 0xFFFFFFFF
+ * @brief Get current alarm time.
+ *
+ * @param[in] timespec pointer to variable storing time of alarm.
+ *
+ * @note Fractional part will be silently ignored. There is no possibility
+ * to change it on STM32F1xx platform.
+ *
+ * @note Default value after BKP domain reset is 0xFFFFFFFF
*
* @notapi
*/
-inline uint32_t rtc_lld_get_alarm(void){
- return ((RTC->ALRH << 16) + RTC->ALRL);
+inline void rtc_lld_get_alarm(RTCDateTime *timespec){
+ timespec->tv_sec = ((RTC->ALRH << 16) + RTC->ALRL);
}
diff --git a/os/hal/platforms/STM32/rtc_lld.h b/os/hal/platforms/STM32/RTCv1/rtc_lld.h
index d73d35091..125b6c11e 100644
--- a/os/hal/platforms/STM32/rtc_lld.h
+++ b/os/hal/platforms/STM32/RTCv1/rtc_lld.h
@@ -59,6 +59,21 @@
/* Driver data structures and types. */
/*===========================================================================*/
+
+
+
+
+typedef struct {
+ uint32_t tv_sec;
+ uint32_t tv_msec;
+}RTCDateTime;
+
+
+
+
+
+
+
/**
* @brief Structure representing an RTC driver.
* @note This driver if dummy when callbacks disabled.
@@ -99,10 +114,12 @@ extern "C" {
void rtc_lld_init(void);
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_time(uint16_t *msec);
- uint32_t rtc_lld_get_alarm(void);
- void rtc_lld_set_alarm(uint32_t);
+
+ void rtc_lld_set_time(RTCDateTime *timespec);
+ void rtc_lld_get_time(RTCDateTime *timespec);
+
+ void rtc_lld_get_alarm(RTCDateTime *timespec);
+ void rtc_lld_set_alarm(RTCDateTime *timespec);
#ifdef __cplusplus
}
#endif
diff --git a/os/hal/platforms/STM32F1xx/platform.mk b/os/hal/platforms/STM32F1xx/platform.mk
index 51601731e..a73f1b4f3 100644
--- a/os/hal/platforms/STM32F1xx/platform.mk
+++ b/os/hal/platforms/STM32F1xx/platform.mk
@@ -15,11 +15,12 @@ PLATFORMSRC = ${CHIBIOS}/os/hal/platforms/STM32F1xx/hal_lld.c \
${CHIBIOS}/os/hal/platforms/STM32/GPIOv1/pal_lld.c \
${CHIBIOS}/os/hal/platforms/STM32/DMAv1/stm32_dma.c \
${CHIBIOS}/os/hal/platforms/STM32/USBv1/usb_lld.c \
- ${CHIBIOS}/os/hal/platforms/STM32/rtc_lld.c
+ ${CHIBIOS}/os/hal/platforms/STM32/RTCv1/rtc_lld.c
# Required include directories
PLATFORMINC = ${CHIBIOS}/os/hal/platforms/STM32F1xx \
${CHIBIOS}/os/hal/platforms/STM32 \
${CHIBIOS}/os/hal/platforms/STM32/GPIOv1 \
${CHIBIOS}/os/hal/platforms/STM32/DMAv1 \
- ${CHIBIOS}/os/hal/platforms/STM32/USBv1
+ ${CHIBIOS}/os/hal/platforms/STM32/USBv1 \
+ ${CHIBIOS}/os/hal/platforms/STM32/RTCv1
diff --git a/os/hal/src/rtc.c b/os/hal/src/rtc.c
index 3b4b5824b..0c8959ea6 100644
--- a/os/hal/src/rtc.c
+++ b/os/hal/src/rtc.c
@@ -83,36 +83,42 @@ void rtcSetCallback(RTCDriver *rtcp, rtccb_t overflowcb,
/**
* @brief Set current time.
- * @param[in] tv_sec - time value in UNIX notation.
+ *
+ * @param[in] timespec pointer to variable storing time.
*/
-void rtcSetTime(uint32_t tv_sec){
- rtc_lld_set_time(tv_sec);
+void rtcSetTime(RTCDateTime *timespec){
+ chDbgCheck((timespec != NULL), "rtcSetTime");
+ rtc_lld_set_time(timespec);
}
/**
- * @brief Return return seconds since UNIX epoch.
- *
- * @param[in] msec pointer to variable for storing fractional part of
- * time (milliseconds).
+ * @brief Get current time.
*
- * @notapi
+ * @param[in] timespec pointer to variable storing time.
*/
-inline uint32_t rtcGetTime(uint16_t *msec){
- return rtc_lld_get_time(msec);
+void rtcGetTime(RTCDateTime *timespec){
+ chDbgCheck((timespec != NULL), "rtcGetTime");
+ rtc_lld_get_time(timespec);
}
/**
- * @brief Set alarm date in UNIX notation.
+ * @brief Set alarm time.
+ *
+ * @param[in] timespec pointer to variable storing time of alarm.
*/
-void rtcSetAlarm(uint32_t tv_alarm){
- rtc_lld_set_alarm(tv_alarm);
+void rtcSetAlarm(RTCDateTime *timespec){
+ chDbgCheck((timespec != NULL), "rtcSetAlarm");
+ rtc_lld_set_alarm(timespec);
}
/**
- * @brief Get current alarm date in UNIX notation.
+ * @brief Get current alarm.
+ *
+ * @param[in] timespec pointer to variable to store alarm time.
*/
-inline uint32_t rtcGetAlarm(void){
- return rtc_lld_get_alarm();
+void rtcGetAlarm(RTCDateTime *timespec){
+ chDbgCheck((timespec != NULL), "rtcGetAlarm");
+ rtc_lld_get_alarm(timespec);
}
#endif /* HAL_USE_RTC */