ShellPkg: Add extended USB decoding for consistent device names
[mirror_edk2.git] / PcAtChipsetPkg / PcatRealTimeClockRuntimeDxe / PcRtc.c
CommitLineData
fb0b259e 1/** @file\r
2 RTC Architectural Protocol GUID as defined in DxeCis 0.96.\r
8cd4d17c 3\r
0e991a2f 4Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.<BR>\r
95d48e82 5This program and the accompanying materials\r
3cfb790c 6are licensed and made available under the terms and conditions of the BSD License\r
7which accompanies this distribution. The full text of the license may be found at\r
8http://opensource.org/licenses/bsd-license.php\r
9\r
10THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
8cd4d17c 12\r
fb0b259e 13**/\r
8cd4d17c 14\r
15#include "PcRtc.h"\r
16\r
8d85dc31 17/**\r
18 Compare the Hour, Minute and Second of the From time and the To time.\r
19 \r
20 Only compare H/M/S in EFI_TIME and ignore other fields here.\r
21\r
22 @param From the first time\r
23 @param To the second time\r
24\r
25 @return >0 The H/M/S of the From time is later than those of To time\r
26 @return ==0 The H/M/S of the From time is same as those of To time\r
27 @return <0 The H/M/S of the From time is earlier than those of To time\r
28**/\r
8cd4d17c 29INTN\r
30CompareHMS (\r
31 IN EFI_TIME *From,\r
32 IN EFI_TIME *To\r
33 );\r
34\r
8d85dc31 35/**\r
36 To check if second date is later than first date within 24 hours.\r
37\r
38 @param From the first date\r
39 @param To the second date\r
40\r
41 @retval TRUE From is previous to To within 24 hours.\r
42 @retval FALSE From is later, or it is previous to To more than 24 hours.\r
43**/\r
8cd4d17c 44BOOLEAN\r
45IsWithinOneDay (\r
46 IN EFI_TIME *From,\r
47 IN EFI_TIME *To\r
48 );\r
49\r
8d85dc31 50/**\r
51 Read RTC content through its registers.\r
52\r
53 @param Address Address offset of RTC. It is recommended to use macros such as\r
54 RTC_ADDRESS_SECONDS.\r
55\r
56 @return The data of UINT8 type read from RTC.\r
57**/\r
8cd4d17c 58UINT8\r
59RtcRead (\r
60 IN UINT8 Address\r
61 )\r
8cd4d17c 62{\r
63 IoWrite8 (PCAT_RTC_ADDRESS_REGISTER, (UINT8) (Address | (UINT8) (IoRead8 (PCAT_RTC_ADDRESS_REGISTER) & 0x80)));\r
64 return IoRead8 (PCAT_RTC_DATA_REGISTER);\r
65}\r
66\r
8d85dc31 67/**\r
68 Write RTC through its registers.\r
69\r
70 @param Address Address offset of RTC. It is recommended to use macros such as\r
71 RTC_ADDRESS_SECONDS.\r
72 @param Data The content you want to write into RTC.\r
73\r
74**/\r
8cd4d17c 75VOID\r
76RtcWrite (\r
77 IN UINT8 Address,\r
78 IN UINT8 Data\r
79 )\r
8cd4d17c 80{\r
81 IoWrite8 (PCAT_RTC_ADDRESS_REGISTER, (UINT8) (Address | (UINT8) (IoRead8 (PCAT_RTC_ADDRESS_REGISTER) & 0x80)));\r
82 IoWrite8 (PCAT_RTC_DATA_REGISTER, Data);\r
83}\r
84\r
8d85dc31 85/**\r
86 Initialize RTC.\r
87\r
88 @param Global For global use inside this module.\r
89\r
90 @retval EFI_DEVICE_ERROR Initialization failed due to device error.\r
91 @retval EFI_SUCCESS Initialization successful.\r
92\r
93**/\r
8cd4d17c 94EFI_STATUS\r
95PcRtcInit (\r
96 IN PC_RTC_MODULE_GLOBALS *Global\r
97 )\r
8cd4d17c 98{\r
99 EFI_STATUS Status;\r
100 RTC_REGISTER_A RegisterA;\r
101 RTC_REGISTER_B RegisterB;\r
102 RTC_REGISTER_D RegisterD;\r
103 UINT8 Century;\r
104 EFI_TIME Time;\r
ec35e997
LG
105 UINTN DataSize;\r
106 UINT32 TimerVar;\r
8cd4d17c 107\r
108 //\r
109 // Acquire RTC Lock to make access to RTC atomic\r
110 //\r
8cd4d17c 111 if (!EfiAtRuntime ()) {\r
8d85dc31 112 EfiAcquireLock (&Global->RtcLock);\r
8cd4d17c 113 }\r
114 //\r
115 // Initialize RTC Register\r
116 //\r
117 // Make sure Division Chain is properly configured,\r
118 // or RTC clock won't "tick" -- time won't increment\r
119 //\r
120 RegisterA.Data = RTC_INIT_REGISTER_A;\r
121 RtcWrite (RTC_ADDRESS_REGISTER_A, RegisterA.Data);\r
122\r
123 //\r
124 // Read Register B\r
125 //\r
126 RegisterB.Data = RtcRead (RTC_ADDRESS_REGISTER_B);\r
127\r
128 //\r
129 // Clear RTC flag register\r
130 //\r
131 RtcRead (RTC_ADDRESS_REGISTER_C);\r
132\r
133 //\r
134 // Clear RTC register D\r
135 //\r
136 RegisterD.Data = RTC_INIT_REGISTER_D;\r
137 RtcWrite (RTC_ADDRESS_REGISTER_D, RegisterD.Data);\r
138\r
139 //\r
140 // Wait for up to 0.1 seconds for the RTC to be updated\r
141 //\r
f8ea3026 142 Status = RtcWaitToUpdate (PcdGet32 (PcdRealTimeClockUpdateTimeout));\r
8cd4d17c 143 if (EFI_ERROR (Status)) {\r
6ff84d99 144 //\r
145 // Set the variable with default value if the RTC is functioning incorrectly.\r
146 //\r
147 Global->SavedTimeZone = EFI_UNSPECIFIED_TIMEZONE;\r
148 Global->Daylight = 0;\r
8cd4d17c 149 if (!EfiAtRuntime ()) {\r
8d85dc31 150 EfiReleaseLock (&Global->RtcLock);\r
8cd4d17c 151 }\r
152 return EFI_DEVICE_ERROR;\r
153 }\r
154 //\r
155 // Get the Time/Date/Daylight Savings values.\r
156 //\r
157 Time.Second = RtcRead (RTC_ADDRESS_SECONDS);\r
158 Time.Minute = RtcRead (RTC_ADDRESS_MINUTES);\r
159 Time.Hour = RtcRead (RTC_ADDRESS_HOURS);\r
160 Time.Day = RtcRead (RTC_ADDRESS_DAY_OF_THE_MONTH);\r
161 Time.Month = RtcRead (RTC_ADDRESS_MONTH);\r
162 Time.Year = RtcRead (RTC_ADDRESS_YEAR);\r
163\r
9a1eee23 164 Century = RtcRead (RTC_ADDRESS_CENTURY);\r
9a1eee23 165 \r
8cd4d17c 166 //\r
167 // Set RTC configuration after get original time\r
ec35e997 168 // The value of bit AIE should be reserved.\r
8cd4d17c 169 //\r
f7033880 170 RtcWrite (RTC_ADDRESS_REGISTER_B, (UINT8)(RTC_INIT_REGISTER_B | (RegisterB.Data & BIT5)));\r
8cd4d17c 171\r
172 //\r
173 // Release RTC Lock.\r
174 //\r
8cd4d17c 175 if (!EfiAtRuntime ()) {\r
8d85dc31 176 EfiReleaseLock (&Global->RtcLock);\r
8cd4d17c 177 }\r
254ba247 178 \r
6bfa178c 179 //\r
180 // Get the data of Daylight saving and time zone, if they have been\r
181 // stored in NV variable during previous boot.\r
182 //\r
183 DataSize = sizeof (UINT32);\r
184 Status = EfiGetVariable (\r
185 L"RTC",\r
186 &gEfiCallerIdGuid,\r
187 NULL,\r
188 &DataSize,\r
189 (VOID *) &TimerVar\r
190 );\r
191 if (!EFI_ERROR (Status)) {\r
192 Time.TimeZone = (INT16) TimerVar;\r
193 Time.Daylight = (UINT8) (TimerVar >> 16);\r
194 } else {\r
195 Time.TimeZone = EFI_UNSPECIFIED_TIMEZONE;\r
196 Time.Daylight = 0; \r
197 }\r
198\r
8cd4d17c 199 //\r
200 // Validate time fields\r
201 //\r
254ba247 202 Status = ConvertRtcTimeToEfiTime (&Time, Century, RegisterB);\r
203 if (!EFI_ERROR (Status)) {\r
204 Status = RtcTimeFieldsValid (&Time);\r
205 }\r
8cd4d17c 206 if (EFI_ERROR (Status)) {\r
44d52203 207 //\r
208 // Report Status Code to indicate that the RTC has bad date and time\r
209 //\r
210 REPORT_STATUS_CODE (\r
211 EFI_ERROR_CODE | EFI_ERROR_MINOR,\r
212 (EFI_SOFTWARE_DXE_RT_DRIVER | EFI_SW_EC_BAD_DATE_TIME)\r
213 );\r
8cd4d17c 214 Time.Second = RTC_INIT_SECOND;\r
215 Time.Minute = RTC_INIT_MINUTE;\r
216 Time.Hour = RTC_INIT_HOUR;\r
217 Time.Day = RTC_INIT_DAY;\r
218 Time.Month = RTC_INIT_MONTH;\r
219 Time.Year = RTC_INIT_YEAR;\r
2ba53a4f 220 Time.Nanosecond = 0;\r
9bb1fced 221 Time.TimeZone = EFI_UNSPECIFIED_TIMEZONE;\r
222 Time.Daylight = 0;\r
8cd4d17c 223 }\r
ec35e997 224\r
ec35e997 225 //\r
8cd4d17c 226 // Reset time value according to new RTC configuration\r
227 //\r
2ba53a4f 228 Status = PcRtcSetTime (&Time, Global);\r
229 if(!EFI_ERROR (Status)) {\r
230 return EFI_SUCCESS;\r
231 } else {\r
232 return EFI_DEVICE_ERROR;\r
233 }\r
8cd4d17c 234}\r
235\r
8d85dc31 236/**\r
237 Returns the current time and date information, and the time-keeping capabilities\r
238 of the hardware platform.\r
8cd4d17c 239\r
8d85dc31 240 @param Time A pointer to storage to receive a snapshot of the current time.\r
241 @param Capabilities An optional pointer to a buffer to receive the real time clock\r
242 device's capabilities.\r
243 @param Global For global use inside this module.\r
8cd4d17c 244\r
8d85dc31 245 @retval EFI_SUCCESS The operation completed successfully.\r
246 @retval EFI_INVALID_PARAMETER Time is NULL.\r
247 @retval EFI_DEVICE_ERROR The time could not be retrieved due to hardware error.\r
8cd4d17c 248\r
8d85dc31 249**/\r
250EFI_STATUS\r
251PcRtcGetTime (\r
252 OUT EFI_TIME *Time,\r
253 OUT EFI_TIME_CAPABILITIES *Capabilities, OPTIONAL\r
254 IN PC_RTC_MODULE_GLOBALS *Global\r
255 )\r
8cd4d17c 256{\r
257 EFI_STATUS Status;\r
258 RTC_REGISTER_B RegisterB;\r
259 UINT8 Century;\r
260\r
261 //\r
262 // Check parameters for null pointer\r
263 //\r
264 if (Time == NULL) {\r
265 return EFI_INVALID_PARAMETER;\r
266\r
267 }\r
268 //\r
269 // Acquire RTC Lock to make access to RTC atomic\r
270 //\r
8cd4d17c 271 if (!EfiAtRuntime ()) {\r
8d85dc31 272 EfiAcquireLock (&Global->RtcLock);\r
8cd4d17c 273 }\r
274 //\r
275 // Wait for up to 0.1 seconds for the RTC to be updated\r
276 //\r
f8ea3026 277 Status = RtcWaitToUpdate (PcdGet32 (PcdRealTimeClockUpdateTimeout));\r
8cd4d17c 278 if (EFI_ERROR (Status)) {\r
8cd4d17c 279 if (!EfiAtRuntime ()) {\r
8d85dc31 280 EfiReleaseLock (&Global->RtcLock);\r
8cd4d17c 281 }\r
282 return Status;\r
283 }\r
284 //\r
285 // Read Register B\r
286 //\r
287 RegisterB.Data = RtcRead (RTC_ADDRESS_REGISTER_B);\r
288\r
289 //\r
290 // Get the Time/Date/Daylight Savings values.\r
291 //\r
292 Time->Second = RtcRead (RTC_ADDRESS_SECONDS);\r
293 Time->Minute = RtcRead (RTC_ADDRESS_MINUTES);\r
294 Time->Hour = RtcRead (RTC_ADDRESS_HOURS);\r
295 Time->Day = RtcRead (RTC_ADDRESS_DAY_OF_THE_MONTH);\r
296 Time->Month = RtcRead (RTC_ADDRESS_MONTH);\r
297 Time->Year = RtcRead (RTC_ADDRESS_YEAR);\r
298\r
9a1eee23 299 Century = RtcRead (RTC_ADDRESS_CENTURY);\r
9a1eee23 300 \r
8cd4d17c 301 //\r
302 // Release RTC Lock.\r
303 //\r
8cd4d17c 304 if (!EfiAtRuntime ()) {\r
8d85dc31 305 EfiReleaseLock (&Global->RtcLock);\r
8cd4d17c 306 }\r
6bfa178c 307\r
8cd4d17c 308 //\r
2d4117c0 309 // Get the variable that contains the TimeZone and Daylight fields\r
8cd4d17c 310 //\r
311 Time->TimeZone = Global->SavedTimeZone;\r
312 Time->Daylight = Global->Daylight;\r
313\r
314 //\r
315 // Make sure all field values are in correct range\r
316 //\r
254ba247 317 Status = ConvertRtcTimeToEfiTime (Time, Century, RegisterB);\r
318 if (!EFI_ERROR (Status)) {\r
319 Status = RtcTimeFieldsValid (Time);\r
320 }\r
8cd4d17c 321 if (EFI_ERROR (Status)) {\r
322 return EFI_DEVICE_ERROR;\r
323 }\r
6bfa178c 324\r
8cd4d17c 325 //\r
326 // Fill in Capabilities if it was passed in\r
327 //\r
8d85dc31 328 if (Capabilities != NULL) {\r
8cd4d17c 329 Capabilities->Resolution = 1;\r
330 //\r
331 // 1 hertz\r
332 //\r
333 Capabilities->Accuracy = 50000000;\r
334 //\r
335 // 50 ppm\r
336 //\r
337 Capabilities->SetsToZero = FALSE;\r
338 }\r
339\r
340 return EFI_SUCCESS;\r
341}\r
342\r
8d85dc31 343/**\r
344 Sets the current local time and date information.\r
345\r
346 @param Time A pointer to the current time.\r
347 @param Global For global use inside this module.\r
348\r
349 @retval EFI_SUCCESS The operation completed successfully.\r
350 @retval EFI_INVALID_PARAMETER A time field is out of range.\r
351 @retval EFI_DEVICE_ERROR The time could not be set due due to hardware error.\r
352\r
353**/\r
8cd4d17c 354EFI_STATUS\r
355PcRtcSetTime (\r
356 IN EFI_TIME *Time,\r
357 IN PC_RTC_MODULE_GLOBALS *Global\r
358 )\r
8cd4d17c 359{\r
360 EFI_STATUS Status;\r
361 EFI_TIME RtcTime;\r
362 RTC_REGISTER_B RegisterB;\r
363 UINT8 Century;\r
ec35e997 364 UINT32 TimerVar;\r
8cd4d17c 365\r
366 if (Time == NULL) {\r
367 return EFI_INVALID_PARAMETER;\r
368 }\r
369 //\r
370 // Make sure that the time fields are valid\r
371 //\r
372 Status = RtcTimeFieldsValid (Time);\r
373 if (EFI_ERROR (Status)) {\r
374 return Status;\r
375 }\r
376\r
377 CopyMem (&RtcTime, Time, sizeof (EFI_TIME));\r
378\r
379 //\r
380 // Acquire RTC Lock to make access to RTC atomic\r
381 //\r
8cd4d17c 382 if (!EfiAtRuntime ()) {\r
8d85dc31 383 EfiAcquireLock (&Global->RtcLock);\r
8cd4d17c 384 }\r
385 //\r
386 // Wait for up to 0.1 seconds for the RTC to be updated\r
387 //\r
f8ea3026 388 Status = RtcWaitToUpdate (PcdGet32 (PcdRealTimeClockUpdateTimeout));\r
8cd4d17c 389 if (EFI_ERROR (Status)) {\r
8cd4d17c 390 if (!EfiAtRuntime ()) {\r
ca08e40b 391 EfiReleaseLock (&Global->RtcLock);\r
8cd4d17c 392 }\r
393 return Status;\r
394 }\r
0e991a2f
EL
395 \r
396 //\r
397 // Write timezone and daylight to RTC variable\r
398 //\r
399 TimerVar = Time->Daylight;\r
400 TimerVar = (UINT32) ((TimerVar << 16) | (UINT16)(Time->TimeZone));\r
401 Status = EfiSetVariable (\r
402 L"RTC",\r
403 &gEfiCallerIdGuid,\r
404 EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,\r
405 sizeof (TimerVar),\r
406 &TimerVar\r
407 );\r
408 if (EFI_ERROR (Status)) {\r
409 if (!EfiAtRuntime ()) {\r
410 EfiReleaseLock (&Global->RtcLock);\r
411 }\r
412 return EFI_DEVICE_ERROR;\r
413 }\r
414\r
8cd4d17c 415 //\r
416 // Read Register B, and inhibit updates of the RTC\r
417 //\r
418 RegisterB.Data = RtcRead (RTC_ADDRESS_REGISTER_B);\r
24115e44 419 RegisterB.Bits.Set = 1;\r
8cd4d17c 420 RtcWrite (RTC_ADDRESS_REGISTER_B, RegisterB.Data);\r
421\r
422 ConvertEfiTimeToRtcTime (&RtcTime, RegisterB, &Century);\r
423\r
424 RtcWrite (RTC_ADDRESS_SECONDS, RtcTime.Second);\r
425 RtcWrite (RTC_ADDRESS_MINUTES, RtcTime.Minute);\r
426 RtcWrite (RTC_ADDRESS_HOURS, RtcTime.Hour);\r
427 RtcWrite (RTC_ADDRESS_DAY_OF_THE_MONTH, RtcTime.Day);\r
428 RtcWrite (RTC_ADDRESS_MONTH, RtcTime.Month);\r
429 RtcWrite (RTC_ADDRESS_YEAR, (UINT8) RtcTime.Year);\r
8cd4d17c 430 RtcWrite (RTC_ADDRESS_CENTURY, Century);\r
431\r
432 //\r
433 // Allow updates of the RTC registers\r
434 //\r
24115e44 435 RegisterB.Bits.Set = 0;\r
8cd4d17c 436 RtcWrite (RTC_ADDRESS_REGISTER_B, RegisterB.Data);\r
437\r
438 //\r
439 // Release RTC Lock.\r
440 //\r
8cd4d17c 441 if (!EfiAtRuntime ()) {\r
8d85dc31 442 EfiReleaseLock (&Global->RtcLock);\r
8cd4d17c 443 }\r
444 //\r
2d4117c0 445 // Set the variable that contains the TimeZone and Daylight fields\r
8cd4d17c 446 //\r
447 Global->SavedTimeZone = Time->TimeZone;\r
448 Global->Daylight = Time->Daylight;\r
ec35e997 449\r
ec35e997 450 return EFI_SUCCESS;\r
8cd4d17c 451}\r
452\r
8d85dc31 453/**\r
454 Returns the current wakeup alarm clock setting.\r
455\r
456 @param Enabled Indicates if the alarm is currently enabled or disabled.\r
2d4117c0 457 @param Pending Indicates if the alarm signal is pending and requires acknowledgment.\r
8d85dc31 458 @param Time The current alarm setting.\r
459 @param Global For global use inside this module.\r
460\r
461 @retval EFI_SUCCESS The alarm settings were returned.\r
462 @retval EFI_INVALID_PARAMETER Enabled is NULL.\r
463 @retval EFI_INVALID_PARAMETER Pending is NULL.\r
464 @retval EFI_INVALID_PARAMETER Time is NULL.\r
465 @retval EFI_DEVICE_ERROR The wakeup time could not be retrieved due to a hardware error.\r
466 @retval EFI_UNSUPPORTED A wakeup timer is not supported on this platform.\r
467\r
468**/\r
8cd4d17c 469EFI_STATUS\r
470PcRtcGetWakeupTime (\r
471 OUT BOOLEAN *Enabled,\r
472 OUT BOOLEAN *Pending,\r
473 OUT EFI_TIME *Time,\r
8d85dc31 474 IN PC_RTC_MODULE_GLOBALS *Global\r
8cd4d17c 475 )\r
8cd4d17c 476{\r
477 EFI_STATUS Status;\r
478 RTC_REGISTER_B RegisterB;\r
479 RTC_REGISTER_C RegisterC;\r
480 UINT8 Century;\r
7018623c 481 EFI_TIME RtcTime;\r
482 UINTN DataSize;\r
8cd4d17c 483\r
484 //\r
2d4117c0 485 // Check parameters for null pointers\r
8cd4d17c 486 //\r
487 if ((Enabled == NULL) || (Pending == NULL) || (Time == NULL)) {\r
488 return EFI_INVALID_PARAMETER;\r
489\r
490 }\r
491 //\r
492 // Acquire RTC Lock to make access to RTC atomic\r
493 //\r
8cd4d17c 494 if (!EfiAtRuntime ()) {\r
8d85dc31 495 EfiAcquireLock (&Global->RtcLock);\r
8cd4d17c 496 }\r
497 //\r
498 // Wait for up to 0.1 seconds for the RTC to be updated\r
499 //\r
f8ea3026 500 Status = RtcWaitToUpdate (PcdGet32 (PcdRealTimeClockUpdateTimeout));\r
8cd4d17c 501 if (EFI_ERROR (Status)) {\r
8cd4d17c 502 if (!EfiAtRuntime ()) {\r
503 EfiReleaseLock (&Global->RtcLock);\r
504 }\r
505 return EFI_DEVICE_ERROR;\r
506 }\r
507 //\r
508 // Read Register B and Register C\r
509 //\r
510 RegisterB.Data = RtcRead (RTC_ADDRESS_REGISTER_B);\r
511 RegisterC.Data = RtcRead (RTC_ADDRESS_REGISTER_C);\r
512\r
513 //\r
514 // Get the Time/Date/Daylight Savings values.\r
515 //\r
24115e44 516 *Enabled = RegisterB.Bits.Aie;\r
7018623c 517 *Pending = RegisterC.Bits.Af;\r
518\r
519 Time->Second = RtcRead (RTC_ADDRESS_SECONDS_ALARM);\r
520 Time->Minute = RtcRead (RTC_ADDRESS_MINUTES_ALARM);\r
521 Time->Hour = RtcRead (RTC_ADDRESS_HOURS_ALARM);\r
522 Time->Day = RtcRead (RTC_ADDRESS_DAY_OF_THE_MONTH);\r
523 Time->Month = RtcRead (RTC_ADDRESS_MONTH);\r
524 Time->Year = RtcRead (RTC_ADDRESS_YEAR);\r
525 Time->TimeZone = Global->SavedTimeZone;\r
526 Time->Daylight = Global->Daylight;\r
8cd4d17c 527\r
9a1eee23 528 Century = RtcRead (RTC_ADDRESS_CENTURY);\r
7018623c 529\r
8cd4d17c 530 //\r
7018623c 531 // Get the alarm info from variable\r
8cd4d17c 532 //\r
ffa1e783 533 DataSize = sizeof (EFI_TIME);\r
7018623c 534 Status = EfiGetVariable (\r
535 L"RTCALARM",\r
536 &gEfiCallerIdGuid,\r
537 NULL,\r
538 &DataSize,\r
539 &RtcTime\r
540 );\r
541 if (!EFI_ERROR (Status)) {\r
542 //\r
543 // The alarm variable exists. In this case, we read variable to get info.\r
544 //\r
545 Time->Day = RtcTime.Day;\r
546 Time->Month = RtcTime.Month;\r
547 Time->Year = RtcTime.Year;\r
8cd4d17c 548 }\r
6bfa178c 549\r
550 //\r
7018623c 551 // Release RTC Lock.\r
6bfa178c 552 //\r
7018623c 553 if (!EfiAtRuntime ()) {\r
554 EfiReleaseLock (&Global->RtcLock);\r
555 }\r
6bfa178c 556\r
8cd4d17c 557 //\r
558 // Make sure all field values are in correct range\r
559 //\r
254ba247 560 Status = ConvertRtcTimeToEfiTime (Time, Century, RegisterB);\r
561 if (!EFI_ERROR (Status)) {\r
562 Status = RtcTimeFieldsValid (Time);\r
563 }\r
8cd4d17c 564 if (EFI_ERROR (Status)) {\r
565 return EFI_DEVICE_ERROR;\r
566 }\r
567\r
8cd4d17c 568 return EFI_SUCCESS;\r
569}\r
570\r
8d85dc31 571/**\r
572 Sets the system wakeup alarm clock time.\r
573\r
574 @param Enabled Enable or disable the wakeup alarm.\r
575 @param Time If Enable is TRUE, the time to set the wakeup alarm for.\r
576 If Enable is FALSE, then this parameter is optional, and may be NULL.\r
577 @param Global For global use inside this module.\r
578\r
579 @retval EFI_SUCCESS If Enable is TRUE, then the wakeup alarm was enabled.\r
580 If Enable is FALSE, then the wakeup alarm was disabled.\r
581 @retval EFI_INVALID_PARAMETER A time field is out of range.\r
582 @retval EFI_DEVICE_ERROR The wakeup time could not be set due to a hardware error.\r
583 @retval EFI_UNSUPPORTED A wakeup timer is not supported on this platform.\r
584\r
585**/\r
8cd4d17c 586EFI_STATUS\r
587PcRtcSetWakeupTime (\r
588 IN BOOLEAN Enable,\r
8d85dc31 589 IN EFI_TIME *Time, OPTIONAL\r
8cd4d17c 590 IN PC_RTC_MODULE_GLOBALS *Global\r
591 )\r
8cd4d17c 592{\r
593 EFI_STATUS Status;\r
594 EFI_TIME RtcTime;\r
595 RTC_REGISTER_B RegisterB;\r
596 UINT8 Century;\r
597 EFI_TIME_CAPABILITIES Capabilities;\r
598\r
aca70749 599 ZeroMem (&RtcTime, sizeof (RtcTime));\r
7018623c 600\r
8cd4d17c 601 if (Enable) {\r
602\r
603 if (Time == NULL) {\r
604 return EFI_INVALID_PARAMETER;\r
605 }\r
606 //\r
607 // Make sure that the time fields are valid\r
608 //\r
609 Status = RtcTimeFieldsValid (Time);\r
610 if (EFI_ERROR (Status)) {\r
611 return EFI_INVALID_PARAMETER;\r
612 }\r
613 //\r
614 // Just support set alarm time within 24 hours\r
615 //\r
616 PcRtcGetTime (&RtcTime, &Capabilities, Global);\r
79864f54 617 Status = RtcTimeFieldsValid (&RtcTime);\r
618 if (EFI_ERROR (Status)) {\r
619 return EFI_DEVICE_ERROR;\r
620 }\r
8cd4d17c 621 if (!IsWithinOneDay (&RtcTime, Time)) {\r
622 return EFI_UNSUPPORTED;\r
623 }\r
624 //\r
625 // Make a local copy of the time and date\r
626 //\r
627 CopyMem (&RtcTime, Time, sizeof (EFI_TIME));\r
628\r
629 }\r
630 //\r
631 // Acquire RTC Lock to make access to RTC atomic\r
632 //\r
8cd4d17c 633 if (!EfiAtRuntime ()) {\r
8d85dc31 634 EfiAcquireLock (&Global->RtcLock);\r
8cd4d17c 635 }\r
636 //\r
637 // Wait for up to 0.1 seconds for the RTC to be updated\r
638 //\r
f8ea3026 639 Status = RtcWaitToUpdate (PcdGet32 (PcdRealTimeClockUpdateTimeout));\r
8cd4d17c 640 if (EFI_ERROR (Status)) {\r
8cd4d17c 641 if (!EfiAtRuntime ()) {\r
642 EfiReleaseLock (&Global->RtcLock);\r
643 }\r
644 return EFI_DEVICE_ERROR;\r
645 }\r
646 //\r
0e991a2f 647 // Read Register B\r
8cd4d17c 648 //\r
0e991a2f 649 RegisterB.Data = RtcRead (RTC_ADDRESS_REGISTER_B);\r
8cd4d17c 650\r
651 if (Enable) {\r
652 ConvertEfiTimeToRtcTime (&RtcTime, RegisterB, &Century);\r
8cd4d17c 653 } else {\r
7018623c 654 //\r
655 // if the alarm is disable, record the current setting.\r
656 //\r
657 RtcTime.Second = RtcRead (RTC_ADDRESS_SECONDS_ALARM);\r
658 RtcTime.Minute = RtcRead (RTC_ADDRESS_MINUTES_ALARM);\r
659 RtcTime.Hour = RtcRead (RTC_ADDRESS_HOURS_ALARM);\r
660 RtcTime.Day = RtcRead (RTC_ADDRESS_DAY_OF_THE_MONTH);\r
661 RtcTime.Month = RtcRead (RTC_ADDRESS_MONTH);\r
662 RtcTime.Year = RtcRead (RTC_ADDRESS_YEAR);\r
663 RtcTime.TimeZone = Global->SavedTimeZone;\r
664 RtcTime.Daylight = Global->Daylight;\r
8cd4d17c 665 }\r
8cd4d17c 666\r
7018623c 667 //\r
668 // Set the Y/M/D info to variable as it has no corresponding hw registers.\r
669 //\r
670 Status = EfiSetVariable (\r
671 L"RTCALARM",\r
672 &gEfiCallerIdGuid,\r
673 EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,\r
674 sizeof (RtcTime),\r
675 &RtcTime\r
676 );\r
677 if (EFI_ERROR (Status)) {\r
0e991a2f
EL
678 if (!EfiAtRuntime ()) {\r
679 EfiReleaseLock (&Global->RtcLock);\r
680 }\r
7018623c 681 return EFI_DEVICE_ERROR;\r
682 }\r
0e991a2f
EL
683 \r
684 //\r
685 // Inhibit updates of the RTC\r
686 //\r
687 RegisterB.Bits.Set = 1;\r
688 RtcWrite (RTC_ADDRESS_REGISTER_B, RegisterB.Data);\r
689\r
690 if (Enable) {\r
691 //\r
692 // Set RTC alarm time\r
693 //\r
694 RtcWrite (RTC_ADDRESS_SECONDS_ALARM, RtcTime.Second);\r
695 RtcWrite (RTC_ADDRESS_MINUTES_ALARM, RtcTime.Minute);\r
696 RtcWrite (RTC_ADDRESS_HOURS_ALARM, RtcTime.Hour);\r
697\r
698 RegisterB.Bits.Aie = 1;\r
699\r
700 } else {\r
701 RegisterB.Bits.Aie = 0;\r
702 }\r
703 //\r
704 // Allow updates of the RTC registers\r
705 //\r
706 RegisterB.Bits.Set = 0;\r
707 RtcWrite (RTC_ADDRESS_REGISTER_B, RegisterB.Data);\r
7018623c 708\r
8cd4d17c 709 //\r
710 // Release RTC Lock.\r
711 //\r
8cd4d17c 712 if (!EfiAtRuntime ()) {\r
8d85dc31 713 EfiReleaseLock (&Global->RtcLock);\r
8cd4d17c 714 }\r
715 return EFI_SUCCESS;\r
716}\r
717\r
8cd4d17c 718\r
254ba247 719/**\r
720 Checks an 8-bit BCD value, and converts to an 8-bit value if valid.\r
721\r
722 This function checks the 8-bit BCD value specified by Value.\r
723 If valid, the function converts it to an 8-bit value and returns it.\r
724 Otherwise, return 0xff.\r
725\r
8d85dc31 726 @param Value The 8-bit BCD value to check and convert\r
254ba247 727\r
8d85dc31 728 @return The 8-bit value converted. Or 0xff if Value is invalid.\r
254ba247 729\r
730**/\r
731UINT8\r
732CheckAndConvertBcd8ToDecimal8 (\r
733 IN UINT8 Value\r
8cd4d17c 734 )\r
254ba247 735{\r
736 if ((Value < 0xa0) && ((Value & 0xf) < 0xa)) {\r
737 return BcdToDecimal8 (Value);\r
738 }\r
8cd4d17c 739\r
254ba247 740 return 0xff;\r
741}\r
8cd4d17c 742\r
254ba247 743/**\r
744 Converts time read from RTC to EFI_TIME format defined by UEFI spec.\r
8cd4d17c 745\r
254ba247 746 This function converts raw time data read from RTC to the EFI_TIME format\r
747 defined by UEFI spec.\r
748 If data mode of RTC is BCD, then converts it to decimal,\r
749 If RTC is in 12-hour format, then converts it to 24-hour format.\r
8cd4d17c 750\r
254ba247 751 @param Time On input, the time data read from RTC to convert\r
752 On output, the time converted to UEFI format\r
753 @param Century Value of century read from RTC.\r
754 @param RegisterB Value of Register B of RTC, indicating data mode\r
755 and hour format.\r
8cd4d17c 756\r
8d85dc31 757 @retval EFI_INVALID_PARAMETER Parameters passed in are invalid.\r
758 @retval EFI_SUCCESS Convert RTC time to EFI time successfully.\r
759\r
254ba247 760**/\r
761EFI_STATUS\r
762ConvertRtcTimeToEfiTime (\r
763 IN OUT EFI_TIME *Time,\r
764 IN UINT8 Century,\r
765 IN RTC_REGISTER_B RegisterB\r
766 )\r
8cd4d17c 767{\r
8d85dc31 768 BOOLEAN IsPM;\r
8cd4d17c 769\r
21176834 770 if ((Time->Hour & 0x80) != 0) {\r
8d85dc31 771 IsPM = TRUE;\r
8cd4d17c 772 } else {\r
8d85dc31 773 IsPM = FALSE;\r
8cd4d17c 774 }\r
775\r
776 Time->Hour = (UINT8) (Time->Hour & 0x7f);\r
777\r
24115e44 778 if (RegisterB.Bits.Dm == 0) {\r
254ba247 779 Time->Year = CheckAndConvertBcd8ToDecimal8 ((UINT8) Time->Year);\r
780 Time->Month = CheckAndConvertBcd8ToDecimal8 (Time->Month);\r
781 Time->Day = CheckAndConvertBcd8ToDecimal8 (Time->Day);\r
782 Time->Hour = CheckAndConvertBcd8ToDecimal8 (Time->Hour);\r
783 Time->Minute = CheckAndConvertBcd8ToDecimal8 (Time->Minute);\r
784 Time->Second = CheckAndConvertBcd8ToDecimal8 (Time->Second);\r
254ba247 785 }\r
42c65073 786 Century = CheckAndConvertBcd8ToDecimal8 (Century);\r
254ba247 787\r
788 if (Time->Year == 0xff || Time->Month == 0xff || Time->Day == 0xff ||\r
789 Time->Hour == 0xff || Time->Minute == 0xff || Time->Second == 0xff ||\r
790 Century == 0xff) {\r
791 return EFI_INVALID_PARAMETER;\r
8cd4d17c 792 }\r
254ba247 793\r
794 Time->Year = (UINT16) (Century * 100 + Time->Year);\r
795\r
8cd4d17c 796 //\r
797 // If time is in 12 hour format, convert it to 24 hour format\r
798 //\r
24115e44 799 if (RegisterB.Bits.Mil == 0) {\r
8d85dc31 800 if (IsPM && Time->Hour < 12) {\r
8cd4d17c 801 Time->Hour = (UINT8) (Time->Hour + 12);\r
802 }\r
803\r
8d85dc31 804 if (!IsPM && Time->Hour == 12) {\r
8cd4d17c 805 Time->Hour = 0;\r
806 }\r
807 }\r
808\r
809 Time->Nanosecond = 0;\r
254ba247 810\r
811 return EFI_SUCCESS;\r
8cd4d17c 812}\r
813\r
8d85dc31 814/**\r
815 Wait for a period for the RTC to be ready.\r
816\r
817 @param Timeout Tell how long it should take to wait.\r
818\r
819 @retval EFI_DEVICE_ERROR RTC device error.\r
820 @retval EFI_SUCCESS RTC is updated and ready. \r
821**/\r
8cd4d17c 822EFI_STATUS\r
823RtcWaitToUpdate (\r
824 UINTN Timeout\r
825 )\r
8cd4d17c 826{\r
827 RTC_REGISTER_A RegisterA;\r
828 RTC_REGISTER_D RegisterD;\r
829\r
830 //\r
831 // See if the RTC is functioning correctly\r
832 //\r
833 RegisterD.Data = RtcRead (RTC_ADDRESS_REGISTER_D);\r
834\r
24115e44 835 if (RegisterD.Bits.Vrt == 0) {\r
8cd4d17c 836 return EFI_DEVICE_ERROR;\r
837 }\r
838 //\r
839 // Wait for up to 0.1 seconds for the RTC to be ready.\r
840 //\r
841 Timeout = (Timeout / 10) + 1;\r
842 RegisterA.Data = RtcRead (RTC_ADDRESS_REGISTER_A);\r
24115e44 843 while (RegisterA.Bits.Uip == 1 && Timeout > 0) {\r
8cd4d17c 844 MicroSecondDelay (10);\r
845 RegisterA.Data = RtcRead (RTC_ADDRESS_REGISTER_A);\r
846 Timeout--;\r
847 }\r
848\r
849 RegisterD.Data = RtcRead (RTC_ADDRESS_REGISTER_D);\r
24115e44 850 if (Timeout == 0 || RegisterD.Bits.Vrt == 0) {\r
8cd4d17c 851 return EFI_DEVICE_ERROR;\r
852 }\r
853\r
854 return EFI_SUCCESS;\r
855}\r
856\r
8d85dc31 857/**\r
858 See if all fields of a variable of EFI_TIME type is correct.\r
859\r
860 @param Time The time to be checked.\r
861\r
862 @retval EFI_INVALID_PARAMETER Some fields of Time are not correct.\r
863 @retval EFI_SUCCESS Time is a valid EFI_TIME variable.\r
864\r
865**/\r
8cd4d17c 866EFI_STATUS\r
867RtcTimeFieldsValid (\r
868 IN EFI_TIME *Time\r
869 )\r
8cd4d17c 870{\r
871 if (Time->Year < 1998 ||\r
872 Time->Year > 2099 ||\r
873 Time->Month < 1 ||\r
874 Time->Month > 12 ||\r
6bfa178c 875 (!DayValid (Time)) ||\r
8cd4d17c 876 Time->Hour > 23 ||\r
877 Time->Minute > 59 ||\r
878 Time->Second > 59 ||\r
879 Time->Nanosecond > 999999999 ||\r
880 (!(Time->TimeZone == EFI_UNSPECIFIED_TIMEZONE || (Time->TimeZone >= -1440 && Time->TimeZone <= 1440))) ||\r
6bfa178c 881 ((Time->Daylight & (~(EFI_TIME_ADJUST_DAYLIGHT | EFI_TIME_IN_DAYLIGHT))) != 0)) {\r
882 return EFI_INVALID_PARAMETER;\r
8cd4d17c 883 }\r
884\r
885 return EFI_SUCCESS;\r
886}\r
887\r
8d85dc31 888/**\r
889 See if field Day of an EFI_TIME is correct.\r
890\r
891 @param Time Its Day field is to be checked.\r
892\r
893 @retval TRUE Day field of Time is correct.\r
894 @retval FALSE Day field of Time is NOT correct.\r
895**/\r
8cd4d17c 896BOOLEAN\r
897DayValid (\r
898 IN EFI_TIME *Time\r
899 )\r
8cd4d17c 900{\r
558bfebb 901 INTN DayOfMonth[12];\r
902\r
903 DayOfMonth[0] = 31;\r
904 DayOfMonth[1] = 29;\r
905 DayOfMonth[2] = 31;\r
906 DayOfMonth[3] = 30;\r
907 DayOfMonth[4] = 31;\r
908 DayOfMonth[5] = 30;\r
909 DayOfMonth[6] = 31;\r
910 DayOfMonth[7] = 31;\r
911 DayOfMonth[8] = 30;\r
912 DayOfMonth[9] = 31;\r
913 DayOfMonth[10] = 30;\r
914 DayOfMonth[11] = 31;\r
8cd4d17c 915\r
96a5ac5b 916 //\r
917 // The validity of Time->Month field should be checked before\r
918 //\r
919 ASSERT (Time->Month >=1);\r
920 ASSERT (Time->Month <=12);\r
8cd4d17c 921 if (Time->Day < 1 ||\r
922 Time->Day > DayOfMonth[Time->Month - 1] ||\r
923 (Time->Month == 2 && (!IsLeapYear (Time) && Time->Day > 28))\r
924 ) {\r
925 return FALSE;\r
926 }\r
927\r
928 return TRUE;\r
929}\r
930\r
8d85dc31 931/**\r
2d4117c0 932 Check if it is a leap year.\r
8d85dc31 933\r
934 @param Time The time to be checked.\r
935\r
2d4117c0 936 @retval TRUE It is a leap year.\r
937 @retval FALSE It is NOT a leap year.\r
8d85dc31 938**/\r
8cd4d17c 939BOOLEAN\r
940IsLeapYear (\r
941 IN EFI_TIME *Time\r
942 )\r
8cd4d17c 943{\r
944 if (Time->Year % 4 == 0) {\r
945 if (Time->Year % 100 == 0) {\r
946 if (Time->Year % 400 == 0) {\r
947 return TRUE;\r
948 } else {\r
949 return FALSE;\r
950 }\r
951 } else {\r
952 return TRUE;\r
953 }\r
954 } else {\r
955 return FALSE;\r
956 }\r
957}\r
958\r
8d85dc31 959/**\r
960 Converts time from EFI_TIME format defined by UEFI spec to RTC's.\r
8cd4d17c 961\r
8d85dc31 962 This function converts time from EFI_TIME format defined by UEFI spec to RTC's.\r
963 If data mode of RTC is BCD, then converts EFI_TIME to it.\r
964 If RTC is in 12-hour format, then converts EFI_TIME to it.\r
8cd4d17c 965\r
8d85dc31 966 @param Time On input, the time data read from UEFI to convert\r
967 On output, the time converted to RTC format\r
968 @param RegisterB Value of Register B of RTC, indicating data mode\r
969 @param Century It is set according to EFI_TIME Time.\r
8cd4d17c 970\r
8d85dc31 971**/\r
972VOID\r
973ConvertEfiTimeToRtcTime (\r
974 IN OUT EFI_TIME *Time,\r
975 IN RTC_REGISTER_B RegisterB,\r
976 OUT UINT8 *Century\r
977 )\r
8cd4d17c 978{\r
8d85dc31 979 BOOLEAN IsPM;\r
8cd4d17c 980\r
8d85dc31 981 IsPM = TRUE;\r
8cd4d17c 982 //\r
8d85dc31 983 // Adjust hour field if RTC is in 12 hour mode\r
8cd4d17c 984 //\r
24115e44 985 if (RegisterB.Bits.Mil == 0) {\r
8cd4d17c 986 if (Time->Hour < 12) {\r
8d85dc31 987 IsPM = FALSE;\r
8cd4d17c 988 }\r
989\r
990 if (Time->Hour >= 13) {\r
991 Time->Hour = (UINT8) (Time->Hour - 12);\r
992 } else if (Time->Hour == 0) {\r
993 Time->Hour = 12;\r
994 }\r
995 }\r
996 //\r
997 // Set the Time/Date/Daylight Savings values.\r
998 //\r
999 *Century = DecimalToBcd8 ((UINT8) (Time->Year / 100));\r
1000\r
1001 Time->Year = (UINT16) (Time->Year % 100);\r
1002\r
24115e44 1003 if (RegisterB.Bits.Dm == 0) {\r
8cd4d17c 1004 Time->Year = DecimalToBcd8 ((UINT8) Time->Year);\r
1005 Time->Month = DecimalToBcd8 (Time->Month);\r
1006 Time->Day = DecimalToBcd8 (Time->Day);\r
1007 Time->Hour = DecimalToBcd8 (Time->Hour);\r
1008 Time->Minute = DecimalToBcd8 (Time->Minute);\r
1009 Time->Second = DecimalToBcd8 (Time->Second);\r
1010 }\r
1011 //\r
1012 // If we are in 12 hour mode and PM is set, then set bit 7 of the Hour field.\r
1013 //\r
24115e44 1014 if (RegisterB.Bits.Mil == 0 && IsPM) {\r
8cd4d17c 1015 Time->Hour = (UINT8) (Time->Hour | 0x80);\r
1016 }\r
1017}\r
1018\r
8d85dc31 1019/**\r
1020 Compare the Hour, Minute and Second of the From time and the To time.\r
1021 \r
1022 Only compare H/M/S in EFI_TIME and ignore other fields here.\r
1023\r
1024 @param From the first time\r
1025 @param To the second time\r
1026\r
1027 @return >0 The H/M/S of the From time is later than those of To time\r
1028 @return ==0 The H/M/S of the From time is same as those of To time\r
1029 @return <0 The H/M/S of the From time is earlier than those of To time\r
1030**/\r
8cd4d17c 1031INTN\r
1032CompareHMS (\r
1033 IN EFI_TIME *From,\r
1034 IN EFI_TIME *To\r
1035 )\r
8cd4d17c 1036{\r
1037 if ((From->Hour > To->Hour) ||\r
1038 ((From->Hour == To->Hour) && (From->Minute > To->Minute)) ||\r
1039 ((From->Hour == To->Hour) && (From->Minute == To->Minute) && (From->Second > To->Second))) {\r
1040 return 1;\r
1041 } else if ((From->Hour == To->Hour) && (From->Minute == To->Minute) && (From->Second == To->Second)) {\r
1042 return 0;\r
1043 } else {\r
1044 return -1;\r
1045 }\r
1046}\r
1047\r
8d85dc31 1048/**\r
1049 To check if second date is later than first date within 24 hours.\r
1050\r
1051 @param From the first date\r
1052 @param To the second date\r
1053\r
1054 @retval TRUE From is previous to To within 24 hours.\r
1055 @retval FALSE From is later, or it is previous to To more than 24 hours.\r
1056**/\r
8cd4d17c 1057BOOLEAN\r
1058IsWithinOneDay (\r
1059 IN EFI_TIME *From,\r
1060 IN EFI_TIME *To\r
1061 )\r
8cd4d17c 1062{\r
558bfebb 1063 UINT8 DayOfMonth[12];\r
1f4cf7b1 1064 BOOLEAN Adjacent;\r
1065\r
558bfebb 1066 DayOfMonth[0] = 31;\r
1067 DayOfMonth[1] = 29;\r
1068 DayOfMonth[2] = 31;\r
1069 DayOfMonth[3] = 30;\r
1070 DayOfMonth[4] = 31;\r
1071 DayOfMonth[5] = 30;\r
1072 DayOfMonth[6] = 31;\r
1073 DayOfMonth[7] = 31;\r
1074 DayOfMonth[8] = 30;\r
1075 DayOfMonth[9] = 31;\r
1076 DayOfMonth[10] = 30;\r
1077 DayOfMonth[11] = 31;\r
1078\r
1f4cf7b1 1079 Adjacent = FALSE;\r
8cd4d17c 1080\r
96a5ac5b 1081 //\r
4cfc3293 1082 // The validity of From->Month field should be checked before\r
96a5ac5b 1083 //\r
1084 ASSERT (From->Month >=1);\r
1085 ASSERT (From->Month <=12);\r
1086 \r
8cd4d17c 1087 if (From->Year == To->Year) {\r
1088 if (From->Month == To->Month) {\r
1089 if ((From->Day + 1) == To->Day) {\r
1090 if ((CompareHMS(From, To) >= 0)) {\r
1091 Adjacent = TRUE;\r
1092 }\r
1093 } else if (From->Day == To->Day) {\r
1094 if ((CompareHMS(From, To) <= 0)) {\r
1095 Adjacent = TRUE;\r
1096 }\r
1097 }\r
1098 } else if (((From->Month + 1) == To->Month) && (To->Day == 1)) {\r
1099 if ((From->Month == 2) && !IsLeapYear(From)) {\r
1100 if (From->Day == 28) {\r
1101 if ((CompareHMS(From, To) >= 0)) {\r
1102 Adjacent = TRUE;\r
1103 }\r
1104 }\r
1105 } else if (From->Day == DayOfMonth[From->Month - 1]) {\r
1106 if ((CompareHMS(From, To) >= 0)) {\r
1107 Adjacent = TRUE;\r
1108 }\r
1109 }\r
1110 }\r
1111 } else if (((From->Year + 1) == To->Year) &&\r
1112 (From->Month == 12) &&\r
1113 (From->Day == 31) &&\r
1114 (To->Month == 1) &&\r
1115 (To->Day == 1)) {\r
1116 if ((CompareHMS(From, To) >= 0)) {\r
1117 Adjacent = TRUE;\r
1118 }\r
1119 }\r
1120\r
1121 return Adjacent;\r
1122}\r
1123\r