From facfe77b186a05dde255b4c66d22cdddaf0fd0f6 Mon Sep 17 00:00:00 2001 From: barthess Date: Mon, 12 Dec 2011 10:56:51 +0000 Subject: RTC. Development suspended until EXTI driver API will changed. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/rtc_dev@3600 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/platforms/STM32/RTCv1/rtc_lld.c | 8 +-- os/hal/platforms/STM32/RTCv2/rtc_lld.c | 120 ++++++++++++++++++++++----------- os/hal/platforms/STM32/RTCv2/rtc_lld.h | 19 ++++-- os/hal/src/rtc.c | 10 +-- 4 files changed, 101 insertions(+), 56 deletions(-) (limited to 'os/hal') diff --git a/os/hal/platforms/STM32/RTCv1/rtc_lld.c b/os/hal/platforms/STM32/RTCv1/rtc_lld.c index 88c0814fc..931d028f4 100644 --- a/os/hal/platforms/STM32/RTCv1/rtc_lld.c +++ b/os/hal/platforms/STM32/RTCv1/rtc_lld.c @@ -215,7 +215,7 @@ void rtc_lld_set_time(RTCDriver *rtcp, const RTCTime *timespec) { * @brief Get current time. * * @param[in] rtcp pointer to RTC driver structure - * @param[in] timespec pointer to a @p RTCTime structure + * @param[out] timespec pointer to a @p RTCTime structure * * @notapi */ @@ -280,9 +280,9 @@ void rtc_lld_set_alarm(RTCDriver *rtcp, * * @note Default value after BKP domain reset is 0xFFFFFFFF. * - * @param[in] rtcp pointer to RTC driver structure - * @param[in] alarm alarm identifier - * @param[in] alarmspec pointer to a @p RTCAlarm structure + * @param[in] rtcp pointer to RTC driver structure + * @param[in] alarm alarm identifier + * @param[out] alarmspec pointer to a @p RTCAlarm structure * * @notapi */ diff --git a/os/hal/platforms/STM32/RTCv2/rtc_lld.c b/os/hal/platforms/STM32/RTCv2/rtc_lld.c index cc1e846e7..f549dc62d 100644 --- a/os/hal/platforms/STM32/RTCv2/rtc_lld.c +++ b/os/hal/platforms/STM32/RTCv2/rtc_lld.c @@ -89,7 +89,7 @@ void rtc_lld_init(void){ #define PREDIV_A ((uint32_t)0x7F) /* Add async part to preload value. */ - uint32_t preload = PREDIV_A << 16; + volatile uint32_t preload = PREDIV_A << 16; /* Enables access to BKP registers.*/ PWR->CR |= PWR_CR_DBP; @@ -128,13 +128,12 @@ void rtc_lld_init(void){ /* RTC enabled regardless its previous status.*/ RCC->BDCR |= RCC_BDCR_RTCEN; + /* Disable write protection on RTC registers. */ + RTCD1.id_rtc->WPR = 0xCA; + RTCD1.id_rtc->WPR = 0x53; + /* If calendar not init yet. */ if (!(RTC->ISR & RTC_ISR_INITS)){ - /* Disable write protection on RTC registers. */ - - RTCD1.id_rtc->WPR = 0xCA; - RTCD1.id_rtc->WPR = 0x53; - /* Enter in init mode. */ RTCD1.id_rtc->ISR |= RTC_ISR_INIT; while(!(RTC->ISR & RTC_ISR_INITF)) @@ -146,6 +145,7 @@ void rtc_lld_init(void){ } } + /** * @brief Set current time. * @note Fractional part will be silently ignored. There is no possibility @@ -229,9 +229,9 @@ void rtc_lld_set_alarm(RTCDriver *rtcp, /** * @brief Get alarm time. * - * @param[in] rtcp pointer to RTC driver structure - * @param[in] alarm alarm identifier - * @param[in] alarmspec pointer to a @p RTCAlarm structure + * @param[in] rtcp pointer to RTC driver structure + * @param[in] alarm alarm identifier + * @param[out] alarmspec pointer to a @p RTCAlarm structure * * @notapi */ @@ -255,14 +255,14 @@ void rtc_lld_get_alarm(RTCDriver *rtcp, * @notapi */ void rtc_lld_set_periodic_wakeup(RTCDriver *rtcp, RTCWakeup *wakeupspec){ - chDbgCheck((wakeupspec->wutr != 0) || ((wakeupspec->wucksel & 0x7) != 3), + chDbgCheck((wakeupspec->wakeup != 0x30000), "rtc_lld_set_periodic_wakeup, forbidden combination"); rtcp->id_rtc->CR &= ~RTC_CR_WUTE; while(!(rtcp->id_rtc->ISR & RTC_ISR_WUTWF)) ; - rtcp->id_rtc->WUTR = wakeupspec->wutr & 0xFFFF; - rtcp->id_rtc->CR = wakeupspec->wucksel & 0x7; + rtcp->id_rtc->WUTR = wakeupspec->wakeup & 0xFFFF; + rtcp->id_rtc->CR = (wakeupspec->wakeup >> 16) & 0x7; rtcp->id_rtc->CR |= RTC_CR_WUTE; } @@ -271,20 +271,50 @@ void rtc_lld_set_periodic_wakeup(RTCDriver *rtcp, RTCWakeup *wakeupspec){ * * @note Default value after BKP domain reset is 0x0000FFFF * - * @param[in] rtcp pointer to RTC driver structure - * @param[in] wakeupspec pointer to a @p RTCWakeup structure + * @param[in] rtcp pointer to RTC driver structure + * @param[out] wakeupspec pointer to a @p RTCWakeup structure * * @notapi */ void rtc_lld_get_periodic_wakeup(RTCDriver *rtcp, RTCWakeup *wakeupspec){ - wakeupspec->wutr = rtcp->id_rtc->WUTR; - wakeupspec->wucksel = rtcp->id_rtc->CR & 0x7; + wakeupspec->wakeup = 0; + wakeupspec->wakeup |= rtcp->id_rtc->WUTR; + 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) +}; @@ -293,30 +323,44 @@ void rtc_lld_get_periodic_wakeup(RTCDriver *rtcp, RTCWakeup *wakeupspec){ * @details TODO: * * @param[in] rtcp pointer to RTC driver structure - * @param[in] callback callback function pointer or @p NULL + * @param[in] cb_cfg pointer to configuration structure with callbacks * * @notapi */ void rtc_lld_set_callback(RTCDriver *rtcp, RTCCallbackConfig *cb_cfg) { - (void)rtcp; - (void)cb_cfg; -// if (callback != NULL) { -// rtcp->rtc_cb = callback; -// NVICEnableVector(RTC_IRQn, CORTEX_PRIORITY_MASK(STM32_RTC_IRQ_PRIORITY)); -// -// /* 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.*/ -// RTC->CRL &= ~(RTC_CRL_OWF | RTC_CRL_ALRF | RTC_CRL_SECF); -// RTC->CRH |= RTC_CRH_OWIE | RTC_CRH_ALRIE | RTC_CRH_SECIE; -// } -// else { -// NVICDisableVector(RTC_IRQn); -// RTC->CRL = 0; -// RTC->CRH = 0; -// } -} + /* 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; + rtcp->id_rtc->CR |= RTC_CR_ALRAIE; + } + else{ + extChannelDisable(&EXTD1, STM32_RTC_ALARM_EXTI_CH); + } + + 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->wakeup_cb != NULL){ + rtc_extcfg.channels[STM32_RTC_WAKEUP_EXTI_CH].cb = cb_cfg->wakeup_cb; + rtcp->id_rtc->CR |= RTC_CR_WUTIE; + } + else{ + extChannelDisable(&EXTD1, STM32_RTC_WAKEUP_EXTI_CH); + } + + extStart(&EXTD1, &rtc_extcfg); +} +#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 626f236a0..3780945c4 100644 --- a/os/hal/platforms/STM32/RTCv2/rtc_lld.h +++ b/os/hal/platforms/STM32/RTCv2/rtc_lld.h @@ -47,6 +47,13 @@ */ #define RTC_ALARMS 2 +/** + * @brief EXTI channel numbers for different RTC events. + */ +#define STM32_RTC_ALARM_EXTI_CH 17 +#define STM32_RTC_TAMPER_TIMESTAMP_EXTI_CH 21 +#define STM32_RTC_WAKEUP_EXTI_CH 22 + /*===========================================================================*/ /* Driver pre-compile time settings. */ /*===========================================================================*/ @@ -143,13 +150,13 @@ struct RTCAlarm { */ struct RTCWakeup { /** - * @brief RTC WUTR register. - */ - uint32_t wutr; - /** - * @brief RTC WUCKSEL bits of CR register. + * @brief RTC WUTR register. + * @details Bits [15:0] contain value of WUTR register + * Bits [18:16] contain value of WUCKSEL bits in CR register + * + * @notes ((WUTR == 0) || (WUCKSEL == 3)) is forbidden combination. */ - uint32_t wucksel; + uint32_t wakeup; }; /** diff --git a/os/hal/src/rtc.c b/os/hal/src/rtc.c index f7ce21529..52e35fd22 100644 --- a/os/hal/src/rtc.c +++ b/os/hal/src/rtc.c @@ -117,8 +117,8 @@ void rtcSetAlarm(RTCDriver *rtcp, * @note If an alarm has not been set then the returned alarm specification * is not meaningful. * - * @param[in] rtcp pointer to RTC driver structure - * @param[in] alarm alarm identifier + * @param[in] rtcp pointer to RTC driver structure + * @param[in] alarm alarm identifier * @param[out] alarmspec pointer to a @p RTCAlarm structure * * @api @@ -134,12 +134,6 @@ void rtcGetAlarm(RTCDriver *rtcp, } #endif /* RTC_ALARMS > 0 */ - - - - - - /** * @brief Sets periodic wakeup period. */ -- cgit v1.2.3