aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--os/hal/platforms/STM32/RTCv1/rtc_lld.c26
-rw-r--r--os/hal/platforms/STM32/RTCv1/rtc_lld.h2
-rw-r--r--os/hal/src/rtc.c20
-rw-r--r--testhal/STM32F1xx/RTC/main.c24
4 files changed, 32 insertions, 40 deletions
diff --git a/os/hal/platforms/STM32/RTCv1/rtc_lld.c b/os/hal/platforms/STM32/RTCv1/rtc_lld.c
index 1330e106e..e6088c342 100644
--- a/os/hal/platforms/STM32/RTCv1/rtc_lld.c
+++ b/os/hal/platforms/STM32/RTCv1/rtc_lld.c
@@ -60,16 +60,16 @@ static void rtc_lld_serve_interrupt(RTCDriver *rtcp) {
chSysLockFromIsr();
if ((RTC->CRH & RTC_CRH_SECIE) && (RTC->CRL & RTC_CRL_SECF)) {
+ RTC->CRL &= ~RTC_CRL_SECF;
rtcp->rtc_cb(rtcp, RTC_EVENT_SECOND);
- RTC->CRL &= ~RTC_CRL_SECF;
}
if ((RTC->CRH & RTC_CRH_ALRIE) && (RTC->CRL & RTC_CRL_ALRF)) {
- rtcp->rtc_cb(rtcp, RTC_EVENT_ALARM);
- RTC->CRL &= ~RTC_CRL_ALRF;
+ RTC->CRL &= ~RTC_CRL_ALRF;
+ rtcp->rtc_cb(rtcp, RTC_EVENT_ALARM);
}
if ((RTC->CRH & RTC_CRH_OWIE) && (RTC->CRL & RTC_CRL_OWF)) {
+ RTC->CRL &= ~RTC_CRL_OWF;
rtcp->rtc_cb(rtcp, RTC_EVENT_OVERFLOW);
- RTC->CRL &= ~RTC_CRL_OWF;
}
chSysUnlockFromIsr();
@@ -225,10 +225,8 @@ void rtc_lld_get_time(RTCDriver *rtcp, RTCTime *timespec) {
uint32_t time_frac;
READ_REGISTERS:
- chSysLock();
timespec->tv_sec = ((uint32_t)(RTC->CNTH) << 16) + RTC->CNTL;
time_frac = (((uint32_t)RTC->DIVH) << 16) + (uint32_t)RTC->DIVL;
- chSysUnlock();
/* If second counter updated between reading of integer and fractional parts
* we must reread both values. */
@@ -306,20 +304,22 @@ void rtc_lld_get_alarm(RTCDriver *rtcp,
*
* @notapi
*/
-void rtc_lld_set_callback(RTCDriver *rtcp, rtccb_t callback) {
-
- if (callback != NULL) {
- rtcp->rtc_cb = callback;
- NVICEnableVector(RTC_IRQn, CORTEX_PRIORITY_MASK(STM32_RTC_IRQ_PRIORITY));
+void rtc_lld_set_callback(RTCDriver *rtcp, RTCCallbackConfig *cb_cfg) {
+ if (cb_cfg->rtc_cb != NULL) {
+ rtcp->rtc_cb = cb_cfg->rtc_cb;
/* Interrupts are enabled only after setting up the callback, this
- way there is no need to check for the NULL callback pointer inside
- the IRQ handler.*/
+ way there is no need to check for the NULL callback pointer inside
+ the IRQ handler.*/
+ rtc_lld_wait_write();
RTC->CRL &= ~(RTC_CRL_OWF | RTC_CRL_ALRF | RTC_CRL_SECF);
+ NVICEnableVector(RTC_IRQn, CORTEX_PRIORITY_MASK(STM32_RTC_IRQ_PRIORITY));
+ rtc_lld_wait_write();
RTC->CRH |= RTC_CRH_OWIE | RTC_CRH_ALRIE | RTC_CRH_SECIE;
}
else {
NVICDisableVector(RTC_IRQn);
+ rtc_lld_wait_write();
RTC->CRL = 0;
RTC->CRH = 0;
}
diff --git a/os/hal/platforms/STM32/RTCv1/rtc_lld.h b/os/hal/platforms/STM32/RTCv1/rtc_lld.h
index 6e682db61..b49031126 100644
--- a/os/hal/platforms/STM32/RTCv1/rtc_lld.h
+++ b/os/hal/platforms/STM32/RTCv1/rtc_lld.h
@@ -166,7 +166,7 @@ extern "C" {
void rtc_lld_get_alarm(RTCDriver *rtcp,
rtcalarm_t alarm,
RTCAlarm *alarmspec);
- void rtc_lld_set_callback(RTCDriver *rtcp, rtccb_t callback);
+ void rtc_lld_set_callback(RTCDriver *rtcp, RTCCallbackConfig *cb_cfg);
#ifdef __cplusplus
}
#endif
diff --git a/os/hal/src/rtc.c b/os/hal/src/rtc.c
index 52e35fd22..37ab87c00 100644
--- a/os/hal/src/rtc.c
+++ b/os/hal/src/rtc.c
@@ -134,26 +134,6 @@ void rtcGetAlarm(RTCDriver *rtcp,
}
#endif /* RTC_ALARMS > 0 */
-/**
- * @brief Sets periodic wakeup period.
- */
-void rtcSetPeriodicWakeup(RTCDriver *rtcp, RTCWakeup *wakeupspec) {
- chDbgCheck((rtcp != NULL) && (wakeupspec != NULL), "rtcSetPeriodicWakeup");
- rtc_lld_set_periodic_wakeup(rtcp, wakeupspec);
-}
-/**
- * @brief Gets periodic wakeup period.
- */
-void rtcGetPeriodicWakeup(RTCDriver *rtcp, RTCWakeup *wakeupspec) {
- chDbgCheck((rtcp != NULL) && (wakeupspec != NULL), "rtcGetPeriodicWakeup");
- rtc_lld_get_periodic_wakeup(rtcp, wakeupspec);
-}
-
-
-
-
-
-
#if RTC_SUPPORTS_CALLBACKS || defined(__DOXYGEN__)
/**
diff --git a/testhal/STM32F1xx/RTC/main.c b/testhal/STM32F1xx/RTC/main.c
index 19043a02a..e8e3480ec 100644
--- a/testhal/STM32F1xx/RTC/main.c
+++ b/testhal/STM32F1xx/RTC/main.c
@@ -24,7 +24,7 @@
RTCTime timespec;
RTCAlarm alarmspec;
-#define TEST_ALARM_WAKEUP TRUE
+#define TEST_ALARM_WAKEUP FALSE
#if TEST_ALARM_WAKEUP
@@ -63,8 +63,10 @@ int main(void) {
#else /* TEST_ALARM_WAKEUP */
+/**
+ * Callback function for RTC.
+ */
static void my_cb(RTCDriver *rtcp, rtcevent_t event) {
-
(void)rtcp;
switch (event) {
@@ -77,21 +79,31 @@ static void my_cb(RTCDriver *rtcp, rtcevent_t event) {
case RTC_EVENT_ALARM:
palTogglePad(GPIOC, GPIOC_LED);
rtcGetTime(&RTCD1, &timespec);
- alarmspec.tv_sec = timespec.tv_sec + 10;
+ alarmspec.tv_sec = timespec.tv_sec + 5;
rtcSetAlarm(&RTCD1, 0, &alarmspec);
break;
}
}
-int main(void) {
+/**
+ * Configuration structure with all callbacks supported by platform.
+ */
+static RTCCallbackConfig rtc_cb_cfg = {
+ my_cb
+};
+
+/**
+ * Main function.
+ */
+int main(void){
halInit();
chSysInit();
rtcGetTime(&RTCD1, &timespec);
- alarmspec.tv_sec = timespec.tv_sec + 10;
+ alarmspec.tv_sec = timespec.tv_sec + 5;
rtcSetAlarm(&RTCD1, 0, &alarmspec);
- rtcSetCallback(&RTCD1, my_cb);
+ rtcSetCallback(&RTCD1, &rtc_cb_cfg);
while (TRUE){
chThdSleepMilliseconds(500);
}