From 7a0857aa5d161a27128622b0d9f61867dc7520ae Mon Sep 17 00:00:00 2001 From: Giovanni Di Sirio Date: Sun, 25 Nov 2018 10:20:09 +0000 Subject: RTC callbacks now working. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@12437 110e8d01-0319-4d1e-a829-52ad28d1bb01 --- os/hal/ports/STM32/LLD/EXTIv1/stm32_exti.c | 4 +- os/hal/ports/STM32/LLD/RTCv2/hal_rtc_lld.c | 49 +++++++--- readme.txt | 1 + ...RTC (Select ELF file)(OpenOCD, Just Run).launch | 104 ++++++++++----------- testhal/STM32/multi/RTC/main.c | 50 +++++++++- 5 files changed, 138 insertions(+), 70 deletions(-) diff --git a/os/hal/ports/STM32/LLD/EXTIv1/stm32_exti.c b/os/hal/ports/STM32/LLD/EXTIv1/stm32_exti.c index d2d448e80..e4952937a 100644 --- a/os/hal/ports/STM32/LLD/EXTIv1/stm32_exti.c +++ b/os/hal/ports/STM32/LLD/EXTIv1/stm32_exti.c @@ -64,7 +64,7 @@ void extiEnableGroup1(uint32_t mask, extimode_t mode) { /* Masked out lines must not be touched by this driver.*/ - osalDbgAssert((mask & STM32_EXTI_IMR1_MASK) == 0U, "fixed line"); + osalDbgAssert((mask & STM32_EXTI_IMR1_MASK) == 0U, "fixed lines"); if ((mode & EXTI_MODE_EDGES_MASK) == 0U) { /* Disabling channels.*/ @@ -113,7 +113,7 @@ void extiEnableGroup1(uint32_t mask, extimode_t mode) { void extiEnableGroup2(uint32_t mask, extimode_t mode) { /* Masked out lines must not be touched by this driver.*/ - osalDbgAssert((mask & STM32_EXTI_IMR2_MASK) == 0U, "fixed line"); + osalDbgAssert((mask & STM32_EXTI_IMR2_MASK) == 0U, "fixed lines"); if ((mode & EXTI_MODE_EDGES_MASK) == 0U) { /* Disabling channels.*/ diff --git a/os/hal/ports/STM32/LLD/RTCv2/hal_rtc_lld.c b/os/hal/ports/STM32/LLD/RTCv2/hal_rtc_lld.c index 7d70cd44b..a7c212b00 100644 --- a/os/hal/ports/STM32/LLD/RTCv2/hal_rtc_lld.c +++ b/os/hal/ports/STM32/LLD/RTCv2/hal_rtc_lld.c @@ -243,12 +243,33 @@ struct RTCDriverVMT _rtc_lld_vmt = { * @isr */ OSAL_IRQ_HANDLER(STM32_RTC_COMMON_HANDLER) { - uint32_t isr; + uint32_t isr, clear; OSAL_IRQ_PROLOGUE(); + clear = (0U + | RTC_ISR_TSF + | RTC_ISR_TSOVF +#if defined(RTC_ISR_TAMP1F) + | RTC_ISR_TAMP1F +#endif +#if defined(RTC_ISR_TAMP2F) + | RTC_ISR_TAMP2F +#endif +#if defined(RTC_ISR_TAMP3F) + | RTC_ISR_TAMP3F +#endif + | RTC_ISR_WUTF +#if defined(RTC_ISR_ALRAF) + | RTC_ISR_ALRAF +#endif +#if defined(RTC_ISR_ALRBF) + | RTC_ISR_ALRBF +#endif + ); + isr = RTCD1.rtc->ISR; - RTCD1.rtc->ISR = 0U; + RTCD1.rtc->ISR = isr & ~clear; extiClearGroup1(EXTI_MASK1(STM32_RTC_ALARM_EXTI) | EXTI_MASK1(STM32_RTC_TAMP_STAMP_EXTI) | @@ -319,22 +340,22 @@ OSAL_IRQ_HANDLER(STM32_RTC_TAMP_STAMP_HANDLER) { OSAL_IRQ_PROLOGUE(); - clear = ~(0U - | RTC_ISR_TSF - | RTC_ISR_TSOVF + clear = (0U + | RTC_ISR_TSF + | RTC_ISR_TSOVF #if defined(RTC_ISR_TAMP1F) - | RTC_ISR_TAMP1F + | RTC_ISR_TAMP1F #endif #if defined(RTC_ISR_TAMP2F) - | RTC_ISR_TAMP2F + | RTC_ISR_TAMP2F #endif #if defined(RTC_ISR_TAMP3F) - | RTC_ISR_TAMP3F + | RTC_ISR_TAMP3F #endif ); isr = RTCD1.rtc->ISR; - RTCD1.rtc->ISR = clear; + RTCD1.rtc->ISR = isr & ~clear; extiClearGroup1(EXTI_MASK1(STM32_RTC_TAMP_STAMP_EXTI)); @@ -385,7 +406,7 @@ OSAL_IRQ_HANDLER(STM32_RTC_WKUP_HANDLER) { OSAL_IRQ_PROLOGUE(); isr = RTCD1.rtc->ISR; - RTCD1.rtc->ISR = ~RTC_ISR_WUTF; + RTCD1.rtc->ISR = isr & ~RTC_ISR_WUTF; extiClearGroup1(EXTI_MASK1(STM32_RTC_WKUP_EXTI)); @@ -410,17 +431,17 @@ OSAL_IRQ_HANDLER(STM32_RTC_ALARM_HANDLER) { OSAL_IRQ_PROLOGUE(); - clear = ~(0U + clear = (0U #if defined(RTC_ISR_ALRAF) - | RTC_ISR_ALRAF + | RTC_ISR_ALRAF #endif #if defined(RTC_ISR_ALRBF) - | RTC_ISR_ALRBF + | RTC_ISR_ALRBF #endif ); isr = RTCD1.rtc->ISR; - RTCD1.rtc->ISR = clear; + RTCD1.rtc->ISR = isr & ~clear; extiClearGroup1(EXTI_MASK1(STM32_RTC_ALARM_EXTI)); diff --git a/readme.txt b/readme.txt index c4724f5e5..5180ee598 100644 --- a/readme.txt +++ b/readme.txt @@ -75,6 +75,7 @@ ***************************************************************************** *** Next *** +- NEW: STM32 RTCv2 driver now supports callbacks on events. - NEW: Added an EXTI helper driver for STM32. - NEW: Added demo for STM32L4R9I-Discovery board. - NEW: Support for new serial NOR device MX25LM51245G. Other Macronix devices diff --git a/testhal/STM32/multi/RTC/debug/STM32-RTC (Select ELF file)(OpenOCD, Just Run).launch b/testhal/STM32/multi/RTC/debug/STM32-RTC (Select ELF file)(OpenOCD, Just Run).launch index 940c83fad..835e7d705 100644 --- a/testhal/STM32/multi/RTC/debug/STM32-RTC (Select ELF file)(OpenOCD, Just Run).launch +++ b/testhal/STM32/multi/RTC/debug/STM32-RTC (Select ELF file)(OpenOCD, Just Run).launch @@ -1,52 +1,52 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/testhal/STM32/multi/RTC/main.c b/testhal/STM32/multi/RTC/main.c index be90b57a5..3c273c238 100644 --- a/testhal/STM32/multi/RTC/main.c +++ b/testhal/STM32/multi/RTC/main.c @@ -29,6 +29,7 @@ #define SHELL_WA_SIZE THD_WORKING_AREA_SIZE(2048) static void cmd_date(BaseSequentialStream *chp, int argc, char *argv[]) { + RTCDateTime timespec; (void)argv; @@ -36,6 +37,16 @@ static void cmd_date(BaseSequentialStream *chp, int argc, char *argv[]) { chprintf(chp, "Usage: date\r\n"); return; } + + rtcGetTime(&RTCD1, ×pec); + chprintf(chp, "%02d:%02d:%02d (%02d) - %02d-%02d-%04d\r\n", + timespec.millisecond / 3600000U, + (timespec.millisecond % 3600000U) / 60000U, + (timespec.millisecond % 60000U) / 1000U, + timespec.millisecond % 1000U, + timespec.month, + timespec.day, + timespec.year + 1980U); } static const ShellCommand commands[] = { @@ -52,6 +63,8 @@ static const ShellConfig shell_cfg1 = { /* Generic code. */ /*===========================================================================*/ +static sysinterval_t interval = TIME_MS2I(500); + /* * LED blinker thread, times are in milliseconds. */ @@ -62,9 +75,24 @@ static THD_FUNCTION(Thread1, arg) { chRegSetThreadName("blinker"); while (true) { palToggleLine(PORTAB_LINE_LED1); - chThdSleepMilliseconds(500); + chThdSleep(interval); palToggleLine(PORTAB_LINE_LED1); - chThdSleepMilliseconds(500); + chThdSleep(interval); + } +} + +/* + * RTC callback. + */ +static void alarmcb(RTCDriver *rtcp, rtcevent_t event) { + + (void)rtcp; + + if (event == RTC_EVENT_ALARM_A) { + interval = TIME_MS2I(500); + } + else if (event == RTC_EVENT_ALARM_B) { + interval = TIME_MS2I(50); } } @@ -72,6 +100,20 @@ static THD_FUNCTION(Thread1, arg) { * Application entry point. */ int main(void) { + static const RTCAlarm alarm1 = { + RTC_ALRM_MSK4 | /* No month/week day match. */ + RTC_ALRM_MSK3 | /* No hour match. */ + RTC_ALRM_MSK2 | /* No minutes match. */ + RTC_ALRM_ST(0) | + RTC_ALRM_SU(0) /* Match minute start. */ + }; + static const RTCAlarm alarm2 = { + RTC_ALRM_MSK4 | /* No month/week day match. */ + RTC_ALRM_MSK3 | /* No hour match. */ + RTC_ALRM_MSK2 | /* No minutes match. */ + RTC_ALRM_ST(3) | + RTC_ALRM_SU(0) /* Match minute half. */ + }; /* * System initializations. @@ -95,6 +137,10 @@ int main(void) { /* Creates the blinker thread.*/ chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL); + rtcSetAlarm(&RTCD1, 0, &alarm1); + rtcSetAlarm(&RTCD1, 1, &alarm2); + rtcSetCallback(&RTCD1, alarmcb); + /* Normal main() thread activity, spawning shells.*/ while (true) { thread_t *shelltp = chThdCreateFromHeap(NULL, SHELL_WA_SIZE, -- cgit v1.2.3