[rtems commit] bsp/atsam: Improve RTC power driver
Sebastian Huber
sebh at rtems.org
Thu Jun 13 06:49:21 UTC 2019
Module: rtems
Branch: master
Commit: ee366168042de61057a89e3e7aee49c39678c5a3
Changeset: http://git.rtems.org/rtems/commit/?id=ee366168042de61057a89e3e7aee49c39678c5a3
Author: Sebastian Huber <sebastian.huber at embedded-brains.de>
Date: Wed Jun 12 12:53:22 2019 +0200
bsp/atsam: Improve RTC power driver
Accept a time interval up to 24h.
---
bsps/arm/atsam/include/bsp/power.h | 4 +++-
bsps/arm/atsam/start/power-rtc.c | 31 ++++++++++++++++++++++---------
2 files changed, 25 insertions(+), 10 deletions(-)
diff --git a/bsps/arm/atsam/include/bsp/power.h b/bsps/arm/atsam/include/bsp/power.h
index a352386..dd9946a 100644
--- a/bsps/arm/atsam/include/bsp/power.h
+++ b/bsps/arm/atsam/include/bsp/power.h
@@ -221,8 +221,10 @@ void atsam_power_handler_sleep_mode(
typedef struct {
/**
* @brief Interval in seconds for which the power off mode should be active.
+ *
+ * An interval up to 24h is supported.
*/
- uint8_t interval;
+ uint32_t interval;
} atsam_power_data_rtc_driver;
/**
diff --git a/bsps/arm/atsam/start/power-rtc.c b/bsps/arm/atsam/start/power-rtc.c
index b60235a..313efff 100644
--- a/bsps/arm/atsam/start/power-rtc.c
+++ b/bsps/arm/atsam/start/power-rtc.c
@@ -18,23 +18,36 @@
#include <libchip/chip.h>
-#define ATSAM_ENABLE_ALARM_INTERRUPT (1u << 1)
+#define ATSAM_ENABLE_ALARM_INTERRUPT RTC_IER_ALREN
-static void set_rtc_alarm_interrupt(uint8_t interval)
+static void set_rtc_alarm_interrupt(uint32_t interval)
{
Rtc *rtc = RTC;
- rtems_time_of_day tod;
+ uint8_t hour;
+ uint8_t minute;
+ uint8_t second;
+ uint32_t time;
/* Clear current status register */
RTC_ClearSCCR(rtc, 0x3F);
- atsam_rtc_get_time(&tod);
- tod.second = (tod.second + interval) % 60;
- tod.second = (((tod.second / 10) << 4) | (tod.second % 10));
+ RTC_GetTime(rtc, &hour, &minute, &second);
+
+ time = UINT32_C(3600) * hour + UINT32_C(60) * minute + second;
+ time = (time + interval) % (UINT32_C(24) * 3600);
+
+ second = (uint8_t) (time % 60);
+ minute = (uint8_t) ((time / 60) % 60);
+ hour = (uint8_t) (time / 3600);
+
+ if (interval < 60) {
+ RTC_SetTimeAlarm(rtc, NULL, NULL, &second);
+ } else if (interval < 3600) {
+ RTC_SetTimeAlarm(rtc, NULL, &minute, &second);
+ } else {
+ RTC_SetTimeAlarm(rtc, &hour, &minute, &second);
+ }
- rtc->RTC_TIMALR &= ~RTC_TIMALR_SECEN;
- rtc->RTC_TIMALR = tod.second;
- rtc->RTC_TIMALR |= RTC_TIMALR_SECEN;
RTC_EnableIt(rtc, ATSAM_ENABLE_ALARM_INTERRUPT);
}
More information about the vc
mailing list