From 9a98744b28ecfda0d78d5983e3a2d264c36bcec7 Mon Sep 17 00:00:00 2001 From: barthess Date: Thu, 15 Dec 2011 20:49:24 +0000 Subject: RTC. Testhal works on F4x, compiles (but not deeply tested) on F1x. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@3615 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/platforms/STM32/RTCv1/rtc_lld.h | 33 +++++++++++++++++++++++++++++++++ os/hal/platforms/STM32/RTCv2/rtc_lld.c | 27 ++++++++++++++++++++------- os/hal/platforms/STM32/RTCv2/rtc_lld.h | 15 ++++++++++----- 3 files changed, 63 insertions(+), 12 deletions(-) (limited to 'os/hal/platforms') 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 @@ -76,6 +76,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; -- cgit v1.2.3