Changeset ee36616 in rtems


Ignore:
Timestamp:
Jun 12, 2019, 10:53:22 AM (4 months ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
master
Children:
d7d0bba
Parents:
5d4a81f5
git-author:
Sebastian Huber <sebastian.huber@…> (06/12/19 10:53:22)
git-committer:
Sebastian Huber <sebastian.huber@…> (06/13/19 06:48:50)
Message:

bsp/atsam: Improve RTC power driver

Accept a time interval up to 24h.

Location:
bsps/arm/atsam
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • bsps/arm/atsam/include/bsp/power.h

    r5d4a81f5 ree36616  
    222222  /**
    223223   * @brief Interval in seconds for which the power off mode should be active.
    224    */
    225   uint8_t interval;
     224   *
     225   * An interval up to 24h is supported.
     226   */
     227  uint32_t interval;
    226228} atsam_power_data_rtc_driver;
    227229
  • bsps/arm/atsam/start/power-rtc.c

    r5d4a81f5 ree36616  
    1919#include <libchip/chip.h>
    2020
    21 #define ATSAM_ENABLE_ALARM_INTERRUPT (1u << 1)
     21#define ATSAM_ENABLE_ALARM_INTERRUPT RTC_IER_ALREN
    2222
    23 static void set_rtc_alarm_interrupt(uint8_t interval)
     23static void set_rtc_alarm_interrupt(uint32_t interval)
    2424{
    2525        Rtc *rtc = RTC;
    26         rtems_time_of_day tod;
     26        uint8_t hour;
     27        uint8_t minute;
     28        uint8_t second;
     29        uint32_t time;
    2730
    2831        /* Clear current status register */
    2932        RTC_ClearSCCR(rtc, 0x3F);
    3033
    31         atsam_rtc_get_time(&tod);
    32         tod.second = (tod.second + interval) % 60;
    33         tod.second = (((tod.second / 10) << 4) | (tod.second % 10));
     34        RTC_GetTime(rtc, &hour, &minute, &second);
    3435
    35         rtc->RTC_TIMALR &= ~RTC_TIMALR_SECEN;
    36         rtc->RTC_TIMALR = tod.second;
    37         rtc->RTC_TIMALR |= RTC_TIMALR_SECEN;
     36        time = UINT32_C(3600) * hour + UINT32_C(60) * minute + second;
     37        time = (time + interval) % (UINT32_C(24) * 3600);
     38
     39        second = (uint8_t) (time % 60);
     40        minute = (uint8_t) ((time / 60) % 60);
     41        hour = (uint8_t) (time / 3600);
     42
     43        if (interval < 60) {
     44                RTC_SetTimeAlarm(rtc, NULL, NULL, &second);
     45        } else if (interval < 3600) {
     46                RTC_SetTimeAlarm(rtc, NULL, &minute, &second);
     47        } else {
     48                RTC_SetTimeAlarm(rtc, &hour, &minute, &second);
     49        }
     50
    3851        RTC_EnableIt(rtc, ATSAM_ENABLE_ALARM_INTERRUPT);
    3952}
Note: See TracChangeset for help on using the changeset viewer.