]>
git.ipfire.org Git - people/ms/u-boot.git/blob - post/drivers/rtc.c
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5 * SPDX-License-Identifier: GPL-2.0+
13 * The Real Time Clock (RTC) operation is verified by this test.
14 * The following features are verified:
16 * This is verified by analyzing the rtc_get() return status.
18 * This is verified by reading RTC in polling within
19 * a short period of time.
20 * o) Passing month boundaries
21 * This is checked by setting RTC to a second before
22 * a month boundary and reading it after its passing the
23 * boundary. The test is performed for both leap- and
30 #if CONFIG_POST & CONFIG_SYS_POST_RTC
32 static int rtc_post_skip (ulong
* diff
)
40 start1
= get_timer (0);
44 start2
= get_timer (0);
45 if (tm1
.tm_sec
!= tm2
.tm_sec
)
47 if (start2
- start1
> 1500)
51 if (tm1
.tm_sec
!= tm2
.tm_sec
) {
52 *diff
= start2
- start1
;
60 static void rtc_post_restore (struct rtc_time
*tm
, unsigned int sec
)
62 time_t t
= rtc_mktime(tm
) + sec
;
70 int rtc_post_test (int flags
)
75 static unsigned int daysnl
[] =
76 { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
77 static unsigned int daysl
[] =
78 { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
79 unsigned int ynl
= 1999;
80 unsigned int yl
= 2000;
81 unsigned int skipped
= 0;
84 /* Time reliability */
85 reliable
= rtc_get (&svtm
);
88 if (rtc_post_skip (&diff
) != 0) {
89 post_log ("Timeout while waiting for a new second !\n");
94 for (i
= 0; i
< 5; i
++) {
95 if (rtc_post_skip (&diff
) != 0) {
96 post_log ("Timeout while waiting for a new second !\n");
101 if (diff
< 950 || diff
> 1050) {
102 post_log ("Invalid second duration !\n");
108 /* Passing month boundaries */
110 if (rtc_post_skip (&diff
) != 0) {
111 post_log ("Timeout while waiting for a new second !\n");
117 for (i
= 0; i
< 12; i
++) {
123 tm
.tm_mday
= daysnl
[i
];
132 if (rtc_post_skip (&diff
) != 0) {
133 rtc_post_restore (&svtm
, skipped
);
134 post_log ("Timeout while waiting for a new second !\n");
140 if (tm
.tm_mon
== i
+ 1) {
141 rtc_post_restore (&svtm
, skipped
);
142 post_log ("Month %d boundary is not passed !\n", i
+ 1);
148 for (i
= 0; i
< 12; i
++) {
154 tm
.tm_mday
= daysl
[i
];
164 if (rtc_post_skip (&diff
) != 0) {
165 rtc_post_restore (&svtm
, skipped
);
166 post_log ("Timeout while waiting for a new second !\n");
172 if (tm
.tm_mon
== i
+ 1) {
173 rtc_post_restore (&svtm
, skipped
);
174 post_log ("Month %d boundary is not passed !\n", i
+ 1);
179 rtc_post_restore (&svtm
, skipped
);
181 /* If come here, then RTC operates correcty, check the correctness
182 * of the time it reports.
185 post_log ("RTC Time is not reliable! Power fault? \n");
193 #endif /* CONFIG_POST & CONFIG_SYS_POST_RTC */