2 RTC Architectural Protocol GUID as defined in DxeCis 0.96.
4 Copyright (c) 2006 - 2007, Intel Corporation
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
37 GC_TODO: Add function description
41 Address - GC_TODO: add argument description
45 GC_TODO: add return values
49 IoWrite8 (PCAT_RTC_ADDRESS_REGISTER
, (UINT8
) (Address
| (UINT8
) (IoRead8 (PCAT_RTC_ADDRESS_REGISTER
) & 0x80)));
50 return IoRead8 (PCAT_RTC_DATA_REGISTER
);
62 GC_TODO: Add function description
66 Address - GC_TODO: add argument description
67 Data - GC_TODO: add argument description
71 GC_TODO: add return values
75 IoWrite8 (PCAT_RTC_ADDRESS_REGISTER
, (UINT8
) (Address
| (UINT8
) (IoRead8 (PCAT_RTC_ADDRESS_REGISTER
) & 0x80)));
76 IoWrite8 (PCAT_RTC_DATA_REGISTER
, Data
);
81 IN PC_RTC_MODULE_GLOBALS
*Global
87 GC_TODO: Add function description
91 Global - GC_TODO: add argument description
95 EFI_DEVICE_ERROR - GC_TODO: Add description for return value
96 EFI_SUCCESS - GC_TODO: Add description for return value
101 RTC_REGISTER_A RegisterA
;
102 RTC_REGISTER_B RegisterB
;
103 RTC_REGISTER_D RegisterD
;
110 // Acquire RTC Lock to make access to RTC atomic
112 //BugBug: the EfiAtRuntime should be encapsulated in EfiAcquireLock or
113 // provide a new instance for EfiAcquireLock, say, RtEfiAcquireLock
114 if (!EfiAtRuntime ()) {
115 EfiAcquireLock (&Global
->RtcLock
);
118 // Initialize RTC Register
120 // Make sure Division Chain is properly configured,
121 // or RTC clock won't "tick" -- time won't increment
123 RegisterA
.Data
= RTC_INIT_REGISTER_A
;
124 RtcWrite (RTC_ADDRESS_REGISTER_A
, RegisterA
.Data
);
129 RegisterB
.Data
= RtcRead (RTC_ADDRESS_REGISTER_B
);
132 // Clear RTC flag register
134 RtcRead (RTC_ADDRESS_REGISTER_C
);
137 // Clear RTC register D
139 RegisterD
.Data
= RTC_INIT_REGISTER_D
;
140 RtcWrite (RTC_ADDRESS_REGISTER_D
, RegisterD
.Data
);
143 // Wait for up to 0.1 seconds for the RTC to be updated
145 Status
= RtcWaitToUpdate (PcdGet32 (PcdRealTimeClockUpdateTimeout
));
146 if (EFI_ERROR (Status
)) {
147 //BugBug: the EfiAtRuntime should be encapsulated in EfiAcquireLock or
148 // provide a new instance for EfiAcquireLock, say, RtEfiAcquireLock
149 if (!EfiAtRuntime ()) {
150 EfiReleaseLock (&Global
->RtcLock
);
152 return EFI_DEVICE_ERROR
;
155 // Get the Time/Date/Daylight Savings values.
157 Time
.Second
= RtcRead (RTC_ADDRESS_SECONDS
);
158 Time
.Minute
= RtcRead (RTC_ADDRESS_MINUTES
);
159 Time
.Hour
= RtcRead (RTC_ADDRESS_HOURS
);
160 Time
.Day
= RtcRead (RTC_ADDRESS_DAY_OF_THE_MONTH
);
161 Time
.Month
= RtcRead (RTC_ADDRESS_MONTH
);
162 Time
.Year
= RtcRead (RTC_ADDRESS_YEAR
);
164 if (RtcTestCenturyRegister () == EFI_SUCCESS
) {
165 Century
= (UINT8
) (RtcRead (RTC_ADDRESS_CENTURY
) & 0x7f);
167 Century
= RtcRead (RTC_ADDRESS_CENTURY
);
171 // Set RTC configuration after get original time
172 // The value of bit AIE should be reserved.
174 RtcWrite (RTC_ADDRESS_REGISTER_B
, (UINT8
)(RTC_INIT_REGISTER_B
| (RegisterB
.Data
& BIT5
)));
179 //BugBug: the EfiAtRuntime should be encapsulated in EfiAcquireLock or
180 // provide a new instance for EfiAcquireLock, say, RtEfiAcquireLock
182 if (!EfiAtRuntime ()) {
183 EfiReleaseLock (&Global
->RtcLock
);
187 // Validate time fields
189 Status
= ConvertRtcTimeToEfiTime (&Time
, Century
, RegisterB
);
190 if (!EFI_ERROR (Status
)) {
191 Status
= RtcTimeFieldsValid (&Time
);
193 if (EFI_ERROR (Status
)) {
194 Time
.Second
= RTC_INIT_SECOND
;
195 Time
.Minute
= RTC_INIT_MINUTE
;
196 Time
.Hour
= RTC_INIT_HOUR
;
197 Time
.Day
= RTC_INIT_DAY
;
198 Time
.Month
= RTC_INIT_MONTH
;
199 Time
.Year
= RTC_INIT_YEAR
;
202 // Get the data of Daylight saving and time zone, if they have been
203 // stored in NV variable during previous boot.
205 DataSize
= sizeof (UINT32
);
206 Status
= EfiGetVariable (
208 &gEfiGenericPlatformVariableGuid
,
213 if (!EFI_ERROR (Status
)) {
214 Global
->SavedTimeZone
= (INT16
) TimerVar
;
215 Global
->Daylight
= (UINT8
) (TimerVar
>> 16);
217 Time
.TimeZone
= Global
->SavedTimeZone
;
218 Time
.Daylight
= Global
->Daylight
;
221 // Reset time value according to new RTC configuration
223 PcRtcSetTime (&Time
, Global
);
231 IN EFI_TIME_CAPABILITIES
*Capabilities
,
232 IN PC_RTC_MODULE_GLOBALS
*Global
242 // GC_TODO: Time - add argument and description to function comment
243 // GC_TODO: Capabilities - add argument and description to function comment
244 // GC_TODO: Global - add argument and description to function comment
245 // GC_TODO: EFI_INVALID_PARAMETER - add return value to function comment
246 // GC_TODO: EFI_DEVICE_ERROR - add return value to function comment
247 // GC_TODO: EFI_SUCCESS - add return value to function comment
250 RTC_REGISTER_B RegisterB
;
254 // Check parameters for null pointer
257 return EFI_INVALID_PARAMETER
;
261 // Acquire RTC Lock to make access to RTC atomic
263 //BugBug: the EfiAtRuntime should be encapsulated in EfiAcquireLock or
264 // provide a new instance for EfiAcquireLock, say, RtEfiAcquireLock
265 if (!EfiAtRuntime ()) {
266 EfiAcquireLock (&Global
->RtcLock
);
269 // Wait for up to 0.1 seconds for the RTC to be updated
271 Status
= RtcWaitToUpdate (PcdGet32 (PcdRealTimeClockUpdateTimeout
));
272 if (EFI_ERROR (Status
)) {
273 //BugBug: the EfiAtRuntime should be encapsulated in EfiReleaseLock or
274 // provide a new instance for EfiReleaseLock, say, RtEfiReleaseLock
275 if (!EfiAtRuntime ()) {
276 EfiReleaseLock (&Global
->RtcLock
);
283 RegisterB
.Data
= RtcRead (RTC_ADDRESS_REGISTER_B
);
286 // Get the Time/Date/Daylight Savings values.
288 Time
->Second
= RtcRead (RTC_ADDRESS_SECONDS
);
289 Time
->Minute
= RtcRead (RTC_ADDRESS_MINUTES
);
290 Time
->Hour
= RtcRead (RTC_ADDRESS_HOURS
);
291 Time
->Day
= RtcRead (RTC_ADDRESS_DAY_OF_THE_MONTH
);
292 Time
->Month
= RtcRead (RTC_ADDRESS_MONTH
);
293 Time
->Year
= RtcRead (RTC_ADDRESS_YEAR
);
295 if (RtcTestCenturyRegister () == EFI_SUCCESS
) {
296 Century
= (UINT8
) (RtcRead (RTC_ADDRESS_CENTURY
) & 0x7f);
298 Century
= RtcRead (RTC_ADDRESS_CENTURY
);
304 //BugBug: the EfiAtRuntime should be encapsulated in EfiReleaseLock or
305 // provide a new instance for EfiReleaseLock, say, RtEfiReleaseLock
306 if (!EfiAtRuntime ()) {
307 EfiReleaseLock (&Global
->RtcLock
);
310 // Get the variable that containts the TimeZone and Daylight fields
312 Time
->TimeZone
= Global
->SavedTimeZone
;
313 Time
->Daylight
= Global
->Daylight
;
316 // Make sure all field values are in correct range
318 Status
= ConvertRtcTimeToEfiTime (Time
, Century
, RegisterB
);
319 if (!EFI_ERROR (Status
)) {
320 Status
= RtcTimeFieldsValid (Time
);
322 if (EFI_ERROR (Status
)) {
323 return EFI_DEVICE_ERROR
;
326 // Fill in Capabilities if it was passed in
329 Capabilities
->Resolution
= 1;
333 Capabilities
->Accuracy
= 50000000;
337 Capabilities
->SetsToZero
= FALSE
;
346 IN PC_RTC_MODULE_GLOBALS
*Global
356 // GC_TODO: Time - add argument and description to function comment
357 // GC_TODO: Global - add argument and description to function comment
358 // GC_TODO: EFI_INVALID_PARAMETER - add return value to function comment
362 RTC_REGISTER_B RegisterB
;
367 return EFI_INVALID_PARAMETER
;
370 // Make sure that the time fields are valid
372 Status
= RtcTimeFieldsValid (Time
);
373 if (EFI_ERROR (Status
)) {
377 CopyMem (&RtcTime
, Time
, sizeof (EFI_TIME
));
380 // Acquire RTC Lock to make access to RTC atomic
382 //BugBug: the EfiAtRuntime should be encapsulated in EfiAcquireLock or
383 // provide a new instance for EfiAcquireLock, say, RtEfiAcquireLock
384 if (!EfiAtRuntime ()) {
385 EfiAcquireLock (&Global
->RtcLock
);
388 // Wait for up to 0.1 seconds for the RTC to be updated
390 Status
= RtcWaitToUpdate (PcdGet32 (PcdRealTimeClockUpdateTimeout
));
391 if (EFI_ERROR (Status
)) {
392 //BugBug: the EfiAtRuntime should be encapsulated in EfiReleaseLock or
393 // provide a new instance for EfiReleaseLock, say, RtEfiReleaseLock
394 if (!EfiAtRuntime ()) {
395 EfiReleaseLock (&Global
->RtcLock
);
400 // Read Register B, and inhibit updates of the RTC
402 RegisterB
.Data
= RtcRead (RTC_ADDRESS_REGISTER_B
);
403 RegisterB
.Bits
.SET
= 1;
404 RtcWrite (RTC_ADDRESS_REGISTER_B
, RegisterB
.Data
);
406 ConvertEfiTimeToRtcTime (&RtcTime
, RegisterB
, &Century
);
408 RtcWrite (RTC_ADDRESS_SECONDS
, RtcTime
.Second
);
409 RtcWrite (RTC_ADDRESS_MINUTES
, RtcTime
.Minute
);
410 RtcWrite (RTC_ADDRESS_HOURS
, RtcTime
.Hour
);
411 RtcWrite (RTC_ADDRESS_DAY_OF_THE_MONTH
, RtcTime
.Day
);
412 RtcWrite (RTC_ADDRESS_MONTH
, RtcTime
.Month
);
413 RtcWrite (RTC_ADDRESS_YEAR
, (UINT8
) RtcTime
.Year
);
414 if (RtcTestCenturyRegister () == EFI_SUCCESS
) {
415 Century
= (UINT8
) ((Century
& 0x7f) | (RtcRead (RTC_ADDRESS_CENTURY
) & 0x80));
418 RtcWrite (RTC_ADDRESS_CENTURY
, Century
);
421 // Allow updates of the RTC registers
423 RegisterB
.Bits
.SET
= 0;
424 RtcWrite (RTC_ADDRESS_REGISTER_B
, RegisterB
.Data
);
429 //BugBug: the EfiAtRuntime should be encapsulated in EfiReleaseLock or
430 // provide a new instance for EfiReleaseLock, say, RtEfiReleaseLock
431 if (!EfiAtRuntime ()) {
432 EfiReleaseLock (&Global
->RtcLock
);
435 // Set the variable that containts the TimeZone and Daylight fields
437 Global
->SavedTimeZone
= Time
->TimeZone
;
438 Global
->Daylight
= Time
->Daylight
;
440 TimerVar
= Time
->Daylight
;
441 TimerVar
= (UINT32
) ((TimerVar
<< 16) | Time
->TimeZone
);
442 Status
= EfiSetVariable (
444 &gEfiGenericPlatformVariableGuid
,
445 EFI_VARIABLE_BOOTSERVICE_ACCESS
| EFI_VARIABLE_RUNTIME_ACCESS
| EFI_VARIABLE_NON_VOLATILE
,
449 ASSERT_EFI_ERROR (Status
);
456 OUT BOOLEAN
*Enabled
,
457 OUT BOOLEAN
*Pending
,
459 IN PC_RTC_MODULE_GLOBALS
*Global
471 // GC_TODO: Enabled - add argument and description to function comment
472 // GC_TODO: Pending - add argument and description to function comment
473 // GC_TODO: Time - add argument and description to function comment
474 // GC_TODO: Global - add argument and description to function comment
475 // GC_TODO: EFI_INVALID_PARAMETER - add return value to function comment
476 // GC_TODO: EFI_DEVICE_ERROR - add return value to function comment
477 // GC_TODO: EFI_DEVICE_ERROR - add return value to function comment
478 // GC_TODO: EFI_SUCCESS - add return value to function comment
481 RTC_REGISTER_B RegisterB
;
482 RTC_REGISTER_C RegisterC
;
486 // Check paramters for null pointers
488 if ((Enabled
== NULL
) || (Pending
== NULL
) || (Time
== NULL
)) {
489 return EFI_INVALID_PARAMETER
;
493 // Acquire RTC Lock to make access to RTC atomic
495 //BugBug: the EfiAtRuntime should be encapsulated in EfiAcquireLock or
496 // provide a new instance for EfiAcquireLock, say, RtEfiAcquireLock
497 if (!EfiAtRuntime ()) {
498 EfiAcquireLock (&Global
->RtcLock
);
501 // Wait for up to 0.1 seconds for the RTC to be updated
503 Status
= RtcWaitToUpdate (PcdGet32 (PcdRealTimeClockUpdateTimeout
));
504 if (EFI_ERROR (Status
)) {
505 //BugBug: the EfiAtRuntime should be encapsulated in EfiReleaseLock or
506 // provide a new instance for EfiReleaseLock, say, RtEfiReleaseLock
507 if (!EfiAtRuntime ()) {
508 EfiReleaseLock (&Global
->RtcLock
);
510 return EFI_DEVICE_ERROR
;
513 // Read Register B and Register C
515 RegisterB
.Data
= RtcRead (RTC_ADDRESS_REGISTER_B
);
516 RegisterC
.Data
= RtcRead (RTC_ADDRESS_REGISTER_C
);
519 // Get the Time/Date/Daylight Savings values.
521 *Enabled
= RegisterB
.Bits
.AIE
;
523 Time
->Second
= RtcRead (RTC_ADDRESS_SECONDS_ALARM
);
524 Time
->Minute
= RtcRead (RTC_ADDRESS_MINUTES_ALARM
);
525 Time
->Hour
= RtcRead (RTC_ADDRESS_HOURS_ALARM
);
526 Time
->Day
= RtcRead (RTC_ADDRESS_DAY_OF_THE_MONTH
);
527 Time
->Month
= RtcRead (RTC_ADDRESS_MONTH
);
528 Time
->Year
= RtcRead (RTC_ADDRESS_YEAR
);
533 Time
->Day
= RtcRead (RTC_ADDRESS_DAY_OF_THE_MONTH
);
534 Time
->Month
= RtcRead (RTC_ADDRESS_MONTH
);
535 Time
->Year
= RtcRead (RTC_ADDRESS_YEAR
);
538 if (RtcTestCenturyRegister () == EFI_SUCCESS
) {
539 Century
= (UINT8
) (RtcRead (RTC_ADDRESS_CENTURY
) & 0x7f);
541 Century
= RtcRead (RTC_ADDRESS_CENTURY
);
547 //BugBug: the EfiAtRuntime should be encapsulated in EfiReleaseLock or
548 // provide a new instance for EfiReleaseLock, say, RtEfiReleaseLock
549 if (!EfiAtRuntime ()) {
550 EfiReleaseLock (&Global
->RtcLock
);
553 // Make sure all field values are in correct range
555 Status
= ConvertRtcTimeToEfiTime (Time
, Century
, RegisterB
);
556 if (!EFI_ERROR (Status
)) {
557 Status
= RtcTimeFieldsValid (Time
);
559 if (EFI_ERROR (Status
)) {
560 return EFI_DEVICE_ERROR
;
563 *Pending
= RegisterC
.Bits
.AF
;
572 IN PC_RTC_MODULE_GLOBALS
*Global
584 // GC_TODO: Enable - add argument and description to function comment
585 // GC_TODO: Time - add argument and description to function comment
586 // GC_TODO: Global - add argument and description to function comment
587 // GC_TODO: EFI_INVALID_PARAMETER - add return value to function comment
588 // GC_TODO: EFI_INVALID_PARAMETER - add return value to function comment
589 // GC_TODO: EFI_UNSUPPORTED - add return value to function comment
590 // GC_TODO: EFI_DEVICE_ERROR - add return value to function comment
591 // GC_TODO: EFI_SUCCESS - add return value to function comment
595 RTC_REGISTER_B RegisterB
;
597 EFI_TIME_CAPABILITIES Capabilities
;
602 return EFI_INVALID_PARAMETER
;
605 // Make sure that the time fields are valid
607 Status
= RtcTimeFieldsValid (Time
);
608 if (EFI_ERROR (Status
)) {
609 return EFI_INVALID_PARAMETER
;
612 // Just support set alarm time within 24 hours
614 PcRtcGetTime (&RtcTime
, &Capabilities
, Global
);
615 if (!IsWithinOneDay (&RtcTime
, Time
)) {
616 return EFI_UNSUPPORTED
;
619 // Make a local copy of the time and date
621 CopyMem (&RtcTime
, Time
, sizeof (EFI_TIME
));
625 // Acquire RTC Lock to make access to RTC atomic
627 //BugBug: the EfiAtRuntime should be encapsulated in EfiAcquireLock or
628 // provide a new instance for EfiAcquireLock, say, RtEfiAcquireLock
629 if (!EfiAtRuntime ()) {
630 EfiAcquireLock (&Global
->RtcLock
);
633 // Wait for up to 0.1 seconds for the RTC to be updated
635 Status
= RtcWaitToUpdate (PcdGet32 (PcdRealTimeClockUpdateTimeout
));
636 if (EFI_ERROR (Status
)) {
637 //BugBug: the EfiAtRuntime should be encapsulated in EfiReleaseLock or
638 // provide a new instance for EfiReleaseLock, say, RtEfiReleaseLock
639 if (!EfiAtRuntime ()) {
640 EfiReleaseLock (&Global
->RtcLock
);
642 return EFI_DEVICE_ERROR
;
645 // Read Register B, and inhibit updates of the RTC
647 RegisterB
.Data
= RtcRead (RTC_ADDRESS_REGISTER_B
);
649 RegisterB
.Bits
.SET
= 1;
650 RtcWrite (RTC_ADDRESS_REGISTER_B
, RegisterB
.Data
);
653 ConvertEfiTimeToRtcTime (&RtcTime
, RegisterB
, &Century
);
656 // Set RTC alarm time
658 RtcWrite (RTC_ADDRESS_SECONDS_ALARM
, RtcTime
.Second
);
659 RtcWrite (RTC_ADDRESS_MINUTES_ALARM
, RtcTime
.Minute
);
660 RtcWrite (RTC_ADDRESS_HOURS_ALARM
, RtcTime
.Hour
);
662 RegisterB
.Bits
.AIE
= 1;
665 RegisterB
.Bits
.AIE
= 0;
668 // Allow updates of the RTC registers
670 RegisterB
.Bits
.SET
= 0;
671 RtcWrite (RTC_ADDRESS_REGISTER_B
, RegisterB
.Data
);
676 //BugBug: the EfiAtRuntime should be encapsulated in EfiReleaseLock or
677 // provide a new instance for EfiReleaseLock, say, RtEfiReleaseLock
678 if (!EfiAtRuntime ()) {
679 EfiReleaseLock (&Global
->RtcLock
);
685 RtcTestCenturyRegister (
698 // GC_TODO: EFI_SUCCESS - add return value to function comment
699 // GC_TODO: EFI_DEVICE_ERROR - add return value to function comment
704 Century
= RtcRead (RTC_ADDRESS_CENTURY
);
706 // RtcWrite (RTC_ADDRESS_CENTURY, 0x00);
708 Temp
= (UINT8
) (RtcRead (RTC_ADDRESS_CENTURY
) & 0x7f);
709 RtcWrite (RTC_ADDRESS_CENTURY
, Century
);
710 if (Temp
== 0x19 || Temp
== 0x20) {
714 return EFI_DEVICE_ERROR
;
718 Checks an 8-bit BCD value, and converts to an 8-bit value if valid.
720 This function checks the 8-bit BCD value specified by Value.
721 If valid, the function converts it to an 8-bit value and returns it.
722 Otherwise, return 0xff.
724 @param Value The 8-bit BCD value to check and convert
726 @return The 8-bit value converted.
727 0xff if Value is invalid.
731 CheckAndConvertBcd8ToDecimal8 (
735 if ((Value
< 0xa0) && ((Value
& 0xf) < 0xa)) {
736 return BcdToDecimal8 (Value
);
743 Converts time read from RTC to EFI_TIME format defined by UEFI spec.
745 This function converts raw time data read from RTC to the EFI_TIME format
746 defined by UEFI spec.
747 If data mode of RTC is BCD, then converts it to decimal,
748 If RTC is in 12-hour format, then converts it to 24-hour format.
750 @param Time On input, the time data read from RTC to convert
751 On output, the time converted to UEFI format
752 @param Century Value of century read from RTC.
753 @param RegisterB Value of Register B of RTC, indicating data mode
758 ConvertRtcTimeToEfiTime (
759 IN OUT EFI_TIME
*Time
,
761 IN RTC_REGISTER_B RegisterB
766 if ((Time
->Hour
) & 0x80) {
772 Time
->Hour
= (UINT8
) (Time
->Hour
& 0x7f);
774 if (RegisterB
.Bits
.DM
== 0) {
775 Time
->Year
= CheckAndConvertBcd8ToDecimal8 ((UINT8
) Time
->Year
);
776 Time
->Month
= CheckAndConvertBcd8ToDecimal8 (Time
->Month
);
777 Time
->Day
= CheckAndConvertBcd8ToDecimal8 (Time
->Day
);
778 Time
->Hour
= CheckAndConvertBcd8ToDecimal8 (Time
->Hour
);
779 Time
->Minute
= CheckAndConvertBcd8ToDecimal8 (Time
->Minute
);
780 Time
->Second
= CheckAndConvertBcd8ToDecimal8 (Time
->Second
);
781 Century
= CheckAndConvertBcd8ToDecimal8 (Century
);
784 if (Time
->Year
== 0xff || Time
->Month
== 0xff || Time
->Day
== 0xff ||
785 Time
->Hour
== 0xff || Time
->Minute
== 0xff || Time
->Second
== 0xff ||
787 return EFI_INVALID_PARAMETER
;
790 Time
->Year
= (UINT16
) (Century
* 100 + Time
->Year
);
793 // If time is in 12 hour format, convert it to 24 hour format
795 if (RegisterB
.Bits
.MIL
== 0) {
796 if (PM
&& Time
->Hour
< 12) {
797 Time
->Hour
= (UINT8
) (Time
->Hour
+ 12);
800 if (!PM
&& Time
->Hour
== 12) {
805 Time
->Nanosecond
= 0;
806 Time
->TimeZone
= EFI_UNSPECIFIED_TIMEZONE
;
825 // GC_TODO: Timeout - add argument and description to function comment
826 // GC_TODO: EFI_DEVICE_ERROR - add return value to function comment
827 // GC_TODO: EFI_DEVICE_ERROR - add return value to function comment
828 // GC_TODO: EFI_SUCCESS - add return value to function comment
830 RTC_REGISTER_A RegisterA
;
831 RTC_REGISTER_D RegisterD
;
834 // See if the RTC is functioning correctly
836 RegisterD
.Data
= RtcRead (RTC_ADDRESS_REGISTER_D
);
838 if (RegisterD
.Bits
.VRT
== 0) {
839 return EFI_DEVICE_ERROR
;
842 // Wait for up to 0.1 seconds for the RTC to be ready.
844 Timeout
= (Timeout
/ 10) + 1;
845 RegisterA
.Data
= RtcRead (RTC_ADDRESS_REGISTER_A
);
846 while (RegisterA
.Bits
.UIP
== 1 && Timeout
> 0) {
847 MicroSecondDelay (10);
848 RegisterA
.Data
= RtcRead (RTC_ADDRESS_REGISTER_A
);
852 RegisterD
.Data
= RtcRead (RTC_ADDRESS_REGISTER_D
);
853 if (Timeout
== 0 || RegisterD
.Bits
.VRT
== 0) {
854 return EFI_DEVICE_ERROR
;
872 // GC_TODO: Time - add argument and description to function comment
873 // GC_TODO: EFI_INVALID_PARAMETER - add return value to function comment
874 // GC_TODO: EFI_SUCCESS - add return value to function comment
876 if (Time
->Year
< 1998 ||
880 (!DayValid (Time
)) ||
884 Time
->Nanosecond
> 999999999 ||
885 (!(Time
->TimeZone
== EFI_UNSPECIFIED_TIMEZONE
|| (Time
->TimeZone
>= -1440 && Time
->TimeZone
<= 1440))) ||
886 (Time
->Daylight
& (~(EFI_TIME_ADJUST_DAYLIGHT
| EFI_TIME_IN_DAYLIGHT
)))
888 return EFI_INVALID_PARAMETER
;
902 GC_TODO: Add function description
906 Time - GC_TODO: add argument description
910 GC_TODO: add return values
930 Time
->Day
> DayOfMonth
[Time
->Month
- 1] ||
931 (Time
->Month
== 2 && (!IsLeapYear (Time
) && Time
->Day
> 28))
947 GC_TODO: Add function description
951 Time - GC_TODO: add argument description
955 GC_TODO: add return values
959 if (Time
->Year
% 4 == 0) {
960 if (Time
->Year
% 100 == 0) {
961 if (Time
->Year
% 400 == 0) {
975 ConvertEfiTimeToRtcTime (
977 IN RTC_REGISTER_B RegisterB
,
989 // GC_TODO: Time - add argument and description to function comment
990 // GC_TODO: RegisterB - add argument and description to function comment
991 // GC_TODO: Century - add argument and description to function comment
997 // Adjust hour field if RTC in in 12 hour mode
999 if (RegisterB
.Bits
.MIL
== 0) {
1000 if (Time
->Hour
< 12) {
1004 if (Time
->Hour
>= 13) {
1005 Time
->Hour
= (UINT8
) (Time
->Hour
- 12);
1006 } else if (Time
->Hour
== 0) {
1011 // Set the Time/Date/Daylight Savings values.
1013 *Century
= DecimalToBcd8 ((UINT8
) (Time
->Year
/ 100));
1015 Time
->Year
= (UINT16
) (Time
->Year
% 100);
1017 if (RegisterB
.Bits
.DM
== 0) {
1018 Time
->Year
= DecimalToBcd8 ((UINT8
) Time
->Year
);
1019 Time
->Month
= DecimalToBcd8 (Time
->Month
);
1020 Time
->Day
= DecimalToBcd8 (Time
->Day
);
1021 Time
->Hour
= DecimalToBcd8 (Time
->Hour
);
1022 Time
->Minute
= DecimalToBcd8 (Time
->Minute
);
1023 Time
->Second
= DecimalToBcd8 (Time
->Second
);
1026 // If we are in 12 hour mode and PM is set, then set bit 7 of the Hour field.
1028 if (RegisterB
.Bits
.MIL
== 0 && PM
) {
1029 Time
->Hour
= (UINT8
) (Time
->Hour
| 0x80);
1040 Routine Description:
1042 Compare the Hour, Minute and Second of the 'From' time and the 'To' time.
1043 Only compare H/M/S in EFI_TIME and ignore other fields here.
1047 From - the first time
1048 To - the second time
1052 >0 : The H/M/S of the 'From' time is later than those of 'To' time
1053 ==0 : The H/M/S of the 'From' time is same as those of 'To' time
1054 <0 : The H/M/S of the 'From' time is earlier than those of 'To' time
1058 if ((From
->Hour
> To
->Hour
) ||
1059 ((From
->Hour
== To
->Hour
) && (From
->Minute
> To
->Minute
)) ||
1060 ((From
->Hour
== To
->Hour
) && (From
->Minute
== To
->Minute
) && (From
->Second
> To
->Second
))) {
1062 } else if ((From
->Hour
== To
->Hour
) && (From
->Minute
== To
->Minute
) && (From
->Second
== To
->Second
)) {
1076 Routine Description:
1078 Judge whether two days are adjacent.
1082 From - the first day
1087 TRUE - The interval of two days are within one day.
1088 FALSE - The interval of two days exceed ony day or parameter error.
1092 UINT8 DayOfMonth
[12];
1105 DayOfMonth
[10] = 30;
1106 DayOfMonth
[11] = 31;
1110 if (From
->Year
== To
->Year
) {
1111 if (From
->Month
== To
->Month
) {
1112 if ((From
->Day
+ 1) == To
->Day
) {
1113 if ((CompareHMS(From
, To
) >= 0)) {
1116 } else if (From
->Day
== To
->Day
) {
1117 if ((CompareHMS(From
, To
) <= 0)) {
1121 } else if (((From
->Month
+ 1) == To
->Month
) && (To
->Day
== 1)) {
1122 if ((From
->Month
== 2) && !IsLeapYear(From
)) {
1123 if (From
->Day
== 28) {
1124 if ((CompareHMS(From
, To
) >= 0)) {
1128 } else if (From
->Day
== DayOfMonth
[From
->Month
- 1]) {
1129 if ((CompareHMS(From
, To
) >= 0)) {
1134 } else if (((From
->Year
+ 1) == To
->Year
) &&
1135 (From
->Month
== 12) &&
1136 (From
->Day
== 31) &&
1139 if ((CompareHMS(From
, To
) >= 0)) {