aboutsummaryrefslogtreecommitdiffstats
path: root/os
diff options
context:
space:
mode:
authorbarthess <barthess@35acf78f-673a-0410-8e92-d51de3d6d3f4>2012-01-13 20:38:02 +0000
committerbarthess <barthess@35acf78f-673a-0410-8e92-d51de3d6d3f4>2012-01-13 20:38:02 +0000
commita2672b8dbb01e460ed1a000143bd22add48fc2b7 (patch)
tree57189ed4ab88b97abc97a25469d7d6f04a38bc54 /os
parent03ab00297198821c5dfc2003b584da8ed734de39 (diff)
downloadChibiOS-a2672b8dbb01e460ed1a000143bd22add48fc2b7.tar.gz
ChibiOS-a2672b8dbb01e460ed1a000143bd22add48fc2b7.tar.bz2
ChibiOS-a2672b8dbb01e460ed1a000143bd22add48fc2b7.zip
RTC. Error fixes and robustness improvements.
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@3806 35acf78f-673a-0410-8e92-d51de3d6d3f4
Diffstat (limited to 'os')
-rw-r--r--os/hal/platforms/STM32/RTCv1/rtc_lld.c30
1 files changed, 14 insertions, 16 deletions
diff --git a/os/hal/platforms/STM32/RTCv1/rtc_lld.c b/os/hal/platforms/STM32/RTCv1/rtc_lld.c
index 13f303bbe..811920e06 100644
--- a/os/hal/platforms/STM32/RTCv1/rtc_lld.c
+++ b/os/hal/platforms/STM32/RTCv1/rtc_lld.c
@@ -60,37 +60,32 @@ RTCDriver RTCD1;
*
* @notapi
*/
-static void rtc_lld_apb1_sync(void) {
+#define rtc_lld_apb1_sync() {while ((RTC->CRL & RTC_CRL_RSF) == 0);}
- while ((RTC->CRL & RTC_CRL_RSF) == 0)
- ;
-}
+/**
+ * @brief Wait for for previous write operation complete.
+ * @details This function must be invoked before writing to any RTC registers
+ *
+ * @notapi
+ */
+#define rtc_lld_wait_write() {while ((RTC->CRL & RTC_CRL_RTOFF) == 0);}
/**
* @brief Acquires write access to RTC registers.
* @details Before writing to the backup domain RTC registers the previous
* write operation must be completed. Use this function before
- * writing to PRL, CNT, ALR registers. CR registers can always
- * be written.
+ * writing to PRL, CNT, ALR registers.
*
* @notapi
*/
-static void rtc_lld_acquire(void) {
-
- while ((RTC->CRL & RTC_CRL_RTOFF) == 0)
- ;
- RTC->CRL |= RTC_CRL_CNF;
-}
+#define rtc_lld_acquire() {rtc_lld_wait_write(); RTC->CRL |= RTC_CRL_CNF;}
/**
* @brief Releases write access to RTC registers.
*
* @notapi
*/
-static void rtc_lld_release(void) {
-
- RTC->CRL &= ~RTC_CRL_CNF;
-}
+#define rtc_lld_release() {RTC->CRL &= ~RTC_CRL_CNF;}
/*===========================================================================*/
/* Driver interrupt handlers. */
@@ -149,6 +144,7 @@ void rtc_lld_init(void){
}
/* All interrupts initially disabled.*/
+ rtc_lld_wait_write();
RTC->CRH = 0;
/* Callback initially disabled.*/
@@ -277,10 +273,12 @@ void rtc_lld_set_callback(RTCDriver *rtcp, rtccb_t callback) {
/* IRQ sources enabled only after setting up the callback.*/
rtcp->callback = callback;
+ rtc_lld_wait_write();
RTC->CRL &= ~(RTC_CRL_OWF | RTC_CRL_ALRF | RTC_CRL_SECF);
RTC->CRH = RTC_CRH_OWIE | RTC_CRH_ALRIE | RTC_CRH_SECIE;
}
else {
+ rtc_lld_wait_write();
RTC->CRH = 0;
/* Callback set to NULL only after disabling the IRQ sources.*/