Rename this function so that it is clear that it is provided by the RTC.
Also return an error when it cannot function as expected. This is unlikely
to occur since it works for dates since 1752 and many RTCs do not support
such old dates. Still it is better to be accurate.
Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Heiko Schocher <hs@denx.de>
#ifndef USE_HOSTCC
struct rtc_time tm;
- to_tm(timestamp, &tm);
+ rtc_to_tm(timestamp, &tm);
printf("%4d-%02d-%02d %2d:%02d:%02d UTC\n",
tm.tm_year, tm.tm_mon, tm.tm_mday,
tm.tm_hour, tm.tm_min, tm.tm_sec);
} while (tim!=tim2);
off = readl(&gpbr->reg[AT91_GPBR_INDEX_TIMEOFF]);
/* off==0 means time is invalid, but we ignore that */
- to_tm (tim+off, tmp);
+ rtc_to_tm(tim+off, tmp);
return 0;
}
/* Calculate the total number of seconds since epoch */
time_in_sec = (tm_sec) + MIN_TO_SECS(tm_min) + HRS_TO_SECS(tm_hr) + DAYS_TO_SECS(tm_day);
- to_tm(time_in_sec, tmp);
+ rtc_to_tm(time_in_sec, tmp);
return 0;
}
return 0;
}
-void to_tm(int tim, struct rtc_time * tm)
+int rtc_to_tm(int tim, struct rtc_time *tm)
{
register int i;
register long hms, day;
/* Days are what is left over (+1) from all that. */
tm->tm_mday = day + 1;
+ /* Zero unused fields */
+ tm->tm_yday = 0;
+ tm->tm_isdst = 0;
+
/*
* Determine the day of week
*/
- rtc_calc_weekday(tm);
+ return rtc_calc_weekday(tm);
}
/* Converts Gregorian date to seconds since 1970-01-01 00:00:00.
DEBUGR ("Get RTC s since 1.1.1970: %ld\n", time1);
- to_tm(time1, tm); /* To Gregorian Date */
+ rtc_to_tm(time1, tm); /* To Gregorian Date */
if (rtc_read(RTC_SR_ADDR) & RTC_SR_BIT_OSF) {
printf ("### Warning: RTC oscillator has stopped\n");
now = ftrtc010_time() + readl(&rtc->record);
#endif
- to_tm(now, tmp);
+ rtc_to_tm(now, tmp);
return 0;
}
}
now = __raw_readl(&data.regs->dtcmr);
- to_tm(now, tmp);
+ rtc_to_tm(now, tmp);
err:
return rc;
tim = day1 * 86400 + time;
- to_tm(tim, rtc);
+ rtc_to_tm(tim, rtc);
rtc->tm_yday = 0;
rtc->tm_isdst = 0;
tim = (tim * 60) + rtc_mins;
tim = (tim * 60) + rtc->seconds;
- to_tm(tim, tmp);
+ rtc_to_tm(tim, tmp);
tmp->tm_yday = 0;
tmp->tm_isdst = 0;
tim = immr->im_sit.sit_rtc;
- to_tm (tim, tmp);
+ rtc_to_tm(tim, tmp);
debug ( "Get DATE: %4d-%02d-%02d (wday=%d) TIME: %2d:%02d:%02d\n",
tmp->tm_year, tmp->tm_mon, tmp->tm_mday, tmp->tm_wday,
sec += min * 60 + hour * 3600 + day * 24 * 3600;
- to_tm(sec, time);
+ rtc_to_tm(sec, time);
return 0;
}
uint32_t secs;
secs = readl(&rtc_regs->hw_rtc_seconds);
- to_tm(secs, time);
+ rtc_to_tm(secs, time);
return 0;
}
tim = RTC_READ_REG(RTC_DR);
- to_tm (tim, tmp);
+ rtc_to_tm(tim, tmp);
debug ( "Get DATE: %4d-%02d-%02d (wday=%d) TIME: %2d:%02d:%02d\n",
tmp->tm_year, tmp->tm_mon, tmp->tm_mday, tmp->tm_wday,
int rtc_set (struct rtc_time *);
void rtc_reset (void);
-void to_tm (int, struct rtc_time *);
unsigned long mktime (unsigned int, unsigned int, unsigned int,
unsigned int, unsigned int, unsigned int);
*/
int rtc_calc_weekday(struct rtc_time *time);
+/**
+ * rtc_to_tm() - Convert a time_t value into a broken-out time
+ *
+ * The following fields are set up by this function:
+ * tm_sec, tm_min, tm_hour, tm_mday, tm_mon, tm_year, tm_wday
+ *
+ * Note that tm_yday and tm_isdst are set to 0.
+ *
+ * @time_t: Number of seconds since 1970-01-01 00:00:00
+ * @time: Place to put the broken-out time
+ * @return 0 if OK, -EINVAL if the weekday could not be determined
+ */
+int rtc_to_tm(int time_t, struct rtc_time *time);
+
#endif /* _RTC_H_ */
*/
memcpy(&seconds, &rpktp->transmit_timestamp, sizeof(ulong));
- to_tm(ntohl(seconds) - 2208988800UL + net_ntp_time_offset, &tm);
+ rtc_to_tm(ntohl(seconds) - 2208988800UL + net_ntp_time_offset, &tm);
#if defined(CONFIG_CMD_DATE)
rtc_set(&tm);
#endif
tm->tm_min, tm->tm_sec) + sec;
struct rtc_time ntm;
- to_tm (t, &ntm);
+ rtc_to_tm(t, &ntm);
rtc_set (&ntm);
}
time_t t = mktime (ynl, i + 1, daysnl[i], 23, 59, 59);
struct rtc_time tm;
- to_tm (t, &tm);
+ rtc_to_tm(t, &tm);
rtc_set (&tm);
skipped++;
time_t t = mktime (yl, i + 1, daysl[i], 23, 59, 59);
struct rtc_time tm;
- to_tm (t, &tm);
+ rtc_to_tm(t, &tm);
rtc_set (&tm);
skipped++;