From 22d2162db773e677c900b8b397889b7087470248 Mon Sep 17 00:00:00 2001 From: barthess Date: Tue, 30 Aug 2011 22:52:11 +0000 Subject: RTC. Initial commit. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/rtc_dev@3269 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/hal.mk | 3 +- os/hal/include/hal.h | 1 + os/hal/include/rtc.h | 77 +++++++++++ os/hal/platforms/STM32/rtc_lld.c | 236 +++++++++++++++++++++++++++++++++ os/hal/platforms/STM32/rtc_lld.h | 100 ++++++++++++++ os/hal/platforms/STM32F1xx/platform.mk | 3 +- os/hal/src/hal.c | 3 + os/hal/src/rtc.c | 108 +++++++++++++++ 8 files changed, 529 insertions(+), 2 deletions(-) create mode 100644 os/hal/include/rtc.h create mode 100644 os/hal/platforms/STM32/rtc_lld.c create mode 100644 os/hal/platforms/STM32/rtc_lld.h create mode 100644 os/hal/src/rtc.c (limited to 'os/hal') diff --git a/os/hal/hal.mk b/os/hal/hal.mk index 762bda57f..87a3c6dc3 100644 --- a/os/hal/hal.mk +++ b/os/hal/hal.mk @@ -15,7 +15,8 @@ HALSRC = ${CHIBIOS}/os/hal/src/hal.c \ ${CHIBIOS}/os/hal/src/uart.c \ ${CHIBIOS}/os/hal/src/usb.c \ ${CHIBIOS}/os/hal/src/mmc_spi.c \ - ${CHIBIOS}/os/hal/src/serial_usb.c + ${CHIBIOS}/os/hal/src/serial_usb.c \ + ${CHIBIOS}/os/hal/src/rtc.c # Required include directories HALINC = ${CHIBIOS}/os/hal/include diff --git a/os/hal/include/hal.h b/os/hal/include/hal.h index 1ed893aab..b92789b02 100644 --- a/os/hal/include/hal.h +++ b/os/hal/include/hal.h @@ -49,6 +49,7 @@ #include "usb.h" #include "mmc_spi.h" #include "serial_usb.h" +#include "rtc.h" /*===========================================================================*/ /* External declarations. */ diff --git a/os/hal/include/rtc.h b/os/hal/include/rtc.h new file mode 100644 index 000000000..4a36f4317 --- /dev/null +++ b/os/hal/include/rtc.h @@ -0,0 +1,77 @@ +/** + * @file rtc.h + * @brief RTC Driver macros and structures. + * + * @addtogroup RTC + * @{ + */ + + +#ifndef _RTC_H_ +#define _RTC_H_ + + + +#if HAL_USE_RTC || defined(__DOXYGEN__) + +/*===========================================================================*/ +/* Driver constants. */ +/*===========================================================================*/ +/* TODO: move this to hal_lld_f103.h & mcuconf.h */ +#define STM32_LSECLK 32768 /**< Low speed external clock. */ + + +/* RCC_CFGR register bits definitions.*/ +#define STM32_RTC_NONE (0 << 8) /**< */ +#define STM32_RTC_LSE (1 << 8) /**< LSE oscillator clock used as RTC clock */ +#define STM32_RTC_LSI (2 << 8) /**< LSI oscillator clock used as RTC clock */ +#define STM32_RTC_HSE (3 << 8) /**< HSE oscillator clock divided by 128 used as RTC clock */ + + +/*===========================================================================*/ +/* Driver pre-compile time settings. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Derived constants and error checks. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver data structures and types. */ +/*===========================================================================*/ + +typedef struct RTCDriver RTCDriver; + +typedef void (*rtccb_t)(RTCDriver *rtcp); + +#include "rtc_lld.h" + +/*===========================================================================*/ +/* Driver macros. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* External declarations. */ +/*===========================================================================*/ + +#ifdef __cplusplus +extern "C" { +#endif + void rtcInit(void); +#if RTC_SUPPORTS_CALLBACKS + void rtcStart(RTCDriver *rtcp, RTCConfig *rtccfgp); + void rtcStop(void); +#endif /* RTC_SUPPORTS_CALLBACKS */ + void rtcSetTime(uint32_t tv_sec); + uint32_t rtcGetSec(void); + uint16_t rtcGetMsec(void); + void rtcSetAlarm(uint32_t tv_alarm); + uint32_t rtcGetAlarm(void); +#ifdef __cplusplus +} +#endif + +#endif /* HAL_USE_RTC */ +#endif /* _RTC_H_ */ + +/** @} */ diff --git a/os/hal/platforms/STM32/rtc_lld.c b/os/hal/platforms/STM32/rtc_lld.c new file mode 100644 index 000000000..4af863005 --- /dev/null +++ b/os/hal/platforms/STM32/rtc_lld.c @@ -0,0 +1,236 @@ +/** + * @file STM32/rtc_lld.c + * @brief STM32 RTC subsystem low level driver header. + * + * @addtogroup RTC + * @{ + */ + +#include "ch.h" +#include "hal.h" + + + + + + +// TODO: defines look in 4492 stm32f10x.h + + + + + +/** The RTCCLK clock source can be either the HSE/128, LSE or LSI clocks. This is selected +by programming the RTCSEL[1:0] bits in the Backup domain control register (RCC_BDCR). +This selection +CANNOT +be modified without resetting the Backup domain. + +The LSE clock is in the Backup domain, whereas the HSE and LSI clocks are not. +Consequently: +* If LSE is selected as RTC clock: +– The RTC continues to work even if the VDD supply is switched off, provided the +VBAT supply is maintained. +* If LSI is selected as Auto-Wakeup unit (AWU) clock: +– The AWU state is not guaranteed if the VDD supply is powered off. Refer to +Section 6.2.5: LSI clock on page 87 for more details on LSI calibration. +* If the HSE clock divided by 128 is used as the RTC clock: +– The RTC state is not guaranteed if the VDD supply is powered off or if the internal +voltage regulator is powered off (removing power from the 1.8 V domain). +– The DPB bit (Disable backup domain write protection) in the Power controller +register must be set to 1 (refer to Section 4.4.1: Power control register +(PWR_CR)). +*/ + +#if HAL_USE_RTC || defined(__DOXYGEN__) + +/*===========================================================================*/ +/* Driver exported variables. */ +/*===========================================================================*/ + +RTCDriver RTCD; + + +/*===========================================================================*/ +/* Driver local variables. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver local functions. */ +/*===========================================================================*/ + +/** + * @brief Shared IRQ handler. + * + * @param[in] rtcp pointer to a @p RTCDriver object + */ +#if RTC_SUPPORTS_CALLBACKS + +static void rtc_lld_serve_interrupt(RTCDriver *rtcp){ + chSysLockFromIsr(); +//TODO: do not forget to reset flags manually + if (RTC->CRL & RTC_CRL_SECF){ + rtcp->config->second_cb(rtcp); + RTC->CRL &= ~RTC_CRL_SECF; + } + if (RTC->CRL & RTC_CRL_ALRF){ + rtcp->config->alarm_cb(rtcp); + RTC->CRL &= ~RTC_CRL_ALRF; + } + if (RTC->CRL & RTC_CRL_OWF){ + rtcp->config->overflow_cb(rtcp); + RTC->CRL &= ~RTC_CRL_OWF; + } + chSysUnlockFromIsr(); +} +#endif /* RTC_SUPPORTS_CALLBACKS */ + +/*===========================================================================*/ +/* Driver interrupt handlers. */ +/*===========================================================================*/ + +/** + * @brief RTC interrupt handler. + * @isr + */ +#if RTC_SUPPORTS_CALLBACKS + +CH_IRQ_HANDLER(RTC_IRQHandler) { + CH_IRQ_PROLOGUE(); + rtc_lld_serve_interrupt(&RTCD); + CH_IRQ_EPILOGUE(); +} + +#endif /* RTC_SUPPORTS_CALLBACKS */ + +/*===========================================================================*/ +/* Driver exported functions. */ +/*===========================================================================*/ + +/** + * @brief Enable access to registers and initialize RTC if BKP domain + * was previously reseted. + */ +void rtc_lld_init(void){ + RCC->APB1ENR |= (RCC_APB1ENR_PWREN | RCC_APB1ENR_BKPEN); /* enable clocking */ + PWR->CR |= PWR_CR_DBP; /* enable access */ + + if (!(RCC->BDCR & (RCC_BDCR_RTCEN | RCC_BDCR_LSEON))){ /* BKP domain was reseted */ + RCC->BDCR |= STM32_RTC_LSE; /* select clocking from LSE */ + RCC->BDCR |= RCC_BDCR_LSEON; /* switch LSE on */ + while(!(RCC->BDCR & RCC_BDCR_LSEON)) /* wait for stabilization */ + ; + RCC->BDCR |= RCC_BDCR_RTCEN; /* run clock */ + } + + /* Ensure that RTC_CNT and RTC_DIV contain actual values after enabling + * clocking on APB1, because these values only update when APB1 functioning.*/ + RTC->CRL &= ~(RTC_CRL_RSF); + while (!(RTC->CRL & RTC_CRL_RSF)) + ; +} + +/** + * @brief Configure and start interrupt servicing routines. + * + * @param[in] rtcp pointer to a @p RTCDriver object + * @param[in] rtccfgp pointer to a @p RTCDriver config object + */ +#if RTC_SUPPORTS_CALLBACKS +void rtc_lld_start(RTCDriver *rtcp, RTCConfig *rtccfgp){ + uint16_t flags = 0; + + NVICEnableVector(RTC_IRQn, CORTEX_PRIORITY_MASK(STM32_RTC_IRQ_PRIORITY)); + + rtcp->config = rtccfgp; + if (rtcp->config->overflow_cb != NULL){ + flags |= RTC_CRH_OWIE; + } + if (rtcp->config->alarm_cb != NULL){ + flags |= RTC_CRH_ALRIE; + } + if (rtcp->config->second_cb != NULL){ + flags |= RTC_CRH_SECIE; + } + + RTC->CRH |= flags; +} + +/** + * @brief Disable interrupt servicing routines. + */ +void rtc_lld_stop(void){ + NVICDisableVector(RTC_IRQn); + RTC->CRH = 0; +} +#endif /* RTC_SUPPORTS_CALLBACKS */ + + + +/** + * @brief Set current time. + * + * @param[in] tv_sec time value in UNIX notation. + */ +void rtc_lld_set_time(uint32_t tv_sec){ + uint32_t preload = STM32_LSECLK - 1UL; + + while(!(RTC->CRL & RTC_CRL_RTOFF)) + ; + + RTC->CRL |= RTC_CRL_CNF; /* switch on configure mode */ + RTC->PRLH = (uint16_t)((preload >> 16) & 0b1111); /* write preloader */ + RTC->PRLL = (uint16_t)(preload & 0xFFFF); + RTC->CNTH = (uint16_t)((tv_sec >> 16) & 0xFFFF); /* write time */ + RTC->CNTL = (uint16_t)(tv_sec & 0xFFFF); + RTC->CRL &= ~RTC_CRL_CNF; /* switch off configure mode */ + + while(!(RTC->CRL & RTC_CRL_RTOFF)) /* wait for completion */ + ; +} + +/** + * @brief Return current time in UNIX notation. + */ +uint32_t rtc_lld_get_sec(void){ + return ((RTC->CNTH << 16) + RTC->CNTL); +} + +/** + * @brief Return fractional part of current time (milliseconds). + */ +uint16_t rtc_lld_get_msec(void){ + uint32_t time_frac = 0; + time_frac = (((uint32_t)RTC->DIVH) << 16) + (RTC->DIVL); + return(((STM32_LSECLK - time_frac) * 1000) / STM32_LSECLK); +} + +/** + * @brief Set alarm date in UNIX notation. + */ +void rtc_lld_set_alarm(uint32_t tv_alarm){ + + while(!(RTC->CRL & RTC_CRL_RTOFF)) + ; + + RTC->CRL |= RTC_CRL_CNF; /* switch on configure mode */ + RTC->ALRH = (uint16_t)((tv_alarm >> 16) & 0xFFFF); /* write time */ + RTC->ALRL = (uint16_t)(tv_alarm & 0xFFFF); + RTC->CRL &= ~RTC_CRL_CNF; /* switch off configure mode */ + + while(!(RTC->CRL & RTC_CRL_RTOFF)) /* wait for completion */ + ; +} + +/** + * @brief Get current alarm date in UNIX notation. + * @note Default value after reset is 0xFFFFFFFF + */ +uint32_t rtc_lld_get_alarm(void){ + return ((RTC->ALRH << 16) + RTC->ALRL); +} + + +#endif /* HAL_USE_RTC */ + +/** @} */ diff --git a/os/hal/platforms/STM32/rtc_lld.h b/os/hal/platforms/STM32/rtc_lld.h new file mode 100644 index 000000000..cf18b664c --- /dev/null +++ b/os/hal/platforms/STM32/rtc_lld.h @@ -0,0 +1,100 @@ + +/** + * @file STM32/rtc_lld.h + * @brief STM32 RTC subsystem low level driver header. + * + * @addtogroup RTC + * @{ + */ + +#ifndef _RTC_LLD_H_ +#define _RTC_LLD_H_ + +#if HAL_USE_RTC || defined(__DOXYGEN__) + +/*===========================================================================*/ +/* Driver constants. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver pre-compile time settings. */ +/*===========================================================================*/ +/** + * @brief Switch to TRUE if you need callbacks from RTC. Switch to FALSE + * if you need only time keeping. + * @note Default is true. + */ +#if !defined(RTC_SUPPORTS_CALLBACKS) || defined(__DOXYGEN__) +#define RTC_SUPPORTS_CALLBACKS TRUE +#endif + +/*===========================================================================*/ +/* Derived constants and error checks. */ +/*===========================================================================*/ + +#if HAL_USE_RTC && !STM32_HAS_RTC +#error "RTC not present in the selected device" +#endif + +/*===========================================================================*/ +/* Driver data structures and types. */ +/*===========================================================================*/ +/** + * @brief Structure representing an RTC driver config. + */ +typedef struct { + /** + * @brief Overflow callback. Set it to NULL if not used. + */ + rtccb_t overflow_cb; + + /** + * @brief Every second callback. Set it to NULL if not used. + */ + rtccb_t second_cb; + + /** + * @brief Alarm callback. Set it to NULL if not used. + */ + rtccb_t alarm_cb; +}RTCConfig; + + +/** + * @brief Structure representing an RTC driver. + */ +struct RTCDriver{ + /** + * @brief Pointer to RCT config. + */ + const RTCConfig *config; +}; + +/*===========================================================================*/ +/* Driver macros. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* External declarations. */ +/*===========================================================================*/ + +#ifdef __cplusplus +extern "C" { +#endif + void rtc_lld_init(void); +#if RTC_SUPPORTS_CALLBACKS + void rtc_lld_start(RTCDriver *rtcp, RTCConfig *rtccfgp); + void rtc_lld_stop(void); +#endif /* RTC_SUPPORTS_CALLBACKS */ + void rtc_lld_set_time(uint32_t tv_sec); + uint32_t rtc_lld_get_sec(void); + uint16_t rtc_lld_get_msec(void); +#ifdef __cplusplus +} +#endif + + +#endif /* HAL_USE_RTC */ +#endif /* _RTC_LLD_H_ */ + +/** @} */ diff --git a/os/hal/platforms/STM32F1xx/platform.mk b/os/hal/platforms/STM32F1xx/platform.mk index 010a3f96d..26f13cd81 100644 --- a/os/hal/platforms/STM32F1xx/platform.mk +++ b/os/hal/platforms/STM32F1xx/platform.mk @@ -12,7 +12,8 @@ PLATFORMSRC = ${CHIBIOS}/os/hal/platforms/STM32F1xx/hal_lld.c \ ${CHIBIOS}/os/hal/platforms/STM32/DMAv1/spi_lld.c \ ${CHIBIOS}/os/hal/platforms/STM32/DMAv1/uart_lld.c \ ${CHIBIOS}/os/hal/platforms/STM32/DMAv1/stm32_dma.c \ - ${CHIBIOS}/os/hal/platforms/STM32/USBv1/usb_lld.c + ${CHIBIOS}/os/hal/platforms/STM32/USBv1/usb_lld.c \ + ${CHIBIOS}/os/hal/platforms/STM32/rtc_lld.c # Required include directories PLATFORMINC = ${CHIBIOS}/os/hal/platforms/STM32F1xx \ diff --git a/os/hal/src/hal.c b/os/hal/src/hal.c index ef7d7af8b..3c8fb2fe6 100644 --- a/os/hal/src/hal.c +++ b/os/hal/src/hal.c @@ -106,6 +106,9 @@ void halInit(void) { #endif #if HAL_USE_SERIAL_USB || defined(__DOXYGEN__) sduInit(); +#endif +#if HAL_USE_RTC || defined(__DOXYGEN__) + rtcInit(); #endif /* Board specific initialization.*/ boardInit(); diff --git a/os/hal/src/rtc.c b/os/hal/src/rtc.c new file mode 100644 index 000000000..bb0dc11f0 --- /dev/null +++ b/os/hal/src/rtc.c @@ -0,0 +1,108 @@ +/** + * @file rtc.c + * @brief Real Time Clock Abstraction Layer code. + * + * @addtogroup RTC + * @{ + */ + +#include "ch.h" +#include "hal.h" + + +#if HAL_USE_RTC || defined(__DOXYGEN__) + +/*===========================================================================*/ +/* Driver local definitions. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver exported variables. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver local variables. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver local functions. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver exported functions. */ +/*===========================================================================*/ +/** + * @brief Enable access to registers and initialize RTC if BKP doamin + * was previously reseted. + */ +void rtcInit(void){ + rtc_lld_init(); +} + +#if RTC_SUPPORTS_CALLBACKS +/** + * @brief Configure and start interrupt servicing routines. + * @param[in] rtcp - pointer to RTC driver structure. + * @param[in] rtccfgp - pointer to RTC config structure. + */ +void rtcStart(RTCDriver *rtcp, RTCConfig *rtccfgp){ + chDbgCheck(((rtcp != NULL) && (rtccfgp != NULL)), "rtcStart"); + rtc_lld_start(rtcp, rtccfgp); +} + +/** + * @brief Stop interrupt servicing routines. + */ +void rtcStop(void){ + rtc_lld_stop(); +} +#endif /* RTC_SUPPORTS_CALLBACKS */ + +/** + * @brief Set current time. + * @param[in] tv_sec - time value in UNIX notation. + */ +void rtcSetTime(uint32_t tv_sec){ + rtc_lld_set_time(tv_sec); +} + +/** + * @brief Return current time in UNIX notation. + */ +uint32_t rtcGetSec(void){ + return rtc_lld_get_sec(); +} + +/** + * @brief Return fractional part of current time (milliseconds). + */ +uint16_t rtcGetMsec(void){ + return rtc_lld_get_msec(); +} + +/** + * @brief Set alarm date in UNIX notation. + */ +void rtcSetAlarm(uint32_t tv_alarm){ + rtc_lld_set_alarm(tv_alarm); +} + +/** + * @brief Get current alarm date in UNIX notation. + */ +uint32_t rtcGetAlarm(void){ + return rtc_lld_get_alarm(); +} + + + + + + +#endif /* HAL_USE_RTC */ + + + +/** @} */ + + -- cgit v1.2.3 From 2991a477339a28ec275647930df45443a9f8a253 Mon Sep 17 00:00:00 2001 From: barthess Date: Wed, 31 Aug 2011 09:34:42 +0000 Subject: RTC. nop git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/rtc_dev@3270 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/include/rtc.h | 2 +- os/hal/platforms/STM32/rtc_lld.c | 28 +++++++++++++++++++--------- os/hal/platforms/STM32/rtc_lld.h | 7 ++++++- os/hal/src/rtc.c | 3 ++- 4 files changed, 28 insertions(+), 12 deletions(-) (limited to 'os/hal') diff --git a/os/hal/include/rtc.h b/os/hal/include/rtc.h index 4a36f4317..474862910 100644 --- a/os/hal/include/rtc.h +++ b/os/hal/include/rtc.h @@ -59,7 +59,7 @@ extern "C" { #endif void rtcInit(void); #if RTC_SUPPORTS_CALLBACKS - void rtcStart(RTCDriver *rtcp, RTCConfig *rtccfgp); + void rtcStart(RTCDriver *rtcp, const RTCConfig *rtccfgp); void rtcStop(void); #endif /* RTC_SUPPORTS_CALLBACKS */ void rtcSetTime(uint32_t tv_sec); diff --git a/os/hal/platforms/STM32/rtc_lld.c b/os/hal/platforms/STM32/rtc_lld.c index 4af863005..80f0185ba 100644 --- a/os/hal/platforms/STM32/rtc_lld.c +++ b/os/hal/platforms/STM32/rtc_lld.c @@ -48,6 +48,7 @@ register must be set to 1 (refer to Section 4.4.1: Power control register /* Driver exported variables. */ /*===========================================================================*/ +/** @brief RTC driver identifier.*/ RTCDriver RTCD; @@ -69,15 +70,21 @@ RTCDriver RTCD; static void rtc_lld_serve_interrupt(RTCDriver *rtcp){ chSysLockFromIsr(); //TODO: do not forget to reset flags manually - if (RTC->CRL & RTC_CRL_SECF){ + if ((RTC->CRH & RTC_CRH_SECIE) && \ + (RTC->CRL & RTC_CRL_SECF) && \ + (rtcp->config->second_cb != NULL)){ rtcp->config->second_cb(rtcp); RTC->CRL &= ~RTC_CRL_SECF; } - if (RTC->CRL & RTC_CRL_ALRF){ + if ((RTC->CRH & RTC_CRH_ALRIE) && \ + (RTC->CRL & RTC_CRL_ALRF) && \ + (rtcp->config->alarm_cb != NULL)){ rtcp->config->alarm_cb(rtcp); RTC->CRL &= ~RTC_CRL_ALRF; } - if (RTC->CRL & RTC_CRL_OWF){ + if ((RTC->CRH & RTC_CRH_OWIE) && \ + (RTC->CRL & RTC_CRL_OWF) && \ + (rtcp->config->overflow_cb != NULL)){ rtcp->config->overflow_cb(rtcp); RTC->CRL &= ~RTC_CRL_OWF; } @@ -128,6 +135,8 @@ void rtc_lld_init(void){ RTC->CRL &= ~(RTC_CRL_RSF); while (!(RTC->CRL & RTC_CRL_RSF)) ; + + RTCD.config = NULL; } /** @@ -137,23 +146,24 @@ void rtc_lld_init(void){ * @param[in] rtccfgp pointer to a @p RTCDriver config object */ #if RTC_SUPPORTS_CALLBACKS -void rtc_lld_start(RTCDriver *rtcp, RTCConfig *rtccfgp){ - uint16_t flags = 0; +void rtc_lld_start(RTCDriver *rtcp, const RTCConfig *rtccfgp){ + uint16_t isr_flags = 0; NVICEnableVector(RTC_IRQn, CORTEX_PRIORITY_MASK(STM32_RTC_IRQ_PRIORITY)); rtcp->config = rtccfgp; if (rtcp->config->overflow_cb != NULL){ - flags |= RTC_CRH_OWIE; + isr_flags |= RTC_CRH_OWIE; } if (rtcp->config->alarm_cb != NULL){ - flags |= RTC_CRH_ALRIE; + isr_flags |= RTC_CRH_ALRIE; } if (rtcp->config->second_cb != NULL){ - flags |= RTC_CRH_SECIE; + isr_flags |= RTC_CRH_SECIE; } - RTC->CRH |= flags; + RTC->CRL &= ~(RTC_CRL_SECF | RTC_CRL_ALRF | RTC_CRL_OWF); /* clear all even flags*/ + RTC->CRH |= isr_flags; } /** diff --git a/os/hal/platforms/STM32/rtc_lld.h b/os/hal/platforms/STM32/rtc_lld.h index cf18b664c..f26315784 100644 --- a/os/hal/platforms/STM32/rtc_lld.h +++ b/os/hal/platforms/STM32/rtc_lld.h @@ -78,17 +78,22 @@ struct RTCDriver{ /* External declarations. */ /*===========================================================================*/ +extern RTCDriver RTCD; + + #ifdef __cplusplus extern "C" { #endif void rtc_lld_init(void); #if RTC_SUPPORTS_CALLBACKS - void rtc_lld_start(RTCDriver *rtcp, RTCConfig *rtccfgp); + void rtc_lld_start(RTCDriver *rtcp, const RTCConfig *rtccfgp); void rtc_lld_stop(void); #endif /* RTC_SUPPORTS_CALLBACKS */ void rtc_lld_set_time(uint32_t tv_sec); uint32_t rtc_lld_get_sec(void); uint16_t rtc_lld_get_msec(void); + uint32_t rtc_lld_get_alarm(void); + void rtc_lld_set_alarm(uint32_t); #ifdef __cplusplus } #endif diff --git a/os/hal/src/rtc.c b/os/hal/src/rtc.c index bb0dc11f0..c6edca4a2 100644 --- a/os/hal/src/rtc.c +++ b/os/hal/src/rtc.c @@ -9,6 +9,7 @@ #include "ch.h" #include "hal.h" +#include "rtc_lld.h" #if HAL_USE_RTC || defined(__DOXYGEN__) @@ -45,7 +46,7 @@ void rtcInit(void){ * @param[in] rtcp - pointer to RTC driver structure. * @param[in] rtccfgp - pointer to RTC config structure. */ -void rtcStart(RTCDriver *rtcp, RTCConfig *rtccfgp){ +void rtcStart(RTCDriver *rtcp, const RTCConfig *rtccfgp){ chDbgCheck(((rtcp != NULL) && (rtccfgp != NULL)), "rtcStart"); rtc_lld_start(rtcp, rtccfgp); } -- cgit v1.2.3 From c8f60c27e1cdcd9d5a5592287d453d8d1fe0051f Mon Sep 17 00:00:00 2001 From: barthess Date: Wed, 31 Aug 2011 14:44:52 +0000 Subject: RTC. Small fixes. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/rtc_dev@3271 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/platforms/STM32/rtc_lld.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'os/hal') diff --git a/os/hal/platforms/STM32/rtc_lld.c b/os/hal/platforms/STM32/rtc_lld.c index 80f0185ba..59699028d 100644 --- a/os/hal/platforms/STM32/rtc_lld.c +++ b/os/hal/platforms/STM32/rtc_lld.c @@ -10,16 +10,9 @@ #include "hal.h" - - - - // TODO: defines look in 4492 stm32f10x.h - - - /** The RTCCLK clock source can be either the HSE/128, LSE or LSI clocks. This is selected by programming the RTCSEL[1:0] bits in the Backup domain control register (RCC_BDCR). This selection @@ -69,7 +62,7 @@ RTCDriver RTCD; static void rtc_lld_serve_interrupt(RTCDriver *rtcp){ chSysLockFromIsr(); -//TODO: do not forget to reset flags manually + if ((RTC->CRH & RTC_CRH_SECIE) && \ (RTC->CRL & RTC_CRL_SECF) && \ (rtcp->config->second_cb != NULL)){ @@ -88,6 +81,7 @@ static void rtc_lld_serve_interrupt(RTCDriver *rtcp){ rtcp->config->overflow_cb(rtcp); RTC->CRL &= ~RTC_CRL_OWF; } + chSysUnlockFromIsr(); } #endif /* RTC_SUPPORTS_CALLBACKS */ @@ -136,6 +130,10 @@ void rtc_lld_init(void){ while (!(RTC->CRL & RTC_CRL_RSF)) ; + /* disable all interrupts and clear all even flags just to be safe */ + RTC->CRH &= ~(RTC_CRH_OWIE | RTC_CRH_ALRIE | RTC_CRH_SECIE); + RTC->CRL &= ~(RTC_CRL_SECF | RTC_CRL_ALRF | RTC_CRL_OWF); + RTCD.config = NULL; } -- cgit v1.2.3 From 6cc29ee5c81b3c6f745ae80ab242514b073d3d3f Mon Sep 17 00:00:00 2001 From: barthess Date: Wed, 31 Aug 2011 15:30:25 +0000 Subject: RTC. Doxy file added. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/rtc_dev@3273 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/dox/rtc.dox | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 os/hal/dox/rtc.dox (limited to 'os/hal') diff --git a/os/hal/dox/rtc.dox b/os/hal/dox/rtc.dox new file mode 100644 index 000000000..3663374de --- /dev/null +++ b/os/hal/dox/rtc.dox @@ -0,0 +1,32 @@ +/* + ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010, + 2011 Giovanni Di Sirio. + + This file is part of ChibiOS/RT. + + ChibiOS/RT is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + ChibiOS/RT is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +/** + * @defgroup RTC RTC Driver + * @brief Real Time Clock Abstraction Layer + * @details This module defines an abstract interface for Real Time Clock cell. + * If you do not need callback functionality than disable + * @p RTC_SUPPORTS_CALLBACKS option in @p halconf.h. + * + * @pre In order to use the RTC driver the @p HAL_USE_RTC option + * must be enabled in @p halconf.h. + * + * @ingroup IO + */ -- cgit v1.2.3 From 3da3cc27891650180b1e725d1efb6f07005e9d3e Mon Sep 17 00:00:00 2001 From: barthess Date: Wed, 31 Aug 2011 15:31:32 +0000 Subject: RTC. Copyrights added. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/rtc_dev@3274 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/include/rtc.h | 33 +++++++++++++++++++++++++++++---- os/hal/platforms/STM32/rtc_lld.c | 28 ++++++++++++++++++++++++---- os/hal/platforms/STM32/rtc_lld.h | 30 ++++++++++++++++++++++++++---- os/hal/src/rtc.c | 33 ++++++++++++++++++++++++--------- 4 files changed, 103 insertions(+), 21 deletions(-) (limited to 'os/hal') diff --git a/os/hal/include/rtc.h b/os/hal/include/rtc.h index 474862910..aa1a61f49 100644 --- a/os/hal/include/rtc.h +++ b/os/hal/include/rtc.h @@ -1,3 +1,23 @@ +/* + ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010, + 2011 Giovanni Di Sirio. + + This file is part of ChibiOS/RT. + + ChibiOS/RT is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + ChibiOS/RT is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + /** * @file rtc.h * @brief RTC Driver macros and structures. @@ -58,10 +78,15 @@ typedef void (*rtccb_t)(RTCDriver *rtcp); extern "C" { #endif void rtcInit(void); -#if RTC_SUPPORTS_CALLBACKS - void rtcStart(RTCDriver *rtcp, const RTCConfig *rtccfgp); - void rtcStop(void); -#endif /* RTC_SUPPORTS_CALLBACKS */ + + #if RTC_SUPPORTS_CALLBACKS + void rtcStart(RTCDriver *rtcp, const RTCConfig *rtccfgp); + void rtcStop(void); + #else /* RTC_SUPPORTS_CALLBACKS */ + #define rtcStart(rtcp, rtccfgp){;} + #define rtcStop(){;} + #endif /* RTC_SUPPORTS_CALLBACKS */ + void rtcSetTime(uint32_t tv_sec); uint32_t rtcGetSec(void); uint16_t rtcGetMsec(void); diff --git a/os/hal/platforms/STM32/rtc_lld.c b/os/hal/platforms/STM32/rtc_lld.c index 59699028d..ed458190d 100644 --- a/os/hal/platforms/STM32/rtc_lld.c +++ b/os/hal/platforms/STM32/rtc_lld.c @@ -1,3 +1,23 @@ +/* + ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010, + 2011 Giovanni Di Sirio. + + This file is part of ChibiOS/RT. + + ChibiOS/RT is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + ChibiOS/RT is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + /** * @file STM32/rtc_lld.c * @brief STM32 RTC subsystem low level driver header. @@ -139,6 +159,7 @@ void rtc_lld_init(void){ /** * @brief Configure and start interrupt servicing routines. + * This function do nothing if callbacks disabled. * * @param[in] rtcp pointer to a @p RTCDriver object * @param[in] rtccfgp pointer to a @p RTCDriver config object @@ -174,7 +195,6 @@ void rtc_lld_stop(void){ #endif /* RTC_SUPPORTS_CALLBACKS */ - /** * @brief Set current time. * @@ -200,14 +220,14 @@ void rtc_lld_set_time(uint32_t tv_sec){ /** * @brief Return current time in UNIX notation. */ -uint32_t rtc_lld_get_sec(void){ +inline uint32_t rtc_lld_get_sec(void){ return ((RTC->CNTH << 16) + RTC->CNTL); } /** * @brief Return fractional part of current time (milliseconds). */ -uint16_t rtc_lld_get_msec(void){ +inline uint16_t rtc_lld_get_msec(void){ uint32_t time_frac = 0; time_frac = (((uint32_t)RTC->DIVH) << 16) + (RTC->DIVL); return(((STM32_LSECLK - time_frac) * 1000) / STM32_LSECLK); @@ -234,7 +254,7 @@ void rtc_lld_set_alarm(uint32_t tv_alarm){ * @brief Get current alarm date in UNIX notation. * @note Default value after reset is 0xFFFFFFFF */ -uint32_t rtc_lld_get_alarm(void){ +inline uint32_t rtc_lld_get_alarm(void){ return ((RTC->ALRH << 16) + RTC->ALRL); } diff --git a/os/hal/platforms/STM32/rtc_lld.h b/os/hal/platforms/STM32/rtc_lld.h index f26315784..fe51df254 100644 --- a/os/hal/platforms/STM32/rtc_lld.h +++ b/os/hal/platforms/STM32/rtc_lld.h @@ -1,3 +1,22 @@ +/* + ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010, + 2011 Giovanni Di Sirio. + + This file is part of ChibiOS/RT. + + ChibiOS/RT is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + ChibiOS/RT is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ /** * @file STM32/rtc_lld.h @@ -85,10 +104,13 @@ extern RTCDriver RTCD; extern "C" { #endif void rtc_lld_init(void); -#if RTC_SUPPORTS_CALLBACKS - void rtc_lld_start(RTCDriver *rtcp, const RTCConfig *rtccfgp); - void rtc_lld_stop(void); -#endif /* RTC_SUPPORTS_CALLBACKS */ + #if RTC_SUPPORTS_CALLBACKS + void rtc_lld_start(RTCDriver *rtcp, const RTCConfig *rtccfgp); + void rtc_lld_stop(void); + #else /* RTC_SUPPORTS_CALLBACKS */ + #define rtc_lld_start(rtcp, rtccfgp){;} + #define rtc_lld_stop(){;} + #endif /* RTC_SUPPORTS_CALLBACKS */ void rtc_lld_set_time(uint32_t tv_sec); uint32_t rtc_lld_get_sec(void); uint16_t rtc_lld_get_msec(void); diff --git a/os/hal/src/rtc.c b/os/hal/src/rtc.c index c6edca4a2..0db21d4d5 100644 --- a/os/hal/src/rtc.c +++ b/os/hal/src/rtc.c @@ -1,3 +1,23 @@ +/* + ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010, + 2011 Giovanni Di Sirio. + + This file is part of ChibiOS/RT. + + ChibiOS/RT is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + ChibiOS/RT is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + /** * @file rtc.c * @brief Real Time Clock Abstraction Layer code. @@ -40,12 +60,14 @@ void rtcInit(void){ rtc_lld_init(); } -#if RTC_SUPPORTS_CALLBACKS /** - * @brief Configure and start interrupt servicing routines. + * @brief Configure and start interrupt servicing routines. + * This function do nothing if callbacks disabled. + * * @param[in] rtcp - pointer to RTC driver structure. * @param[in] rtccfgp - pointer to RTC config structure. */ +#if RTC_SUPPORTS_CALLBACKS void rtcStart(RTCDriver *rtcp, const RTCConfig *rtccfgp){ chDbgCheck(((rtcp != NULL) && (rtccfgp != NULL)), "rtcStart"); rtc_lld_start(rtcp, rtccfgp); @@ -95,15 +117,8 @@ uint32_t rtcGetAlarm(void){ return rtc_lld_get_alarm(); } - - - - - #endif /* HAL_USE_RTC */ - - /** @} */ -- cgit v1.2.3 From 5e62285d1745cd498f89b1a42ae4b28b3ece59a2 Mon Sep 17 00:00:00 2001 From: barthess Date: Wed, 31 Aug 2011 16:32:34 +0000 Subject: RTC. Final polishing. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/rtc_dev@3275 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/dox/rtc.dox | 2 ++ os/hal/include/rtc.h | 10 ------- os/hal/platforms/STM32/rtc_lld.c | 57 +++++++++++++++++++--------------------- os/hal/platforms/STM32/rtc_lld.h | 8 ++++++ os/hal/src/rtc.c | 6 ++--- 5 files changed, 40 insertions(+), 43 deletions(-) (limited to 'os/hal') diff --git a/os/hal/dox/rtc.dox b/os/hal/dox/rtc.dox index 3663374de..3572aca18 100644 --- a/os/hal/dox/rtc.dox +++ b/os/hal/dox/rtc.dox @@ -24,6 +24,8 @@ * @details This module defines an abstract interface for Real Time Clock cell. * If you do not need callback functionality than disable * @p RTC_SUPPORTS_CALLBACKS option in @p halconf.h. + * In @p halconf.h you also can select clock source for RTC in + * @p RTC_CLOCK_SOURCE option. * * @pre In order to use the RTC driver the @p HAL_USE_RTC option * must be enabled in @p halconf.h. diff --git a/os/hal/include/rtc.h b/os/hal/include/rtc.h index aa1a61f49..ad66fcd8b 100644 --- a/os/hal/include/rtc.h +++ b/os/hal/include/rtc.h @@ -37,16 +37,6 @@ /*===========================================================================*/ /* Driver constants. */ /*===========================================================================*/ -/* TODO: move this to hal_lld_f103.h & mcuconf.h */ -#define STM32_LSECLK 32768 /**< Low speed external clock. */ - - -/* RCC_CFGR register bits definitions.*/ -#define STM32_RTC_NONE (0 << 8) /**< */ -#define STM32_RTC_LSE (1 << 8) /**< LSE oscillator clock used as RTC clock */ -#define STM32_RTC_LSI (2 << 8) /**< LSI oscillator clock used as RTC clock */ -#define STM32_RTC_HSE (3 << 8) /**< HSE oscillator clock divided by 128 used as RTC clock */ - /*===========================================================================*/ /* Driver pre-compile time settings. */ diff --git a/os/hal/platforms/STM32/rtc_lld.c b/os/hal/platforms/STM32/rtc_lld.c index ed458190d..ce483d3f9 100644 --- a/os/hal/platforms/STM32/rtc_lld.c +++ b/os/hal/platforms/STM32/rtc_lld.c @@ -30,31 +30,6 @@ #include "hal.h" -// TODO: defines look in 4492 stm32f10x.h - - -/** The RTCCLK clock source can be either the HSE/128, LSE or LSI clocks. This is selected -by programming the RTCSEL[1:0] bits in the Backup domain control register (RCC_BDCR). -This selection -CANNOT -be modified without resetting the Backup domain. - -The LSE clock is in the Backup domain, whereas the HSE and LSI clocks are not. -Consequently: -* If LSE is selected as RTC clock: -– The RTC continues to work even if the VDD supply is switched off, provided the -VBAT supply is maintained. -* If LSI is selected as Auto-Wakeup unit (AWU) clock: -– The AWU state is not guaranteed if the VDD supply is powered off. Refer to -Section 6.2.5: LSI clock on page 87 for more details on LSI calibration. -* If the HSE clock divided by 128 is used as the RTC clock: -– The RTC state is not guaranteed if the VDD supply is powered off or if the internal -voltage regulator is powered off (removing power from the 1.8 V domain). -– The DPB bit (Disable backup domain write protection) in the Power controller -register must be set to 1 (refer to Section 4.4.1: Power control register -(PWR_CR)). -*/ - #if HAL_USE_RTC || defined(__DOXYGEN__) /*===========================================================================*/ @@ -137,13 +112,37 @@ void rtc_lld_init(void){ PWR->CR |= PWR_CR_DBP; /* enable access */ if (!(RCC->BDCR & (RCC_BDCR_RTCEN | RCC_BDCR_LSEON))){ /* BKP domain was reseted */ - RCC->BDCR |= STM32_RTC_LSE; /* select clocking from LSE */ + RCC->BDCR |= RTC_CLOCK_SOURCE; /* select clocking from LSE */ RCC->BDCR |= RCC_BDCR_LSEON; /* switch LSE on */ while(!(RCC->BDCR & RCC_BDCR_LSEON)) /* wait for stabilization */ ; RCC->BDCR |= RCC_BDCR_RTCEN; /* run clock */ } + #if defined(RTC_CLOCK_SOURCE) == defined(RCC_BDCR_RTCSEL_LSE) + uint32_t preload = STM32_LSECLK - 1UL; + #elif defined(RTC_CLOCK_SOURCE) == defined(RCC_BDCR_RTCSEL_LSI) + uint32_t preload = STM32_LSICLK - 1UL; + #elif defined(RTC_CLOCK_SOURCE) == defined(RCC_BDCR_RTCSEL_HSE) + uint32_t preload = (STM32_HSICLK / 128UL) - 1UL; + #else + #error "RTC clock source not selected" + #endif /* RTC_CLOCK_SOURCE == RCC_BDCR_RTCSEL_LSE */ + + /* Write preload register only if value changed */ + if (preload != (((uint32_t)(RTC->PRLH)) << 16) + RTC->PRLH){ + while(!(RTC->CRL & RTC_CRL_RTOFF)) + ; + + RTC->CRL |= RTC_CRL_CNF; /* switch on configure mode */ + RTC->PRLH = (uint16_t)((preload >> 16) & 0b1111); /* write preloader */ + RTC->PRLL = (uint16_t)(preload & 0xFFFF); + RTC->CRL &= ~RTC_CRL_CNF; /* switch off configure mode */ + + while(!(RTC->CRL & RTC_CRL_RTOFF)) /* wait for completion */ + ; + } + /* Ensure that RTC_CNT and RTC_DIV contain actual values after enabling * clocking on APB1, because these values only update when APB1 functioning.*/ RTC->CRL &= ~(RTC_CRL_RSF); @@ -181,7 +180,8 @@ void rtc_lld_start(RTCDriver *rtcp, const RTCConfig *rtccfgp){ isr_flags |= RTC_CRH_SECIE; } - RTC->CRL &= ~(RTC_CRL_SECF | RTC_CRL_ALRF | RTC_CRL_OWF); /* clear all even flags*/ + /* clear all event flags just to be safe */ + RTC->CRL &= ~(RTC_CRL_SECF | RTC_CRL_ALRF | RTC_CRL_OWF); RTC->CRH |= isr_flags; } @@ -201,14 +201,11 @@ void rtc_lld_stop(void){ * @param[in] tv_sec time value in UNIX notation. */ void rtc_lld_set_time(uint32_t tv_sec){ - uint32_t preload = STM32_LSECLK - 1UL; while(!(RTC->CRL & RTC_CRL_RTOFF)) ; RTC->CRL |= RTC_CRL_CNF; /* switch on configure mode */ - RTC->PRLH = (uint16_t)((preload >> 16) & 0b1111); /* write preloader */ - RTC->PRLL = (uint16_t)(preload & 0xFFFF); RTC->CNTH = (uint16_t)((tv_sec >> 16) & 0xFFFF); /* write time */ RTC->CNTL = (uint16_t)(tv_sec & 0xFFFF); RTC->CRL &= ~RTC_CRL_CNF; /* switch off configure mode */ diff --git a/os/hal/platforms/STM32/rtc_lld.h b/os/hal/platforms/STM32/rtc_lld.h index fe51df254..a0490b29a 100644 --- a/os/hal/platforms/STM32/rtc_lld.h +++ b/os/hal/platforms/STM32/rtc_lld.h @@ -47,6 +47,14 @@ #define RTC_SUPPORTS_CALLBACKS TRUE #endif +/** + * @brief Clock source selecting. LSE by default. + */ +#if !defined(RTC_CLOCK_SOURCE) || defined(__DOXYGEN__) +#define RTC_CLOCK_SOURCE RCC_BDCR_RTCSEL_LSE +#endif + + /*===========================================================================*/ /* Derived constants and error checks. */ /*===========================================================================*/ diff --git a/os/hal/src/rtc.c b/os/hal/src/rtc.c index 0db21d4d5..f1aa03a34 100644 --- a/os/hal/src/rtc.c +++ b/os/hal/src/rtc.c @@ -92,14 +92,14 @@ void rtcSetTime(uint32_t tv_sec){ /** * @brief Return current time in UNIX notation. */ -uint32_t rtcGetSec(void){ +inline uint32_t rtcGetSec(void){ return rtc_lld_get_sec(); } /** * @brief Return fractional part of current time (milliseconds). */ -uint16_t rtcGetMsec(void){ +inline uint16_t rtcGetMsec(void){ return rtc_lld_get_msec(); } @@ -113,7 +113,7 @@ void rtcSetAlarm(uint32_t tv_alarm){ /** * @brief Get current alarm date in UNIX notation. */ -uint32_t rtcGetAlarm(void){ +inline uint32_t rtcGetAlarm(void){ return rtc_lld_get_alarm(); } -- cgit v1.2.3 From 7194b7a7fe49bab8d9422dbc2e78d1ae2d39dc9e Mon Sep 17 00:00:00 2001 From: barthess Date: Wed, 31 Aug 2011 17:49:18 +0000 Subject: RTC. Small code improvements. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/rtc_dev@3276 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/platforms/STM32/rtc_lld.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'os/hal') diff --git a/os/hal/platforms/STM32/rtc_lld.c b/os/hal/platforms/STM32/rtc_lld.c index ce483d3f9..3f8468bae 100644 --- a/os/hal/platforms/STM32/rtc_lld.c +++ b/os/hal/platforms/STM32/rtc_lld.c @@ -245,6 +245,11 @@ void rtc_lld_set_alarm(uint32_t tv_alarm){ while(!(RTC->CRL & RTC_CRL_RTOFF)) /* wait for completion */ ; + +#if !(RTC_SUPPORTS_CALLBACKS) + RTC->CRL &= ~RTC_CRL_ALRF; + RTC->CRH |= RTC_CRH_ALRIE; +#endif /* !(RTC_SUPPORTS_CALLBACKS) */ } /** -- cgit v1.2.3 From ca3cc2d5554a99aad1c499fabb9ce3d72fd7aacb Mon Sep 17 00:00:00 2001 From: barthess Date: Thu, 1 Sep 2011 17:44:44 +0000 Subject: RTC. Readability improvements. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/rtc_dev@3278 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/include/rtc.h | 4 ++-- os/hal/platforms/STM32/rtc_lld.c | 2 -- os/hal/platforms/STM32/rtc_lld.h | 9 ++------- 3 files changed, 4 insertions(+), 11 deletions(-) (limited to 'os/hal') diff --git a/os/hal/include/rtc.h b/os/hal/include/rtc.h index ad66fcd8b..0c545c3a6 100644 --- a/os/hal/include/rtc.h +++ b/os/hal/include/rtc.h @@ -73,8 +73,8 @@ extern "C" { void rtcStart(RTCDriver *rtcp, const RTCConfig *rtccfgp); void rtcStop(void); #else /* RTC_SUPPORTS_CALLBACKS */ - #define rtcStart(rtcp, rtccfgp){;} - #define rtcStop(){;} + #define rtcStart(rtcp, rtccfgp) + #define rtcStop() #endif /* RTC_SUPPORTS_CALLBACKS */ void rtcSetTime(uint32_t tv_sec); diff --git a/os/hal/platforms/STM32/rtc_lld.c b/os/hal/platforms/STM32/rtc_lld.c index 3f8468bae..ba89a3c9e 100644 --- a/os/hal/platforms/STM32/rtc_lld.c +++ b/os/hal/platforms/STM32/rtc_lld.c @@ -163,7 +163,6 @@ void rtc_lld_init(void){ * @param[in] rtcp pointer to a @p RTCDriver object * @param[in] rtccfgp pointer to a @p RTCDriver config object */ -#if RTC_SUPPORTS_CALLBACKS void rtc_lld_start(RTCDriver *rtcp, const RTCConfig *rtccfgp){ uint16_t isr_flags = 0; @@ -192,7 +191,6 @@ void rtc_lld_stop(void){ NVICDisableVector(RTC_IRQn); RTC->CRH = 0; } -#endif /* RTC_SUPPORTS_CALLBACKS */ /** diff --git a/os/hal/platforms/STM32/rtc_lld.h b/os/hal/platforms/STM32/rtc_lld.h index a0490b29a..3b4f69665 100644 --- a/os/hal/platforms/STM32/rtc_lld.h +++ b/os/hal/platforms/STM32/rtc_lld.h @@ -112,13 +112,8 @@ extern RTCDriver RTCD; extern "C" { #endif void rtc_lld_init(void); - #if RTC_SUPPORTS_CALLBACKS - void rtc_lld_start(RTCDriver *rtcp, const RTCConfig *rtccfgp); - void rtc_lld_stop(void); - #else /* RTC_SUPPORTS_CALLBACKS */ - #define rtc_lld_start(rtcp, rtccfgp){;} - #define rtc_lld_stop(){;} - #endif /* RTC_SUPPORTS_CALLBACKS */ + void rtc_lld_start(RTCDriver *rtcp, const RTCConfig *rtccfgp); + void rtc_lld_stop(void); void rtc_lld_set_time(uint32_t tv_sec); uint32_t rtc_lld_get_sec(void); uint16_t rtc_lld_get_msec(void); -- cgit v1.2.3 From ac429a2a76727c72d6a7b8273c9643560fcd6222 Mon Sep 17 00:00:00 2001 From: barthess Date: Thu, 1 Sep 2011 18:09:40 +0000 Subject: RTC. Added state checks. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/rtc_dev@3279 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/platforms/STM32/rtc_lld.c | 6 +++--- os/hal/src/rtc.c | 6 ++++-- 2 files changed, 7 insertions(+), 5 deletions(-) (limited to 'os/hal') diff --git a/os/hal/platforms/STM32/rtc_lld.c b/os/hal/platforms/STM32/rtc_lld.c index ba89a3c9e..1ddbc0903 100644 --- a/os/hal/platforms/STM32/rtc_lld.c +++ b/os/hal/platforms/STM32/rtc_lld.c @@ -241,13 +241,13 @@ void rtc_lld_set_alarm(uint32_t tv_alarm){ RTC->ALRL = (uint16_t)(tv_alarm & 0xFFFF); RTC->CRL &= ~RTC_CRL_CNF; /* switch off configure mode */ - while(!(RTC->CRL & RTC_CRL_RTOFF)) /* wait for completion */ - ; - #if !(RTC_SUPPORTS_CALLBACKS) RTC->CRL &= ~RTC_CRL_ALRF; RTC->CRH |= RTC_CRH_ALRIE; #endif /* !(RTC_SUPPORTS_CALLBACKS) */ + + while(!(RTC->CRL & RTC_CRL_RTOFF)) /* wait for completion */ + ; } /** diff --git a/os/hal/src/rtc.c b/os/hal/src/rtc.c index f1aa03a34..1341bb2dd 100644 --- a/os/hal/src/rtc.c +++ b/os/hal/src/rtc.c @@ -68,7 +68,8 @@ void rtcInit(void){ * @param[in] rtccfgp - pointer to RTC config structure. */ #if RTC_SUPPORTS_CALLBACKS -void rtcStart(RTCDriver *rtcp, const RTCConfig *rtccfgp){ +void rtcStartI(RTCDriver *rtcp, const RTCConfig *rtccfgp){ + chDbgCheckClassI(); chDbgCheck(((rtcp != NULL) && (rtccfgp != NULL)), "rtcStart"); rtc_lld_start(rtcp, rtccfgp); } @@ -76,7 +77,8 @@ void rtcStart(RTCDriver *rtcp, const RTCConfig *rtccfgp){ /** * @brief Stop interrupt servicing routines. */ -void rtcStop(void){ +void rtcStopI(void){ + chDbgCheckClassI(); rtc_lld_stop(); } #endif /* RTC_SUPPORTS_CALLBACKS */ -- cgit v1.2.3