1 // SPDX-License-Identifier: GPL-2.0+
4 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
12 * The Real Time Clock (RTC) operation is verified by this test.
13 * The following features are verified:
15 * This is verified by analyzing the rtc_get() return status.
17 * This is verified by reading RTC in polling within
18 * a short period of time.
19 * o) Passing month boundaries
20 * This is checked by setting RTC to a second before
21 * a month boundary and reading it after its passing the
22 * boundary. The test is performed for both leap- and
29 #if CONFIG_POST & CONFIG_SYS_POST_RTC
31 static int rtc_post_skip (ulong * diff)
39 start1 = get_timer (0);
43 start2 = get_timer (0);
44 if (tm1.tm_sec != tm2.tm_sec)
46 if (start2 - start1 > 1500)
50 if (tm1.tm_sec != tm2.tm_sec) {
51 *diff = start2 - start1;
59 static void rtc_post_restore (struct rtc_time *tm, unsigned int sec)
61 time_t t = rtc_mktime(tm) + sec;
69 int rtc_post_test (int flags)
74 static unsigned int daysnl[] =
75 { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
76 static unsigned int daysl[] =
77 { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
78 unsigned int ynl = 1999;
79 unsigned int yl = 2000;
80 unsigned int skipped = 0;
83 /* Time reliability */
84 reliable = rtc_get (&svtm);
87 if (rtc_post_skip (&diff) != 0) {
88 post_log ("Timeout while waiting for a new second !\n");
93 for (i = 0; i < 5; i++) {
94 if (rtc_post_skip (&diff) != 0) {
95 post_log ("Timeout while waiting for a new second !\n");
100 if (diff < 950 || diff > 1050) {
101 post_log ("Invalid second duration !\n");
107 /* Passing month boundaries */
109 if (rtc_post_skip (&diff) != 0) {
110 post_log ("Timeout while waiting for a new second !\n");
116 for (i = 0; i < 12; i++) {
122 tm.tm_mday = daysnl[i];
131 if (rtc_post_skip (&diff) != 0) {
132 rtc_post_restore (&svtm, skipped);
133 post_log ("Timeout while waiting for a new second !\n");
139 if (tm.tm_mon == i + 1) {
140 rtc_post_restore (&svtm, skipped);
141 post_log ("Month %d boundary is not passed !\n", i + 1);
147 for (i = 0; i < 12; i++) {
153 tm.tm_mday = daysl[i];
163 if (rtc_post_skip (&diff) != 0) {
164 rtc_post_restore (&svtm, skipped);
165 post_log ("Timeout while waiting for a new second !\n");
171 if (tm.tm_mon == i + 1) {
172 rtc_post_restore (&svtm, skipped);
173 post_log ("Month %d boundary is not passed !\n", i + 1);
178 rtc_post_restore (&svtm, skipped);
180 /* If come here, then RTC operates correcty, check the correctness
181 * of the time it reports.
184 post_log ("RTC Time is not reliable! Power fault? \n");
192 #endif /* CONFIG_POST & CONFIG_SYS_POST_RTC */