Пример #1
0
int rtc_set_time(struct tm *time)
{
    RtcMode2 *rtcMode2 = &(RTC_DEV);
    if ((time->tm_year < reference_year) || (time->tm_year > reference_year + 63)) {
        return -1;
    }
    else {
        rtcMode2->CLOCK.reg = RTC_MODE2_CLOCK_YEAR(time->tm_year - reference_year)
                | RTC_MODE2_CLOCK_MONTH(time->tm_mon + 1)
                | RTC_MODE2_CLOCK_DAY(time->tm_mday)
                | RTC_MODE2_CLOCK_HOUR(time->tm_hour)
                | RTC_MODE2_CLOCK_MINUTE(time->tm_min)
                | RTC_MODE2_CLOCK_SECOND(time->tm_sec);
    }
    while (rtcMode2->STATUS.bit.SYNCBUSY);
    return 0;
}
Пример #2
0
Файл: rtc.c Проект: ant9000/RIOT
int rtc_set_time(struct tm *time)
{
    if ((time->tm_year < reference_year) || (time->tm_year > reference_year + 63)) {
        return -1;
    }
    else {
        while (RTC->MODE2.SYNCBUSY.bit.CLOCK);
        RTC->MODE2.CLOCK.reg = RTC_MODE2_CLOCK_YEAR(time->tm_year - reference_year)
                             | RTC_MODE2_CLOCK_MONTH(time->tm_mon + 1)
                             | RTC_MODE2_CLOCK_DAY(time->tm_mday)
                             | RTC_MODE2_CLOCK_HOUR(time->tm_hour)
                             | RTC_MODE2_CLOCK_MINUTE(time->tm_min)
                             | RTC_MODE2_CLOCK_SECOND(time->tm_sec);
        while (RTC->MODE2.SYNCBUSY.bit.CLOCK);
    }
   return 0;
}