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.
40 GC_TODO: Add function description
44 Address - GC_TODO: add argument description
48 GC_TODO: add return values
52 IoWrite8 (PCAT_RTC_ADDRESS_REGISTER
, (UINT8
) (Address
| (UINT8
) (IoRead8 (PCAT_RTC_ADDRESS_REGISTER
) & 0x80)));
53 return IoRead8 (PCAT_RTC_DATA_REGISTER
);
66 GC_TODO: Add function description
70 Address - GC_TODO: add argument description
71 Data - GC_TODO: add argument description
75 GC_TODO: add return values
79 IoWrite8 (PCAT_RTC_ADDRESS_REGISTER
, (UINT8
) (Address
| (UINT8
) (IoRead8 (PCAT_RTC_ADDRESS_REGISTER
) & 0x80)));
80 IoWrite8 (PCAT_RTC_DATA_REGISTER
, Data
);
85 IN PC_RTC_MODULE_GLOBALS
*Global
91 GC_TODO: Add function description
95 Global - GC_TODO: add argument description
99 EFI_DEVICE_ERROR - GC_TODO: Add description for return value
100 EFI_SUCCESS - GC_TODO: Add description for return value
105 RTC_REGISTER_A RegisterA
;
106 RTC_REGISTER_B RegisterB
;
107 RTC_REGISTER_D RegisterD
;
114 // Acquire RTC Lock to make access to RTC atomic
116 //BugBug: the EfiAtRuntime should be encapsulated in EfiAcquireLock or
117 // provide a new instance for EfiAcquireLock, say, RtEfiAcquireLock
118 if (!EfiAtRuntime ()) {
119 EfiAcquireLock (&Global
->RtcLock
);
122 // Initialize RTC Register
124 // Make sure Division Chain is properly configured,
125 // or RTC clock won't "tick" -- time won't increment
127 RegisterA
.Data
= RTC_INIT_REGISTER_A
;
128 RtcWrite (RTC_ADDRESS_REGISTER_A
, RegisterA
.Data
);
133 RegisterB
.Data
= RtcRead (RTC_ADDRESS_REGISTER_B
);
136 // Clear RTC flag register
138 RtcRead (RTC_ADDRESS_REGISTER_C
);
141 // Clear RTC register D
143 RegisterD
.Data
= RTC_INIT_REGISTER_D
;
144 RtcWrite (RTC_ADDRESS_REGISTER_D
, RegisterD
.Data
);
147 // Wait for up to 0.1 seconds for the RTC to be updated
149 Status
= RtcWaitToUpdate (PcdGet32 (PcdRealTimeClockUpdateTimeout
));
150 if (EFI_ERROR (Status
)) {
151 //BugBug: the EfiAtRuntime should be encapsulated in EfiAcquireLock or
152 // provide a new instance for EfiAcquireLock, say, RtEfiAcquireLock
153 if (!EfiAtRuntime ()) {
154 EfiReleaseLock (&Global
->RtcLock
);
156 return EFI_DEVICE_ERROR
;
159 // Get the Time/Date/Daylight Savings values.
161 Time
.Second
= RtcRead (RTC_ADDRESS_SECONDS
);
162 Time
.Minute
= RtcRead (RTC_ADDRESS_MINUTES
);
163 Time
.Hour
= RtcRead (RTC_ADDRESS_HOURS
);
164 Time
.Day
= RtcRead (RTC_ADDRESS_DAY_OF_THE_MONTH
);
165 Time
.Month
= RtcRead (RTC_ADDRESS_MONTH
);
166 Time
.Year
= RtcRead (RTC_ADDRESS_YEAR
);
168 if (RtcTestCenturyRegister () == EFI_SUCCESS
) {
169 Century
= (UINT8
) (RtcRead (RTC_ADDRESS_CENTURY
) & 0x7f);
171 Century
= RtcRead (RTC_ADDRESS_CENTURY
);
175 // Set RTC configuration after get original time
176 // The value of bit AIE should be reserved.
178 RtcWrite (RTC_ADDRESS_REGISTER_B
, (UINT8
)(RTC_INIT_REGISTER_B
| (RegisterB
.Data
& BIT5
)));
183 //BugBug: the EfiAtRuntime should be encapsulated in EfiAcquireLock or
184 // provide a new instance for EfiAcquireLock, say, RtEfiAcquireLock
186 if (!EfiAtRuntime ()) {
187 EfiReleaseLock (&Global
->RtcLock
);
191 // Validate time fields
193 Status
= ConvertRtcTimeToEfiTime (&Time
, Century
, RegisterB
);
194 if (!EFI_ERROR (Status
)) {
195 Status
= RtcTimeFieldsValid (&Time
);
197 if (EFI_ERROR (Status
)) {
198 Time
.Second
= RTC_INIT_SECOND
;
199 Time
.Minute
= RTC_INIT_MINUTE
;
200 Time
.Hour
= RTC_INIT_HOUR
;
201 Time
.Day
= RTC_INIT_DAY
;
202 Time
.Month
= RTC_INIT_MONTH
;
203 Time
.Year
= RTC_INIT_YEAR
;
206 // Get the data of Daylight saving and time zone, if they have been
207 // stored in NV variable during previous boot.
209 DataSize
= sizeof (UINT32
);
210 Status
= EfiGetVariable (
212 &gEfiGenericPlatformVariableGuid
,
217 if (!EFI_ERROR (Status
)) {
218 Global
->SavedTimeZone
= (INT16
) TimerVar
;
219 Global
->Daylight
= (UINT8
) (TimerVar
>> 16);
221 Time
.TimeZone
= Global
->SavedTimeZone
;
222 Time
.Daylight
= Global
->Daylight
;
225 // Reset time value according to new RTC configuration
227 PcRtcSetTime (&Time
, Global
);
235 IN EFI_TIME_CAPABILITIES
*Capabilities
,
236 IN PC_RTC_MODULE_GLOBALS
*Global
246 // GC_TODO: Time - add argument and description to function comment
247 // GC_TODO: Capabilities - add argument and description to function comment
248 // GC_TODO: Global - add argument and description to function comment
249 // GC_TODO: EFI_INVALID_PARAMETER - add return value to function comment
250 // GC_TODO: EFI_DEVICE_ERROR - add return value to function comment
251 // GC_TODO: EFI_SUCCESS - add return value to function comment
254 RTC_REGISTER_B RegisterB
;
258 // Check parameters for null pointer
261 return EFI_INVALID_PARAMETER
;
265 // Acquire RTC Lock to make access to RTC atomic
267 //BugBug: the EfiAtRuntime should be encapsulated in EfiAcquireLock or
268 // provide a new instance for EfiAcquireLock, say, RtEfiAcquireLock
269 if (!EfiAtRuntime ()) {
270 EfiAcquireLock (&Global
->RtcLock
);
273 // Wait for up to 0.1 seconds for the RTC to be updated
275 Status
= RtcWaitToUpdate (PcdGet32 (PcdRealTimeClockUpdateTimeout
));
276 if (EFI_ERROR (Status
)) {
277 //BugBug: the EfiAtRuntime should be encapsulated in EfiReleaseLock or
278 // provide a new instance for EfiReleaseLock, say, RtEfiReleaseLock
279 if (!EfiAtRuntime ()) {
280 EfiReleaseLock (&Global
->RtcLock
);
287 RegisterB
.Data
= RtcRead (RTC_ADDRESS_REGISTER_B
);
290 // Get the Time/Date/Daylight Savings values.
292 Time
->Second
= RtcRead (RTC_ADDRESS_SECONDS
);
293 Time
->Minute
= RtcRead (RTC_ADDRESS_MINUTES
);
294 Time
->Hour
= RtcRead (RTC_ADDRESS_HOURS
);
295 Time
->Day
= RtcRead (RTC_ADDRESS_DAY_OF_THE_MONTH
);
296 Time
->Month
= RtcRead (RTC_ADDRESS_MONTH
);
297 Time
->Year
= RtcRead (RTC_ADDRESS_YEAR
);
299 if (RtcTestCenturyRegister () == EFI_SUCCESS
) {
300 Century
= (UINT8
) (RtcRead (RTC_ADDRESS_CENTURY
) & 0x7f);
302 Century
= RtcRead (RTC_ADDRESS_CENTURY
);
308 //BugBug: the EfiAtRuntime should be encapsulated in EfiReleaseLock or
309 // provide a new instance for EfiReleaseLock, say, RtEfiReleaseLock
310 if (!EfiAtRuntime ()) {
311 EfiReleaseLock (&Global
->RtcLock
);
314 // Get the variable that containts the TimeZone and Daylight fields
316 Time
->TimeZone
= Global
->SavedTimeZone
;
317 Time
->Daylight
= Global
->Daylight
;
320 // Make sure all field values are in correct range
322 Status
= ConvertRtcTimeToEfiTime (Time
, Century
, RegisterB
);
323 if (!EFI_ERROR (Status
)) {
324 Status
= RtcTimeFieldsValid (Time
);
326 if (EFI_ERROR (Status
)) {
327 return EFI_DEVICE_ERROR
;
330 // Fill in Capabilities if it was passed in
333 Capabilities
->Resolution
= 1;
337 Capabilities
->Accuracy
= 50000000;
341 Capabilities
->SetsToZero
= FALSE
;
350 IN PC_RTC_MODULE_GLOBALS
*Global
360 // GC_TODO: Time - add argument and description to function comment
361 // GC_TODO: Global - add argument and description to function comment
362 // GC_TODO: EFI_INVALID_PARAMETER - add return value to function comment
366 RTC_REGISTER_B RegisterB
;
371 return EFI_INVALID_PARAMETER
;
374 // Make sure that the time fields are valid
376 Status
= RtcTimeFieldsValid (Time
);
377 if (EFI_ERROR (Status
)) {
381 CopyMem (&RtcTime
, Time
, sizeof (EFI_TIME
));
384 // Acquire RTC Lock to make access to RTC atomic
386 //BugBug: the EfiAtRuntime should be encapsulated in EfiAcquireLock or
387 // provide a new instance for EfiAcquireLock, say, RtEfiAcquireLock
388 if (!EfiAtRuntime ()) {
389 EfiAcquireLock (&Global
->RtcLock
);
392 // Wait for up to 0.1 seconds for the RTC to be updated
394 Status
= RtcWaitToUpdate (PcdGet32 (PcdRealTimeClockUpdateTimeout
));
395 if (EFI_ERROR (Status
)) {
396 //BugBug: the EfiAtRuntime should be encapsulated in EfiReleaseLock or
397 // provide a new instance for EfiReleaseLock, say, RtEfiReleaseLock
398 if (!EfiAtRuntime ()) {
399 EfiReleaseLock (&Global
->RtcLock
);
404 // Read Register B, and inhibit updates of the RTC
406 RegisterB
.Data
= RtcRead (RTC_ADDRESS_REGISTER_B
);
407 RegisterB
.Bits
.SET
= 1;
408 RtcWrite (RTC_ADDRESS_REGISTER_B
, RegisterB
.Data
);
410 ConvertEfiTimeToRtcTime (&RtcTime
, RegisterB
, &Century
);
412 RtcWrite (RTC_ADDRESS_SECONDS
, RtcTime
.Second
);
413 RtcWrite (RTC_ADDRESS_MINUTES
, RtcTime
.Minute
);
414 RtcWrite (RTC_ADDRESS_HOURS
, RtcTime
.Hour
);
415 RtcWrite (RTC_ADDRESS_DAY_OF_THE_MONTH
, RtcTime
.Day
);
416 RtcWrite (RTC_ADDRESS_MONTH
, RtcTime
.Month
);
417 RtcWrite (RTC_ADDRESS_YEAR
, (UINT8
) RtcTime
.Year
);
418 if (RtcTestCenturyRegister () == EFI_SUCCESS
) {
419 Century
= (UINT8
) ((Century
& 0x7f) | (RtcRead (RTC_ADDRESS_CENTURY
) & 0x80));
422 RtcWrite (RTC_ADDRESS_CENTURY
, Century
);
425 // Allow updates of the RTC registers
427 RegisterB
.Bits
.SET
= 0;
428 RtcWrite (RTC_ADDRESS_REGISTER_B
, RegisterB
.Data
);
433 //BugBug: the EfiAtRuntime should be encapsulated in EfiReleaseLock or
434 // provide a new instance for EfiReleaseLock, say, RtEfiReleaseLock
435 if (!EfiAtRuntime ()) {
436 EfiReleaseLock (&Global
->RtcLock
);
439 // Set the variable that containts the TimeZone and Daylight fields
441 Global
->SavedTimeZone
= Time
->TimeZone
;
442 Global
->Daylight
= Time
->Daylight
;
444 TimerVar
= Time
->Daylight
;
445 TimerVar
= (UINT32
) ((TimerVar
<< 16) | Time
->TimeZone
);
446 Status
= EfiSetVariable (
448 &gEfiGenericPlatformVariableGuid
,
449 EFI_VARIABLE_BOOTSERVICE_ACCESS
| EFI_VARIABLE_RUNTIME_ACCESS
| EFI_VARIABLE_NON_VOLATILE
,
453 ASSERT_EFI_ERROR (Status
);
460 OUT BOOLEAN
*Enabled
,
461 OUT BOOLEAN
*Pending
,
463 IN PC_RTC_MODULE_GLOBALS
*Global
475 // GC_TODO: Enabled - add argument and description to function comment
476 // GC_TODO: Pending - add argument and description to function comment
477 // GC_TODO: Time - add argument and description to function comment
478 // GC_TODO: Global - add argument and description to function comment
479 // GC_TODO: EFI_INVALID_PARAMETER - add return value to function comment
480 // GC_TODO: EFI_DEVICE_ERROR - add return value to function comment
481 // GC_TODO: EFI_DEVICE_ERROR - add return value to function comment
482 // GC_TODO: EFI_SUCCESS - add return value to function comment
485 RTC_REGISTER_B RegisterB
;
486 RTC_REGISTER_C RegisterC
;
490 // Check paramters for null pointers
492 if ((Enabled
== NULL
) || (Pending
== NULL
) || (Time
== NULL
)) {
493 return EFI_INVALID_PARAMETER
;
497 // Acquire RTC Lock to make access to RTC atomic
499 //BugBug: the EfiAtRuntime should be encapsulated in EfiAcquireLock or
500 // provide a new instance for EfiAcquireLock, say, RtEfiAcquireLock
501 if (!EfiAtRuntime ()) {
502 EfiAcquireLock (&Global
->RtcLock
);
505 // Wait for up to 0.1 seconds for the RTC to be updated
507 Status
= RtcWaitToUpdate (PcdGet32 (PcdRealTimeClockUpdateTimeout
));
508 if (EFI_ERROR (Status
)) {
509 //BugBug: the EfiAtRuntime should be encapsulated in EfiReleaseLock or
510 // provide a new instance for EfiReleaseLock, say, RtEfiReleaseLock
511 if (!EfiAtRuntime ()) {
512 EfiReleaseLock (&Global
->RtcLock
);
514 return EFI_DEVICE_ERROR
;
517 // Read Register B and Register C
519 RegisterB
.Data
= RtcRead (RTC_ADDRESS_REGISTER_B
);
520 RegisterC
.Data
= RtcRead (RTC_ADDRESS_REGISTER_C
);
523 // Get the Time/Date/Daylight Savings values.
525 *Enabled
= RegisterB
.Bits
.AIE
;
527 Time
->Second
= RtcRead (RTC_ADDRESS_SECONDS_ALARM
);
528 Time
->Minute
= RtcRead (RTC_ADDRESS_MINUTES_ALARM
);
529 Time
->Hour
= RtcRead (RTC_ADDRESS_HOURS_ALARM
);
530 Time
->Day
= RtcRead (RTC_ADDRESS_DAY_OF_THE_MONTH
);
531 Time
->Month
= RtcRead (RTC_ADDRESS_MONTH
);
532 Time
->Year
= RtcRead (RTC_ADDRESS_YEAR
);
537 Time
->Day
= RtcRead (RTC_ADDRESS_DAY_OF_THE_MONTH
);
538 Time
->Month
= RtcRead (RTC_ADDRESS_MONTH
);
539 Time
->Year
= RtcRead (RTC_ADDRESS_YEAR
);
542 if (RtcTestCenturyRegister () == EFI_SUCCESS
) {
543 Century
= (UINT8
) (RtcRead (RTC_ADDRESS_CENTURY
) & 0x7f);
545 Century
= RtcRead (RTC_ADDRESS_CENTURY
);
551 //BugBug: the EfiAtRuntime should be encapsulated in EfiReleaseLock or
552 // provide a new instance for EfiReleaseLock, say, RtEfiReleaseLock
553 if (!EfiAtRuntime ()) {
554 EfiReleaseLock (&Global
->RtcLock
);
557 // Make sure all field values are in correct range
559 Status
= ConvertRtcTimeToEfiTime (Time
, Century
, RegisterB
);
560 if (!EFI_ERROR (Status
)) {
561 Status
= RtcTimeFieldsValid (Time
);
563 if (EFI_ERROR (Status
)) {
564 return EFI_DEVICE_ERROR
;
567 *Pending
= RegisterC
.Bits
.AF
;
576 IN PC_RTC_MODULE_GLOBALS
*Global
588 // GC_TODO: Enable - add argument and description to function comment
589 // GC_TODO: Time - add argument and description to function comment
590 // GC_TODO: Global - add argument and description to function comment
591 // GC_TODO: EFI_INVALID_PARAMETER - add return value to function comment
592 // GC_TODO: EFI_INVALID_PARAMETER - add return value to function comment
593 // GC_TODO: EFI_UNSUPPORTED - add return value to function comment
594 // GC_TODO: EFI_DEVICE_ERROR - add return value to function comment
595 // GC_TODO: EFI_SUCCESS - add return value to function comment
599 RTC_REGISTER_B RegisterB
;
601 EFI_TIME_CAPABILITIES Capabilities
;
606 return EFI_INVALID_PARAMETER
;
609 // Make sure that the time fields are valid
611 Status
= RtcTimeFieldsValid (Time
);
612 if (EFI_ERROR (Status
)) {
613 return EFI_INVALID_PARAMETER
;
616 // Just support set alarm time within 24 hours
618 PcRtcGetTime (&RtcTime
, &Capabilities
, Global
);
619 if (!IsWithinOneDay (&RtcTime
, Time
)) {
620 return EFI_UNSUPPORTED
;
623 // Make a local copy of the time and date
625 CopyMem (&RtcTime
, Time
, sizeof (EFI_TIME
));
629 // Acquire RTC Lock to make access to RTC atomic
631 //BugBug: the EfiAtRuntime should be encapsulated in EfiAcquireLock or
632 // provide a new instance for EfiAcquireLock, say, RtEfiAcquireLock
633 if (!EfiAtRuntime ()) {
634 EfiAcquireLock (&Global
->RtcLock
);
637 // Wait for up to 0.1 seconds for the RTC to be updated
639 Status
= RtcWaitToUpdate (PcdGet32 (PcdRealTimeClockUpdateTimeout
));
640 if (EFI_ERROR (Status
)) {
641 //BugBug: the EfiAtRuntime should be encapsulated in EfiReleaseLock or
642 // provide a new instance for EfiReleaseLock, say, RtEfiReleaseLock
643 if (!EfiAtRuntime ()) {
644 EfiReleaseLock (&Global
->RtcLock
);
646 return EFI_DEVICE_ERROR
;
649 // Read Register B, and inhibit updates of the RTC
651 RegisterB
.Data
= RtcRead (RTC_ADDRESS_REGISTER_B
);
653 RegisterB
.Bits
.SET
= 1;
654 RtcWrite (RTC_ADDRESS_REGISTER_B
, RegisterB
.Data
);
657 ConvertEfiTimeToRtcTime (&RtcTime
, RegisterB
, &Century
);
660 // Set RTC alarm time
662 RtcWrite (RTC_ADDRESS_SECONDS_ALARM
, RtcTime
.Second
);
663 RtcWrite (RTC_ADDRESS_MINUTES_ALARM
, RtcTime
.Minute
);
664 RtcWrite (RTC_ADDRESS_HOURS_ALARM
, RtcTime
.Hour
);
666 RegisterB
.Bits
.AIE
= 1;
669 RegisterB
.Bits
.AIE
= 0;
672 // Allow updates of the RTC registers
674 RegisterB
.Bits
.SET
= 0;
675 RtcWrite (RTC_ADDRESS_REGISTER_B
, RegisterB
.Data
);
680 //BugBug: the EfiAtRuntime should be encapsulated in EfiReleaseLock or
681 // provide a new instance for EfiReleaseLock, say, RtEfiReleaseLock
682 if (!EfiAtRuntime ()) {
683 EfiReleaseLock (&Global
->RtcLock
);
689 RtcTestCenturyRegister (
702 // GC_TODO: EFI_SUCCESS - add return value to function comment
703 // GC_TODO: EFI_DEVICE_ERROR - add return value to function comment
708 Century
= RtcRead (RTC_ADDRESS_CENTURY
);
710 // RtcWrite (RTC_ADDRESS_CENTURY, 0x00);
712 Temp
= (UINT8
) (RtcRead (RTC_ADDRESS_CENTURY
) & 0x7f);
713 RtcWrite (RTC_ADDRESS_CENTURY
, Century
);
714 if (Temp
== 0x19 || Temp
== 0x20) {
718 return EFI_DEVICE_ERROR
;
722 Checks an 8-bit BCD value, and converts to an 8-bit value if valid.
724 This function checks the 8-bit BCD value specified by Value.
725 If valid, the function converts it to an 8-bit value and returns it.
726 Otherwise, return 0xff.
728 @param Value The 8-bit BCD value to check and convert
730 @return The 8-bit value converted.
731 0xff if Value is invalid.
735 CheckAndConvertBcd8ToDecimal8 (
739 if ((Value
< 0xa0) && ((Value
& 0xf) < 0xa)) {
740 return BcdToDecimal8 (Value
);
747 Converts time read from RTC to EFI_TIME format defined by UEFI spec.
749 This function converts raw time data read from RTC to the EFI_TIME format
750 defined by UEFI spec.
751 If data mode of RTC is BCD, then converts it to decimal,
752 If RTC is in 12-hour format, then converts it to 24-hour format.
754 @param Time On input, the time data read from RTC to convert
755 On output, the time converted to UEFI format
756 @param Century Value of century read from RTC.
757 @param RegisterB Value of Register B of RTC, indicating data mode
762 ConvertRtcTimeToEfiTime (
763 IN OUT EFI_TIME
*Time
,
765 IN RTC_REGISTER_B RegisterB
770 if ((Time
->Hour
) & 0x80) {
776 Time
->Hour
= (UINT8
) (Time
->Hour
& 0x7f);
778 if (RegisterB
.Bits
.DM
== 0) {
779 Time
->Year
= CheckAndConvertBcd8ToDecimal8 ((UINT8
) Time
->Year
);
780 Time
->Month
= CheckAndConvertBcd8ToDecimal8 (Time
->Month
);
781 Time
->Day
= CheckAndConvertBcd8ToDecimal8 (Time
->Day
);
782 Time
->Hour
= CheckAndConvertBcd8ToDecimal8 (Time
->Hour
);
783 Time
->Minute
= CheckAndConvertBcd8ToDecimal8 (Time
->Minute
);
784 Time
->Second
= CheckAndConvertBcd8ToDecimal8 (Time
->Second
);
785 Century
= CheckAndConvertBcd8ToDecimal8 (Century
);
788 if (Time
->Year
== 0xff || Time
->Month
== 0xff || Time
->Day
== 0xff ||
789 Time
->Hour
== 0xff || Time
->Minute
== 0xff || Time
->Second
== 0xff ||
791 return EFI_INVALID_PARAMETER
;
794 Time
->Year
= (UINT16
) (Century
* 100 + Time
->Year
);
797 // If time is in 12 hour format, convert it to 24 hour format
799 if (RegisterB
.Bits
.MIL
== 0) {
800 if (PM
&& Time
->Hour
< 12) {
801 Time
->Hour
= (UINT8
) (Time
->Hour
+ 12);
804 if (!PM
&& Time
->Hour
== 12) {
809 Time
->Nanosecond
= 0;
810 Time
->TimeZone
= EFI_UNSPECIFIED_TIMEZONE
;
829 // GC_TODO: Timeout - add argument and description to function comment
830 // GC_TODO: EFI_DEVICE_ERROR - add return value to function comment
831 // GC_TODO: EFI_DEVICE_ERROR - add return value to function comment
832 // GC_TODO: EFI_SUCCESS - add return value to function comment
834 RTC_REGISTER_A RegisterA
;
835 RTC_REGISTER_D RegisterD
;
838 // See if the RTC is functioning correctly
840 RegisterD
.Data
= RtcRead (RTC_ADDRESS_REGISTER_D
);
842 if (RegisterD
.Bits
.VRT
== 0) {
843 return EFI_DEVICE_ERROR
;
846 // Wait for up to 0.1 seconds for the RTC to be ready.
848 Timeout
= (Timeout
/ 10) + 1;
849 RegisterA
.Data
= RtcRead (RTC_ADDRESS_REGISTER_A
);
850 while (RegisterA
.Bits
.UIP
== 1 && Timeout
> 0) {
851 MicroSecondDelay (10);
852 RegisterA
.Data
= RtcRead (RTC_ADDRESS_REGISTER_A
);
856 RegisterD
.Data
= RtcRead (RTC_ADDRESS_REGISTER_D
);
857 if (Timeout
== 0 || RegisterD
.Bits
.VRT
== 0) {
858 return EFI_DEVICE_ERROR
;
876 // GC_TODO: Time - add argument and description to function comment
877 // GC_TODO: EFI_INVALID_PARAMETER - add return value to function comment
878 // GC_TODO: EFI_SUCCESS - add return value to function comment
880 if (Time
->Year
< 1998 ||
884 (!DayValid (Time
)) ||
888 Time
->Nanosecond
> 999999999 ||
889 (!(Time
->TimeZone
== EFI_UNSPECIFIED_TIMEZONE
|| (Time
->TimeZone
>= -1440 && Time
->TimeZone
<= 1440))) ||
890 (Time
->Daylight
& (~(EFI_TIME_ADJUST_DAYLIGHT
| EFI_TIME_IN_DAYLIGHT
)))
892 return EFI_INVALID_PARAMETER
;
906 GC_TODO: Add function description
910 Time - GC_TODO: add argument description
914 GC_TODO: add return values
934 Time
->Day
> DayOfMonth
[Time
->Month
- 1] ||
935 (Time
->Month
== 2 && (!IsLeapYear (Time
) && Time
->Day
> 28))
951 GC_TODO: Add function description
955 Time - GC_TODO: add argument description
959 GC_TODO: add return values
963 if (Time
->Year
% 4 == 0) {
964 if (Time
->Year
% 100 == 0) {
965 if (Time
->Year
% 400 == 0) {
979 ConvertEfiTimeToRtcTime (
981 IN RTC_REGISTER_B RegisterB
,
993 // GC_TODO: Time - add argument and description to function comment
994 // GC_TODO: RegisterB - add argument and description to function comment
995 // GC_TODO: Century - add argument and description to function comment
1001 // Adjust hour field if RTC in in 12 hour mode
1003 if (RegisterB
.Bits
.MIL
== 0) {
1004 if (Time
->Hour
< 12) {
1008 if (Time
->Hour
>= 13) {
1009 Time
->Hour
= (UINT8
) (Time
->Hour
- 12);
1010 } else if (Time
->Hour
== 0) {
1015 // Set the Time/Date/Daylight Savings values.
1017 *Century
= DecimalToBcd8 ((UINT8
) (Time
->Year
/ 100));
1019 Time
->Year
= (UINT16
) (Time
->Year
% 100);
1021 if (RegisterB
.Bits
.DM
== 0) {
1022 Time
->Year
= DecimalToBcd8 ((UINT8
) Time
->Year
);
1023 Time
->Month
= DecimalToBcd8 (Time
->Month
);
1024 Time
->Day
= DecimalToBcd8 (Time
->Day
);
1025 Time
->Hour
= DecimalToBcd8 (Time
->Hour
);
1026 Time
->Minute
= DecimalToBcd8 (Time
->Minute
);
1027 Time
->Second
= DecimalToBcd8 (Time
->Second
);
1030 // If we are in 12 hour mode and PM is set, then set bit 7 of the Hour field.
1032 if (RegisterB
.Bits
.MIL
== 0 && PM
) {
1033 Time
->Hour
= (UINT8
) (Time
->Hour
| 0x80);
1045 Routine Description:
1047 Compare the Hour, Minute and Second of the 'From' time and the 'To' time.
1048 Only compare H/M/S in EFI_TIME and ignore other fields here.
1052 From - the first time
1053 To - the second time
1057 >0 : The H/M/S of the 'From' time is later than those of 'To' time
1058 ==0 : The H/M/S of the 'From' time is same as those of 'To' time
1059 <0 : The H/M/S of the 'From' time is earlier than those of 'To' time
1063 if ((From
->Hour
> To
->Hour
) ||
1064 ((From
->Hour
== To
->Hour
) && (From
->Minute
> To
->Minute
)) ||
1065 ((From
->Hour
== To
->Hour
) && (From
->Minute
== To
->Minute
) && (From
->Second
> To
->Second
))) {
1067 } else if ((From
->Hour
== To
->Hour
) && (From
->Minute
== To
->Minute
) && (From
->Second
== To
->Second
)) {
1082 Routine Description:
1084 Judge whether two days are adjacent.
1088 From - the first day
1093 TRUE - The interval of two days are within one day.
1094 FALSE - The interval of two days exceed ony day or parameter error.
1098 UINT8 DayOfMonth
[12];
1111 DayOfMonth
[10] = 30;
1112 DayOfMonth
[11] = 31;
1116 if (From
->Year
== To
->Year
) {
1117 if (From
->Month
== To
->Month
) {
1118 if ((From
->Day
+ 1) == To
->Day
) {
1119 if ((CompareHMS(From
, To
) >= 0)) {
1122 } else if (From
->Day
== To
->Day
) {
1123 if ((CompareHMS(From
, To
) <= 0)) {
1127 } else if (((From
->Month
+ 1) == To
->Month
) && (To
->Day
== 1)) {
1128 if ((From
->Month
== 2) && !IsLeapYear(From
)) {
1129 if (From
->Day
== 28) {
1130 if ((CompareHMS(From
, To
) >= 0)) {
1134 } else if (From
->Day
== DayOfMonth
[From
->Month
- 1]) {
1135 if ((CompareHMS(From
, To
) >= 0)) {
1140 } else if (((From
->Year
+ 1) == To
->Year
) &&
1141 (From
->Month
== 12) &&
1142 (From
->Day
== 31) &&
1145 if ((CompareHMS(From
, To
) >= 0)) {