[rtems commit] bsp/atsam: Fix RTC_SetTimeAlarm()

Sebastian Huber sebh at rtems.org
Thu Jun 13 06:49:21 UTC 2019


Module:    rtems
Branch:    master
Commit:    5d4a81f50106e2ab856d3237243806526fb8f1d9
Changeset: http://git.rtems.org/rtems/commit/?id=5d4a81f50106e2ab856d3237243806526fb8f1d9

Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
Date:      Wed Jun 12 12:51:20 2019 +0200

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 9527585..77e3236 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);
 }



More information about the vc mailing list