From 5d4a81f50106e2ab856d3237243806526fb8f1d9 Mon Sep 17 00:00:00 2001 From: Sebastian Huber Date: Wed, 12 Jun 2019 12:51:20 +0200 Subject: bsp/atsam: Fix RTC_SetTimeAlarm() Set the alarm time according to the note in the datasheet. --- .../arm/atsam/contrib/libraries/libchip/source/rtc.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/bsps/arm/atsam/contrib/libraries/libchip/source/rtc.c b/bsps/arm/atsam/contrib/libraries/libchip/source/rtc.c index 9527585217..77e3236365 100644 --- a/bsps/arm/atsam/contrib/libraries/libchip/source/rtc.c +++ b/bsps/arm/atsam/contrib/libraries/libchip/source/rtc.c @@ -261,25 +261,31 @@ extern int RTC_SetTimeAlarm(Rtc *pRtc, uint8_t *pucHour, uint8_t *pucMinute, uint8_t *pucSecond) { uint32_t dwAlarm = 0; + uint32_t dwAlarmEnable = 0; TRACE_DEBUG("RTC_SetTimeAlarm()\n\r"); /* Hour */ - if (pucHour) - dwAlarm |= RTC_TIMALR_HOUREN | ((*pucHour / 10) << 20) | (( - *pucHour % 10) << 16); + if (pucHour) { + dwAlarm |= ((*pucHour / 10) << 20) | (( *pucHour % 10) << 16); + dwAlarmEnable |= RTC_TIMALR_HOUREN; + } /* Minute */ if (pucMinute) { - dwAlarm |= RTC_TIMALR_MINEN | ((*pucMinute / 10) << 12) - | ((*pucMinute % 10) << 8); + dwAlarm |= ((*pucMinute / 10) << 12) | ((*pucMinute % 10) << 8); + dwAlarmEnable |= RTC_TIMALR_MINEN; } /* Second */ - if (pucSecond) - dwAlarm |= RTC_TIMALR_SECEN | ((*pucSecond / 10) << 4) | (*pucSecond % 10); + if (pucSecond) { + dwAlarm |= ((*pucSecond / 10) << 4) | (*pucSecond % 10); + dwAlarmEnable |= RTC_TIMALR_SECEN; + } + pRtc->RTC_TIMALR = 0; pRtc->RTC_TIMALR = dwAlarm; + pRtc->RTC_TIMALR = dwAlarm | dwAlarmEnable; return (int)(pRtc->RTC_VER & RTC_VER_NVTIMALR); } -- cgit v1.2.3