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 --- testhal/STM32F4xx/RTC/halconf.h | 2 +- testhal/STM32F4xx/RTC/main.c | 22 ++++++++++++++++++---- 2 files changed, 19 insertions(+), 5 deletions(-) (limited to 'testhal/STM32F4xx/RTC') diff --git a/testhal/STM32F4xx/RTC/halconf.h b/testhal/STM32F4xx/RTC/halconf.h index fc6e7aa8d..9e64ec3c0 100644 --- a/testhal/STM32F4xx/RTC/halconf.h +++ b/testhal/STM32F4xx/RTC/halconf.h @@ -156,7 +156,7 @@ * @brief Enables the RTC subsystem. */ #if !defined(RTC_SUPPORTS_CALLBACKS) || defined(__DOXYGEN__) -#define RTC_SUPPORTS_CALLBACKS FLASE +#define RTC_SUPPORTS_CALLBACKS TRUE #endif /*===========================================================================*/ diff --git a/testhal/STM32F4xx/RTC/main.c b/testhal/STM32F4xx/RTC/main.c index d6cf4f533..8864e0f01 100644 --- a/testhal/STM32F4xx/RTC/main.c +++ b/testhal/STM32F4xx/RTC/main.c @@ -18,12 +18,14 @@ along with this program. If not, see . */ #include +#include #include "ch.h" #include "hal.h" RTCTime timespec; RTCAlarm alarmspec; +RTCWakeup wakeupspec; RTCCallbackConfig cb_cfg; time_t unix_time; @@ -39,17 +41,20 @@ static inline void exti_rtcalarm_cb(EXTDriver *extp, expchannel_t channel){ if (RTCD1.id_rtc->ISR | RTC_ISR_ALRAF){ RTCD1.id_rtc->ISR &= ~RTC_ISR_ALRAF; } + palTogglePad(GPIOB, GPIOB_LED_R); } /** - * Wakeup callback + * Periodic wakeup callback */ static inline void exti_rtcwakeup_cb(EXTDriver *extp, expchannel_t channel){ (void)extp; (void)channel; + /* manually clear flags because exti driver does not do that */ if (RTCD1.id_rtc->ISR | RTC_ISR_WUTF){ RTCD1.id_rtc->ISR &= ~RTC_ISR_WUTF; } + palTogglePad(GPIOB, GPIOB_LED_R); } @@ -72,12 +77,12 @@ static const EXTConfig extcfg = { {EXT_CH_MODE_DISABLED, NULL}, {EXT_CH_MODE_DISABLED, NULL}, {EXT_CH_MODE_DISABLED, NULL}, - {EXT_CH_MODE_RISING_EDGE, exti_rtcalarm_cb},// RTC alarms + {EXT_CH_MODE_RISING_EDGE | EXT_CH_MODE_AUTOSTART, exti_rtcalarm_cb},// RTC alarms {EXT_CH_MODE_DISABLED, NULL}, {EXT_CH_MODE_DISABLED, NULL}, {EXT_CH_MODE_DISABLED, NULL}, {EXT_CH_MODE_DISABLED, NULL},// timestamp - {EXT_CH_MODE_RISING_EDGE, exti_rtcwakeup_cb},// wakeup + {EXT_CH_MODE_RISING_EDGE| EXT_CH_MODE_AUTOSTART, exti_rtcwakeup_cb},// wakeup }, EXT_MODE_EXTI( 0, @@ -157,6 +162,15 @@ int main(void){ extStart(&EXTD1, &extcfg); + /* tune wakeup callback */ + wakeupspec.wakeup = ((uint32_t)4) << 16; // select 1 Hz clock source + wakeupspec.wakeup |= 3; // set counter value to 3. Period will be 3+1 seconds. + rtcSetWakeup(&RTCD1, &wakeupspec); + + /* enable wakeup callback */ + cb_cfg.cb_cfg = WAKEUP_CB_FLAG; + rtcSetCallback(&RTCD1, &cb_cfg); + /* get current time in unix format */ rtcGetTime(&RTCD1, ×pec); bcd2tm(&timp, timespec.tv_time, timespec.tv_date); @@ -165,7 +179,7 @@ int main(void){ if (unix_time == -1){// incorrect time in RTC cell unix_time = 1000000000; } - + /* set correct time */ tm2bcd((localtime(&unix_time)), ×pec); rtcSetTime(&RTCD1, ×pec); -- cgit v1.2.3