aboutsummaryrefslogtreecommitdiffstats
path: root/os/hal
diff options
context:
space:
mode:
Diffstat (limited to 'os/hal')
-rw-r--r--os/hal/include/rtc.h2
-rw-r--r--os/hal/platforms/STM32/RTCv1/rtc_lld.h33
-rw-r--r--os/hal/platforms/STM32/RTCv2/rtc_lld.c27
-rw-r--r--os/hal/platforms/STM32/RTCv2/rtc_lld.h15
-rw-r--r--os/hal/src/rtc.c30
5 files changed, 94 insertions, 13 deletions
diff --git a/os/hal/include/rtc.h b/os/hal/include/rtc.h
index ddb495205..354640a11 100644
--- a/os/hal/include/rtc.h
+++ b/os/hal/include/rtc.h
@@ -85,6 +85,8 @@ extern "C" {
void rtcInit(void);
void rtcSetTime(RTCDriver *rtcp, const RTCTime *timespec);
void rtcGetTime(RTCDriver *rtcp, RTCTime *timespec);
+ void rtcSetWakeup(RTCDriver *rtcp, RTCWakeup *wakeupspec);
+ void rtcGetWakeup(RTCDriver *rtcp, RTCWakeup *wakeupspec);
#if RTC_ALARMS > 0
void rtcSetAlarm(RTCDriver *rtcp,
diff --git a/os/hal/platforms/STM32/RTCv1/rtc_lld.h b/os/hal/platforms/STM32/RTCv1/rtc_lld.h
index b49031126..9237e4dc8 100644
--- a/os/hal/platforms/STM32/RTCv1/rtc_lld.h
+++ b/os/hal/platforms/STM32/RTCv1/rtc_lld.h
@@ -77,6 +77,11 @@ typedef struct RTCAlarm RTCAlarm;
typedef struct RTCCallbackConfig RTCCallbackConfig;
/**
+ * @brief Type of a structure representing an RTC wakeup period.
+ */
+typedef struct RTCWakeup RTCWakeup;
+
+/**
* @brief Type of an RTC alarm.
* @details Meaningful on platforms with more than 1 alarm comparator.
*/
@@ -142,9 +147,37 @@ struct RTCDriver{
rtccb_t rtc_cb;
};
+/**
+ * @brief Structure representing an RTC periodic wakeup period.
+ * @note On this platform it is pointless.
+ */
+struct RTCWakeup {
+};
+
/*===========================================================================*/
/* Driver macros. */
/*===========================================================================*/
+/**
+ * @brief Gets time of periodic wakeup.
+ *
+ * @note On this platform function is pointless.
+ * There is no possibilities to change period on this platform.
+ * It always equal to 1 second.
+ *
+ * @notapi
+ */
+#define rtc_lld_set_periodic_wakeup(rtcp, wakeupspec){(void)wakeupspec;}
+
+/**
+ * @brief Gets time of periodic wakeup.
+ *
+ * @note On this platform function is pointless.
+ * There is no possibilities to change period on this platform.
+ * It always equal to 1 second.
+ *
+ * @notapi
+ */
+#define rtc_lld_get_periodic_wakeup(rtcp, wakeupspec){(void)wakeupspec;}
/*===========================================================================*/
/* External declarations. */
diff --git a/os/hal/platforms/STM32/RTCv2/rtc_lld.c b/os/hal/platforms/STM32/RTCv2/rtc_lld.c
index 3fdc7ceee..ca15dc1b9 100644
--- a/os/hal/platforms/STM32/RTCv2/rtc_lld.c
+++ b/os/hal/platforms/STM32/RTCv2/rtc_lld.c
@@ -185,12 +185,12 @@ void rtc_lld_get_time(RTCDriver *rtcp, RTCTime *timespec) {
while(!(RTC->ISR & RTC_ISR_RSF))
;
- timespec->tv_time = RTCD1.id_rtc->TR;
- timespec->tv_date = RTCD1.id_rtc->DR;
#if STM32_RTC_HAS_SUBSECONDS
- timespec->tv_msec = ((RTCD1.id_rtc->PRER & 0x7FFF) - RTCD1.id_rtc->SSR) /
+ timespec->tv_msec = (1000 * (RTCD1.id_rtc->PRER & 0x7FFF) - RTCD1.id_rtc->SSR) /
((RTCD1.id_rtc->PRER & 0x7FFF) + 1);
#endif /* STM32_RTC_HAS_SUBSECONDS */
+ timespec->tv_time = RTCD1.id_rtc->TR;
+ timespec->tv_date = RTCD1.id_rtc->DR;
}
/**
@@ -297,26 +297,39 @@ void rtc_lld_get_periodic_wakeup(RTCDriver *rtcp, RTCWakeup *wakeupspec){
*/
void rtc_lld_set_callback(RTCDriver *rtcp, RTCCallbackConfig *cb_cfg) {
- if (cb_cfg->cb_cfg & ALARMA_INT)
+ if (cb_cfg->cb_cfg & ALARMA_CB_FLAG)
rtcp->id_rtc->CR |= RTC_CR_ALRAIE;
else
rtcp->id_rtc->CR &= ~RTC_CR_ALRAIE;
- if (cb_cfg->cb_cfg & ALARMB_INT)
+ if (cb_cfg->cb_cfg & ALARMB_CB_FLAG)
rtcp->id_rtc->CR |= RTC_CR_ALRBIE;
else
rtcp->id_rtc->CR &= ~RTC_CR_ALRBIE;
- if (cb_cfg->cb_cfg & WAKEUP_INT)
+ if (cb_cfg->cb_cfg & WAKEUP_CB_FLAG)
rtcp->id_rtc->CR |= RTC_CR_WUTIE;
else
rtcp->id_rtc->CR &= ~RTC_CR_WUTIE;
- if (cb_cfg->cb_cfg & TIMESTAMP_INT)
+ if (cb_cfg->cb_cfg & TIMESTAMP_CB_FLAG)
rtcp->id_rtc->CR |= RTC_CR_TSIE;
else
rtcp->id_rtc->CR &= ~RTC_CR_TSIE;
}
+
+/**
+ * @brief Gets current RTC callbacks.
+ *
+ * @param[in] rtcp pointer to RTC driver structure
+ * @param[out] cb_cfg callback bitmask
+ *
+ * @notapi
+ */
+void rtc_lld_get_callback(RTCDriver *rtcp, RTCCallbackConfig *cb_cfg) {
+ cb_cfg->cb_cfg = rtcp->cb_cfg->cb_cfg;
+}
+
#endif /* RTC_SUPPORTS_CALLBACKS */
#endif /* HAL_USE_RTC */
diff --git a/os/hal/platforms/STM32/RTCv2/rtc_lld.h b/os/hal/platforms/STM32/RTCv2/rtc_lld.h
index 8e1b58f6b..23ceb3132 100644
--- a/os/hal/platforms/STM32/RTCv2/rtc_lld.h
+++ b/os/hal/platforms/STM32/RTCv2/rtc_lld.h
@@ -48,12 +48,12 @@
#define RTC_ALARMS 2
/**
- * @brief Interrupt enable masks.
+ * @brief Callback enable masks.
*/
-#define ALARMA_INT 0x1
-#define ALARMB_INT 0x2
-#define WAKEUP_INT 0x4
-#define TIMESTAMP_INT 0x8
+#define ALARMA_CB_FLAG 0x1
+#define ALARMB_CB_FLAG 0x2
+#define WAKEUP_CB_FLAG 0x4
+#define TIMESTAMP_CB_FLAG 0x8
/*===========================================================================*/
/* Driver pre-compile time settings. */
@@ -158,6 +158,11 @@ struct RTCWakeup {
/**
* @brief Structure representing an RTC callbacks config.
+ * @details It is bitmask. Set bit to enable callback, clear bit to disable.
+ * bit0 - alarmA
+ * bit1 - alarmB
+ * bit2 - wakeup
+ * bit3 - timestamp
*/
struct RTCCallbackConfig{
uint32_t cb_cfg;
diff --git a/os/hal/src/rtc.c b/os/hal/src/rtc.c
index 9df399eeb..20a39ea7c 100644
--- a/os/hal/src/rtc.c
+++ b/os/hal/src/rtc.c
@@ -135,10 +135,38 @@ void rtcGetAlarm(RTCDriver *rtcp,
#endif /* RTC_ALARMS > 0 */
+
+/**
+ * @brief Set periodic wakeup period.
+ *
+ * @param[in] rtcp pointer to RTC driver structure
+ * @param[in] wakeupspec pointer to a @p RTCWakeup structure
+ *
+ * @api
+ */
+void rtcSetWakeup(RTCDriver *rtcp, RTCWakeup *wakeupspec) {
+
+ chDbgCheck((rtcp != NULL), "rtcGetAlarm");
+ rtc_lld_set_periodic_wakeup(rtcp, wakeupspec);
+}
+
+/**
+ * @brief Get periodic wakeup period.
+ *
+ * @param[in] rtcp pointer to RTC driver structure
+ * @param[out] wakeupspec pointer to a @p RTCWakeup structure
+ *
+ * @api
+ */
+void rtcGetWakeup(RTCDriver *rtcp, RTCWakeup *wakeupspec) {
+
+ chDbgCheck((rtcp != NULL), "rtcGetAlarm");
+ rtc_lld_get_periodic_wakeup(rtcp, wakeupspec);
+}
+
#if RTC_SUPPORTS_CALLBACKS || defined(__DOXYGEN__)
/**
* @brief Enables or disables RTC callbacks.
- * @details TODO:
*
* @param[in] rtcp pointer to RTC driver structure
* @param[in] cb_cfg callback configuration struct