]>
git.ipfire.org Git - people/ms/u-boot.git/blob - post/drivers/rtc.c
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5 * See file CREDITS for list of people who contributed to this
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
29 * The Real Time Clock (RTC) operation is verified by this test.
30 * The following features are verified:
32 * This is verified by reading RTC in polling within
33 * a short period of time.
34 * o) Passing month boundaries
35 * This is checked by setting RTC to a second before
36 * a month boundary and reading it after its passing the
37 * boundary. The test is performed for both leap- and
44 #if CONFIG_POST & CFG_POST_RTC
46 static int rtc_post_skip (ulong
* diff
)
54 start1
= get_timer (0);
58 start2
= get_timer (0);
59 if (tm1
.tm_sec
!= tm2
.tm_sec
)
61 if (start2
- start1
> 1500)
65 if (tm1
.tm_sec
!= tm2
.tm_sec
) {
66 *diff
= start2
- start1
;
74 static void rtc_post_restore (struct rtc_time
*tm
, unsigned int sec
)
76 time_t t
= mktime (tm
->tm_year
, tm
->tm_mon
, tm
->tm_mday
, tm
->tm_hour
,
77 tm
->tm_min
, tm
->tm_sec
) + sec
;
85 int rtc_post_test (int flags
)
90 static unsigned int daysnl
[] =
91 { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
92 static unsigned int daysl
[] =
93 { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
94 unsigned int ynl
= 1999;
95 unsigned int yl
= 2000;
96 unsigned int skipped
= 0;
99 if (rtc_post_skip (&diff
) != 0) {
100 post_log ("Timeout while waiting for a new second !\n");
105 for (i
= 0; i
< 5; i
++) {
106 if (rtc_post_skip (&diff
) != 0) {
107 post_log ("Timeout while waiting for a new second !\n");
112 if (diff
< 950 || diff
> 1050) {
113 post_log ("Invalid second duration !\n");
119 /* Passing month boundaries */
121 if (rtc_post_skip (&diff
) != 0) {
122 post_log ("Timeout while waiting for a new second !\n");
128 for (i
= 0; i
< 12; i
++) {
129 time_t t
= mktime (ynl
, i
+ 1, daysnl
[i
], 23, 59, 59);
136 if (rtc_post_skip (&diff
) != 0) {
137 rtc_post_restore (&svtm
, skipped
);
138 post_log ("Timeout while waiting for a new second !\n");
144 if (tm
.tm_mon
== i
+ 1) {
145 rtc_post_restore (&svtm
, skipped
);
146 post_log ("Month %d boundary is not passed !\n", i
+ 1);
152 for (i
= 0; i
< 12; i
++) {
153 time_t t
= mktime (yl
, i
+ 1, daysl
[i
], 23, 59, 59);
160 if (rtc_post_skip (&diff
) != 0) {
161 rtc_post_restore (&svtm
, skipped
);
162 post_log ("Timeout while waiting for a new second !\n");
168 if (tm
.tm_mon
== i
+ 1) {
169 rtc_post_restore (&svtm
, skipped
);
170 post_log ("Month %d boundary is not passed !\n", i
+ 1);
175 rtc_post_restore (&svtm
, skipped
);
180 #endif /* CONFIG_POST & CFG_POST_RTC */