diff options
author | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2019-06-12 12:53:22 +0200 |
---|---|---|
committer | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2019-06-13 08:48:50 +0200 |
commit | ee366168042de61057a89e3e7aee49c39678c5a3 (patch) | |
tree | 94407541c732d13fcc939ce52b9a4e68671ce81b | |
parent | bsp/atsam: Fix RTC_SetTimeAlarm() (diff) | |
download | rtems-ee366168042de61057a89e3e7aee49c39678c5a3.tar.bz2 |
bsp/atsam: Improve RTC power driver
Accept a time interval up to 24h.
-rw-r--r-- | bsps/arm/atsam/include/bsp/power.h | 4 | ||||
-rw-r--r-- | 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 a352386a0e..dd9946acfc 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 b60235ac29..313efff220 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); } |