From 35ea7347004a31e1b850c41b60a3bf7457ed4418 Mon Sep 17 00:00:00 2001 From: barthess Date: Tue, 13 Dec 2011 09:03:41 +0000 Subject: RTC. Added callback switch helper. Not tested. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@3608 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/platforms/STM32/RTCv2/rtc_lld.c | 83 ++++++++-------------------------- os/hal/platforms/STM32/RTCv2/rtc_lld.h | 36 ++++----------- 2 files changed, 30 insertions(+), 89 deletions(-) (limited to 'os/hal/platforms/STM32/RTCv2') diff --git a/os/hal/platforms/STM32/RTCv2/rtc_lld.c b/os/hal/platforms/STM32/RTCv2/rtc_lld.c index f549dc62d..3fdc7ceee 100644 --- a/os/hal/platforms/STM32/RTCv2/rtc_lld.c +++ b/os/hal/platforms/STM32/RTCv2/rtc_lld.c @@ -187,11 +187,9 @@ void rtc_lld_get_time(RTCDriver *rtcp, RTCTime *timespec) { timespec->tv_time = RTCD1.id_rtc->TR; timespec->tv_date = RTCD1.id_rtc->DR; -#if RTC_HAS_SUBSECONDS +#if STM32_RTC_HAS_SUBSECONDS timespec->tv_msec = ((RTCD1.id_rtc->PRER & 0x7FFF) - RTCD1.id_rtc->SSR) / ((RTCD1.id_rtc->PRER & 0x7FFF) + 1); -#else - timespec->tv_msec = 0; #endif /* STM32_RTC_HAS_SUBSECONDS */ } @@ -282,45 +280,15 @@ void rtc_lld_get_periodic_wakeup(RTCDriver *rtcp, RTCWakeup *wakeupspec){ wakeupspec->wakeup |= (((uint32_t)rtcp->id_rtc->CR) & 0x7) << 16; } - #if RTC_SUPPORTS_CALLBACKS -static const EXTConfig rtc_extcfg = { - { - {EXT_CH_MODE_DISABLED, NULL}, - {EXT_CH_MODE_DISABLED, NULL}, - {EXT_CH_MODE_DISABLED, NULL}, - {EXT_CH_MODE_DISABLED, NULL}, - {EXT_CH_MODE_DISABLED, NULL}, - {EXT_CH_MODE_DISABLED, NULL}, - {EXT_CH_MODE_DISABLED, NULL}, - {EXT_CH_MODE_DISABLED, NULL}, - {EXT_CH_MODE_DISABLED, NULL}, - {EXT_CH_MODE_DISABLED, NULL}, - {EXT_CH_MODE_DISABLED, NULL}, - {EXT_CH_MODE_DISABLED, NULL}, - {EXT_CH_MODE_DISABLED, NULL}, - {EXT_CH_MODE_DISABLED, NULL}, - {EXT_CH_MODE_DISABLED, NULL}, - {EXT_CH_MODE_DISABLED, NULL}, - {EXT_CH_MODE_DISABLED, NULL}, - {EXT_CH_MODE_RISING_EDGE, NULL}, //17, RTC alarm - {EXT_CH_MODE_DISABLED, NULL}, - {EXT_CH_MODE_DISABLED, NULL}, - {EXT_CH_MODE_DISABLED, NULL}, - {EXT_CH_MODE_RISING_EDGE, NULL}, //21 RTC tamper - {EXT_CH_MODE_RISING_EDGE, NULL} //22 RTC wakeup - }, - EXT_MODE_EXTI(0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0) -}; - - - /** * @brief Enables or disables RTC callbacks. - * @details TODO: + * @details To enable interrupt set corresponding bit in @p RTCCallbackConfig + * structure. To disable interrupt clear that bit. + * @note This function just enable/disable interrupts in RTC CR register. + * You must configure callbacks in EXTI driver for corresponding + * interrupts. See documentation for you MCU. * * @param[in] rtcp pointer to RTC driver structure * @param[in] cb_cfg pointer to configuration structure with callbacks @@ -329,36 +297,25 @@ static const EXTConfig rtc_extcfg = { */ void rtc_lld_set_callback(RTCDriver *rtcp, RTCCallbackConfig *cb_cfg) { - /* To configure callback we must confugure EXTI interrupt on - * corresponding line. - * And then enable interrupts in RTC CR register. */ - - if (cb_cfg->alarm_cb != NULL){ - rtc_extcfg.channels[STM32_RTC_ALARM_EXTI_CH].cb = cb_cfg->alarm_cb; - rtcp->id_rtc->CR |= RTC_CR_ALRBIE; + if (cb_cfg->cb_cfg & ALARMA_INT) rtcp->id_rtc->CR |= RTC_CR_ALRAIE; - } - else{ - extChannelDisable(&EXTD1, STM32_RTC_ALARM_EXTI_CH); - } + else + rtcp->id_rtc->CR &= ~RTC_CR_ALRAIE; - if (cb_cfg->tamper_timestapm_cb != NULL){ - rtc_extcfg.channels[STM32_RTC_TAMPER_TIMESTAMP_EXTI_CH].cb = cb_cfg->tamper_timestapm_cb; - rtcp->id_rtc->CR |= RTC_CR_TSIE; - } - else{ - extChannelDisable(&EXTD1, STM32_RTC_TAMPER_TIMESTAMP_EXTI_CH); - } + if (cb_cfg->cb_cfg & ALARMB_INT) + rtcp->id_rtc->CR |= RTC_CR_ALRBIE; + else + rtcp->id_rtc->CR &= ~RTC_CR_ALRBIE; - if (cb_cfg->wakeup_cb != NULL){ - rtc_extcfg.channels[STM32_RTC_WAKEUP_EXTI_CH].cb = cb_cfg->wakeup_cb; + if (cb_cfg->cb_cfg & WAKEUP_INT) rtcp->id_rtc->CR |= RTC_CR_WUTIE; - } - else{ - extChannelDisable(&EXTD1, STM32_RTC_WAKEUP_EXTI_CH); - } + else + rtcp->id_rtc->CR &= ~RTC_CR_WUTIE; - extStart(&EXTD1, &rtc_extcfg); + if (cb_cfg->cb_cfg & TIMESTAMP_INT) + rtcp->id_rtc->CR |= RTC_CR_TSIE; + else + rtcp->id_rtc->CR &= ~RTC_CR_TSIE; } #endif /* RTC_SUPPORTS_CALLBACKS */ diff --git a/os/hal/platforms/STM32/RTCv2/rtc_lld.h b/os/hal/platforms/STM32/RTCv2/rtc_lld.h index 3780945c4..8e1b58f6b 100644 --- a/os/hal/platforms/STM32/RTCv2/rtc_lld.h +++ b/os/hal/platforms/STM32/RTCv2/rtc_lld.h @@ -48,11 +48,12 @@ #define RTC_ALARMS 2 /** - * @brief EXTI channel numbers for different RTC events. + * @brief Interrupt enable masks. */ -#define STM32_RTC_ALARM_EXTI_CH 17 -#define STM32_RTC_TAMPER_TIMESTAMP_EXTI_CH 21 -#define STM32_RTC_WAKEUP_EXTI_CH 22 +#define ALARMA_INT 0x1 +#define ALARMB_INT 0x2 +#define WAKEUP_INT 0x4 +#define TIMESTAMP_INT 0x8 /*===========================================================================*/ /* Driver pre-compile time settings. */ @@ -111,11 +112,6 @@ typedef enum { RTC_EVENT_TIMESTAMP = 4, /** Triggered on TimeStamp event. */ } rtcevent_t; -/** - * @brief Type of a generic RTC callback. - */ -typedef void (*rtccb_t)(RTCDriver *rtcp, rtcevent_t event); - /** * @brief Structure representing an RTC time stamp. */ @@ -130,9 +126,10 @@ struct RTCTime { uint32_t tv_time; /** * @brief Fractional part of time. - * @note If platform does not support subseconds than always zero. */ +#if STM32_RTC_HAS_SUBSECONDS uint32_t tv_msec; +#endif }; /** @@ -163,20 +160,7 @@ struct RTCWakeup { * @brief Structure representing an RTC callbacks config. */ struct RTCCallbackConfig{ -#if RTC_SUPPORTS_CALLBACKS - /** - * @brief Alarm callback pointer. - */ - rtccb_t alarm_cb; - /** - * @brief Tamper or TimeStamp callback pointer. - */ - rtccb_t tamper_timestapm_cb; - /** - * @brief Periodic wakeup callback pointer. - */ - rtccb_t wakeup_cb; -#endif /* RTC_SUPPORTS_CALLBACKS */ + uint32_t cb_cfg; }; /** @@ -188,9 +172,9 @@ struct RTCDriver{ */ RTC_TypeDef *id_rtc; /** - * @brief Current configuration data. + * @brief Current callback confuguration. */ - const RTCCallbackConfig *cb_config; + const RTCCallbackConfig *cb_cfg; }; /*===========================================================================*/ -- cgit v1.2.3