diff options
author | barthess <barthess@35acf78f-673a-0410-8e92-d51de3d6d3f4> | 2011-09-25 10:03:59 +0000 |
---|---|---|
committer | barthess <barthess@35acf78f-673a-0410-8e92-d51de3d6d3f4> | 2011-09-25 10:03:59 +0000 |
commit | 41fd0fb5fb2d446605e7a99c11f46d7c28071500 (patch) | |
tree | 36e62fdc404fdbbacf5139a547ff8ac0e4d5bc15 /os/hal/platforms/STM32 | |
parent | 5edc2c8b69cd60a1c53b565e529e099c36a243c4 (diff) | |
download | ChibiOS-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
Diffstat (limited to 'os/hal/platforms/STM32')
-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 |
2 files changed, 54 insertions, 24 deletions
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
|