From 65520865b124dc0d47338e5384f48c8f31c9ebdd Mon Sep 17 00:00:00 2001
From: Hauke Petersen <hauke.petersen@fu-berlin.de>
Date: Fri, 7 Nov 2014 12:25:59 +0100
Subject: [PATCH] cpu/stm32f1: adjusted to RTT interface changes

---
 cpu/stm32f1/periph/rtt.c | 32 ++++++++++++++++++++++++++++++--
 1 file changed, 30 insertions(+), 2 deletions(-)

diff --git a/cpu/stm32f1/periph/rtt.c b/cpu/stm32f1/periph/rtt.c
index 3e4c54d779..281e840962 100644
--- a/cpu/stm32f1/periph/rtt.c
+++ b/cpu/stm32f1/periph/rtt.c
@@ -42,9 +42,15 @@ inline void _rtt_leave_config_mode(void);
 /*
  * callback and argument for an active alarm
  */
-static rtt_alarm_cb_t alarm_cb;
+static rtt_cb_t alarm_cb;
 static void *alarm_arg;
 
+/*
+ * callback and argument for overflow callback
+ */
+static rtt_cb_t overflow_cb;
+static void *overflow_arg;
+
 void rtt_init(void)
 {
     rtt_poweron();
@@ -69,6 +75,24 @@ void rtt_init(void)
     _rtt_leave_config_mode();
 }
 
+void rtt_set_overflow_cb(rtt_cb_t cb, void *arg)
+{
+    overflow_cb = cb;
+    overflow_arg = arg;
+    _rtt_enter_config_mode();
+    /* Enable overflow interrupt */
+    RTT_DEV->CRH |= RTC_CRH_OWIE;
+    _rtt_leave_config_mode();
+}
+
+void rtt_clear_overflow_cb(void)
+{
+    _rtt_enter_config_mode();
+    /* Clear overflow interrupt */
+    RTT_DEV->CRH &= ~(RTC_CRH_OWIE);
+    _rtt_leave_config_mode();
+}
+
 uint32_t rtt_get_counter(void)
 {
     /* wait for syncronization */
@@ -97,7 +121,7 @@ uint32_t rtt_get_alarm(void)
     return (((uint32_t)RTT_DEV->ALRH << 16 ) | (uint32_t)(RTT_DEV->ALRL));
 }
 
-void rtt_set_alarm(uint32_t alarm, rtt_alarm_cb_t cb, void *arg)
+void rtt_set_alarm(uint32_t alarm, rtt_cb_t cb, void *arg)
 {
     _rtt_enter_config_mode();
 
@@ -169,6 +193,10 @@ void RTT_ISR(void)
         RTT_DEV->CRL &= ~(RTC_CRL_ALRF);
         alarm_cb(alarm_arg);
     }
+    if (RTT_DEV->CRL & RTC_CRL_OWF) {
+        RTT_DEV->CRL &= ~(RTC_CRL_OWF);
+        overflow_cb(overflow_arg);
+    }
     if (sched_context_switch_request) {
         thread_yield();
     }
-- 
GitLab