2 RTC Architectural Protocol GUID as defined in DxeCis 0.96.
4 Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>
5 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.
18 Compare the Hour, Minute and Second of the From time and the To time.
20 Only compare H/M/S in EFI_TIME and ignore other fields here.
22 @param From the first time
23 @param To the second time
25 @return >0 The H/M/S of the From time is later than those of To time
26 @return ==0 The H/M/S of the From time is same as those of To time
27 @return <0 The H/M/S of the From time is earlier than those of To time
36 To check if second date is later than first date within 24 hours.
38 @param From the first date
39 @param To the second date
41 @retval TRUE From is previous to To within 24 hours.
42 @retval FALSE From is later, or it is previous to To more than 24 hours.
51 Read RTC content through its registers.
53 @param Address Address offset of RTC. It is recommended to use macros such as
56 @return The data of UINT8 type read from RTC.
63 IoWrite8 (PCAT_RTC_ADDRESS_REGISTER
, (UINT8
) (Address
| (UINT8
) (IoRead8 (PCAT_RTC_ADDRESS_REGISTER
) & 0x80)));
64 return IoRead8 (PCAT_RTC_DATA_REGISTER
);
68 Write RTC through its registers.
70 @param Address Address offset of RTC. It is recommended to use macros such as
72 @param Data The content you want to write into RTC.
81 IoWrite8 (PCAT_RTC_ADDRESS_REGISTER
, (UINT8
) (Address
| (UINT8
) (IoRead8 (PCAT_RTC_ADDRESS_REGISTER
) & 0x80)));
82 IoWrite8 (PCAT_RTC_DATA_REGISTER
, Data
);
88 @param Global For global use inside this module.
90 @retval EFI_DEVICE_ERROR Initialization failed due to device error.
91 @retval EFI_SUCCESS Initialization successful.
96 IN PC_RTC_MODULE_GLOBALS
*Global
100 RTC_REGISTER_A RegisterA
;
101 RTC_REGISTER_B RegisterB
;
102 RTC_REGISTER_D RegisterD
;
109 // Acquire RTC Lock to make access to RTC atomic
111 if (!EfiAtRuntime ()) {
112 EfiAcquireLock (&Global
->RtcLock
);
115 // Initialize RTC Register
117 // Make sure Division Chain is properly configured,
118 // or RTC clock won't "tick" -- time won't increment
120 RegisterA
.Data
= RTC_INIT_REGISTER_A
;
121 RtcWrite (RTC_ADDRESS_REGISTER_A
, RegisterA
.Data
);
126 RegisterB
.Data
= RtcRead (RTC_ADDRESS_REGISTER_B
);
129 // Clear RTC flag register
131 RtcRead (RTC_ADDRESS_REGISTER_C
);
134 // Clear RTC register D
136 RegisterD
.Data
= RTC_INIT_REGISTER_D
;
137 RtcWrite (RTC_ADDRESS_REGISTER_D
, RegisterD
.Data
);
140 // Wait for up to 0.1 seconds for the RTC to be updated
142 Status
= RtcWaitToUpdate (PcdGet32 (PcdRealTimeClockUpdateTimeout
));
143 if (EFI_ERROR (Status
)) {
145 // Set the variable with default value if the RTC is functioning incorrectly.
147 Global
->SavedTimeZone
= EFI_UNSPECIFIED_TIMEZONE
;
148 Global
->Daylight
= 0;
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 Century
= RtcRead (RTC_ADDRESS_CENTURY
);
167 // Set RTC configuration after get original time
168 // The value of bit AIE should be reserved.
170 RtcWrite (RTC_ADDRESS_REGISTER_B
, (UINT8
)(RTC_INIT_REGISTER_B
| (RegisterB
.Data
& BIT5
)));
175 if (!EfiAtRuntime ()) {
176 EfiReleaseLock (&Global
->RtcLock
);
180 // Get the data of Daylight saving and time zone, if they have been
181 // stored in NV variable during previous boot.
183 DataSize
= sizeof (UINT32
);
184 Status
= EfiGetVariable (
191 if (!EFI_ERROR (Status
)) {
192 Time
.TimeZone
= (INT16
) TimerVar
;
193 Time
.Daylight
= (UINT8
) (TimerVar
>> 16);
195 Time
.TimeZone
= EFI_UNSPECIFIED_TIMEZONE
;
200 // Validate time fields
202 Status
= ConvertRtcTimeToEfiTime (&Time
, Century
, RegisterB
);
203 if (!EFI_ERROR (Status
)) {
204 Status
= RtcTimeFieldsValid (&Time
);
206 if (EFI_ERROR (Status
)) {
208 // Report Status Code to indicate that the RTC has bad date and time
211 EFI_ERROR_CODE
| EFI_ERROR_MINOR
,
212 (EFI_SOFTWARE_DXE_RT_DRIVER
| EFI_SW_EC_BAD_DATE_TIME
)
214 Time
.Second
= RTC_INIT_SECOND
;
215 Time
.Minute
= RTC_INIT_MINUTE
;
216 Time
.Hour
= RTC_INIT_HOUR
;
217 Time
.Day
= RTC_INIT_DAY
;
218 Time
.Month
= RTC_INIT_MONTH
;
219 Time
.Year
= RTC_INIT_YEAR
;
221 Time
.TimeZone
= EFI_UNSPECIFIED_TIMEZONE
;
226 // Reset time value according to new RTC configuration
228 Status
= PcRtcSetTime (&Time
, Global
);
229 if(!EFI_ERROR (Status
)) {
232 return EFI_DEVICE_ERROR
;
237 Returns the current time and date information, and the time-keeping capabilities
238 of the hardware platform.
240 @param Time A pointer to storage to receive a snapshot of the current time.
241 @param Capabilities An optional pointer to a buffer to receive the real time clock
242 device's capabilities.
243 @param Global For global use inside this module.
245 @retval EFI_SUCCESS The operation completed successfully.
246 @retval EFI_INVALID_PARAMETER Time is NULL.
247 @retval EFI_DEVICE_ERROR The time could not be retrieved due to hardware error.
253 OUT EFI_TIME_CAPABILITIES
*Capabilities
, OPTIONAL
254 IN PC_RTC_MODULE_GLOBALS
*Global
258 RTC_REGISTER_B RegisterB
;
262 // Check parameters for null pointer
265 return EFI_INVALID_PARAMETER
;
269 // Acquire RTC Lock to make access to RTC atomic
271 if (!EfiAtRuntime ()) {
272 EfiAcquireLock (&Global
->RtcLock
);
275 // Wait for up to 0.1 seconds for the RTC to be updated
277 Status
= RtcWaitToUpdate (PcdGet32 (PcdRealTimeClockUpdateTimeout
));
278 if (EFI_ERROR (Status
)) {
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 Century
= RtcRead (RTC_ADDRESS_CENTURY
);
304 if (!EfiAtRuntime ()) {
305 EfiReleaseLock (&Global
->RtcLock
);
309 // Get the variable that contains the TimeZone and Daylight fields
311 Time
->TimeZone
= Global
->SavedTimeZone
;
312 Time
->Daylight
= Global
->Daylight
;
315 // Make sure all field values are in correct range
317 Status
= ConvertRtcTimeToEfiTime (Time
, Century
, RegisterB
);
318 if (!EFI_ERROR (Status
)) {
319 Status
= RtcTimeFieldsValid (Time
);
321 if (EFI_ERROR (Status
)) {
322 return EFI_DEVICE_ERROR
;
326 // Fill in Capabilities if it was passed in
328 if (Capabilities
!= NULL
) {
329 Capabilities
->Resolution
= 1;
333 Capabilities
->Accuracy
= 50000000;
337 Capabilities
->SetsToZero
= FALSE
;
344 Sets the current local time and date information.
346 @param Time A pointer to the current time.
347 @param Global For global use inside this module.
349 @retval EFI_SUCCESS The operation completed successfully.
350 @retval EFI_INVALID_PARAMETER A time field is out of range.
351 @retval EFI_DEVICE_ERROR The time could not be set due due to hardware error.
357 IN PC_RTC_MODULE_GLOBALS
*Global
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 if (!EfiAtRuntime ()) {
383 EfiAcquireLock (&Global
->RtcLock
);
386 // Wait for up to 0.1 seconds for the RTC to be updated
388 Status
= RtcWaitToUpdate (PcdGet32 (PcdRealTimeClockUpdateTimeout
));
389 if (EFI_ERROR (Status
)) {
390 if (!EfiAtRuntime ()) {
391 EfiReleaseLock (&Global
->RtcLock
);
396 // Read Register B, and inhibit updates of the RTC
398 RegisterB
.Data
= RtcRead (RTC_ADDRESS_REGISTER_B
);
399 RegisterB
.Bits
.Set
= 1;
400 RtcWrite (RTC_ADDRESS_REGISTER_B
, RegisterB
.Data
);
402 ConvertEfiTimeToRtcTime (&RtcTime
, RegisterB
, &Century
);
404 RtcWrite (RTC_ADDRESS_SECONDS
, RtcTime
.Second
);
405 RtcWrite (RTC_ADDRESS_MINUTES
, RtcTime
.Minute
);
406 RtcWrite (RTC_ADDRESS_HOURS
, RtcTime
.Hour
);
407 RtcWrite (RTC_ADDRESS_DAY_OF_THE_MONTH
, RtcTime
.Day
);
408 RtcWrite (RTC_ADDRESS_MONTH
, RtcTime
.Month
);
409 RtcWrite (RTC_ADDRESS_YEAR
, (UINT8
) RtcTime
.Year
);
410 RtcWrite (RTC_ADDRESS_CENTURY
, Century
);
413 // Allow updates of the RTC registers
415 RegisterB
.Bits
.Set
= 0;
416 RtcWrite (RTC_ADDRESS_REGISTER_B
, RegisterB
.Data
);
421 if (!EfiAtRuntime ()) {
422 EfiReleaseLock (&Global
->RtcLock
);
425 // Set the variable that contains the TimeZone and Daylight fields
427 Global
->SavedTimeZone
= Time
->TimeZone
;
428 Global
->Daylight
= Time
->Daylight
;
430 TimerVar
= Time
->Daylight
;
431 TimerVar
= (UINT32
) ((TimerVar
<< 16) | (UINT16
)(Time
->TimeZone
));
432 Status
= EfiSetVariable (
435 EFI_VARIABLE_BOOTSERVICE_ACCESS
| EFI_VARIABLE_RUNTIME_ACCESS
| EFI_VARIABLE_NON_VOLATILE
,
439 ASSERT_EFI_ERROR (Status
);
445 Returns the current wakeup alarm clock setting.
447 @param Enabled Indicates if the alarm is currently enabled or disabled.
448 @param Pending Indicates if the alarm signal is pending and requires acknowledgment.
449 @param Time The current alarm setting.
450 @param Global For global use inside this module.
452 @retval EFI_SUCCESS The alarm settings were returned.
453 @retval EFI_INVALID_PARAMETER Enabled is NULL.
454 @retval EFI_INVALID_PARAMETER Pending is NULL.
455 @retval EFI_INVALID_PARAMETER Time is NULL.
456 @retval EFI_DEVICE_ERROR The wakeup time could not be retrieved due to a hardware error.
457 @retval EFI_UNSUPPORTED A wakeup timer is not supported on this platform.
462 OUT BOOLEAN
*Enabled
,
463 OUT BOOLEAN
*Pending
,
465 IN PC_RTC_MODULE_GLOBALS
*Global
469 RTC_REGISTER_B RegisterB
;
470 RTC_REGISTER_C RegisterC
;
476 // Check parameters for null pointers
478 if ((Enabled
== NULL
) || (Pending
== NULL
) || (Time
== NULL
)) {
479 return EFI_INVALID_PARAMETER
;
483 // Acquire RTC Lock to make access to RTC atomic
485 if (!EfiAtRuntime ()) {
486 EfiAcquireLock (&Global
->RtcLock
);
489 // Wait for up to 0.1 seconds for the RTC to be updated
491 Status
= RtcWaitToUpdate (PcdGet32 (PcdRealTimeClockUpdateTimeout
));
492 if (EFI_ERROR (Status
)) {
493 if (!EfiAtRuntime ()) {
494 EfiReleaseLock (&Global
->RtcLock
);
496 return EFI_DEVICE_ERROR
;
499 // Read Register B and Register C
501 RegisterB
.Data
= RtcRead (RTC_ADDRESS_REGISTER_B
);
502 RegisterC
.Data
= RtcRead (RTC_ADDRESS_REGISTER_C
);
505 // Get the Time/Date/Daylight Savings values.
507 *Enabled
= RegisterB
.Bits
.Aie
;
508 *Pending
= RegisterC
.Bits
.Af
;
510 Time
->Second
= RtcRead (RTC_ADDRESS_SECONDS_ALARM
);
511 Time
->Minute
= RtcRead (RTC_ADDRESS_MINUTES_ALARM
);
512 Time
->Hour
= RtcRead (RTC_ADDRESS_HOURS_ALARM
);
513 Time
->Day
= RtcRead (RTC_ADDRESS_DAY_OF_THE_MONTH
);
514 Time
->Month
= RtcRead (RTC_ADDRESS_MONTH
);
515 Time
->Year
= RtcRead (RTC_ADDRESS_YEAR
);
516 Time
->TimeZone
= Global
->SavedTimeZone
;
517 Time
->Daylight
= Global
->Daylight
;
519 Century
= RtcRead (RTC_ADDRESS_CENTURY
);
522 // Get the alarm info from variable
524 DataSize
= sizeof (EFI_TIME
);
525 Status
= EfiGetVariable (
532 if (!EFI_ERROR (Status
)) {
534 // The alarm variable exists. In this case, we read variable to get info.
536 Time
->Day
= RtcTime
.Day
;
537 Time
->Month
= RtcTime
.Month
;
538 Time
->Year
= RtcTime
.Year
;
544 if (!EfiAtRuntime ()) {
545 EfiReleaseLock (&Global
->RtcLock
);
549 // Make sure all field values are in correct range
551 Status
= ConvertRtcTimeToEfiTime (Time
, Century
, RegisterB
);
552 if (!EFI_ERROR (Status
)) {
553 Status
= RtcTimeFieldsValid (Time
);
555 if (EFI_ERROR (Status
)) {
556 return EFI_DEVICE_ERROR
;
563 Sets the system wakeup alarm clock time.
565 @param Enabled Enable or disable the wakeup alarm.
566 @param Time If Enable is TRUE, the time to set the wakeup alarm for.
567 If Enable is FALSE, then this parameter is optional, and may be NULL.
568 @param Global For global use inside this module.
570 @retval EFI_SUCCESS If Enable is TRUE, then the wakeup alarm was enabled.
571 If Enable is FALSE, then the wakeup alarm was disabled.
572 @retval EFI_INVALID_PARAMETER A time field is out of range.
573 @retval EFI_DEVICE_ERROR The wakeup time could not be set due to a hardware error.
574 @retval EFI_UNSUPPORTED A wakeup timer is not supported on this platform.
580 IN EFI_TIME
*Time
, OPTIONAL
581 IN PC_RTC_MODULE_GLOBALS
*Global
586 RTC_REGISTER_B RegisterB
;
588 EFI_TIME_CAPABILITIES Capabilities
;
590 ZeroMem (&RtcTime
, sizeof (RtcTime
));
595 return EFI_INVALID_PARAMETER
;
598 // Make sure that the time fields are valid
600 Status
= RtcTimeFieldsValid (Time
);
601 if (EFI_ERROR (Status
)) {
602 return EFI_INVALID_PARAMETER
;
605 // Just support set alarm time within 24 hours
607 PcRtcGetTime (&RtcTime
, &Capabilities
, Global
);
608 Status
= RtcTimeFieldsValid (&RtcTime
);
609 if (EFI_ERROR (Status
)) {
610 return EFI_DEVICE_ERROR
;
612 if (!IsWithinOneDay (&RtcTime
, Time
)) {
613 return EFI_UNSUPPORTED
;
616 // Make a local copy of the time and date
618 CopyMem (&RtcTime
, Time
, sizeof (EFI_TIME
));
622 // Acquire RTC Lock to make access to RTC atomic
624 if (!EfiAtRuntime ()) {
625 EfiAcquireLock (&Global
->RtcLock
);
628 // Wait for up to 0.1 seconds for the RTC to be updated
630 Status
= RtcWaitToUpdate (PcdGet32 (PcdRealTimeClockUpdateTimeout
));
631 if (EFI_ERROR (Status
)) {
632 if (!EfiAtRuntime ()) {
633 EfiReleaseLock (&Global
->RtcLock
);
635 return EFI_DEVICE_ERROR
;
638 // Read Register B, and inhibit updates of the RTC
640 RegisterB
.Data
= RtcRead (RTC_ADDRESS_REGISTER_B
);
642 RegisterB
.Bits
.Set
= 1;
643 RtcWrite (RTC_ADDRESS_REGISTER_B
, RegisterB
.Data
);
646 ConvertEfiTimeToRtcTime (&RtcTime
, RegisterB
, &Century
);
649 // Set RTC alarm time
651 RtcWrite (RTC_ADDRESS_SECONDS_ALARM
, RtcTime
.Second
);
652 RtcWrite (RTC_ADDRESS_MINUTES_ALARM
, RtcTime
.Minute
);
653 RtcWrite (RTC_ADDRESS_HOURS_ALARM
, RtcTime
.Hour
);
655 RegisterB
.Bits
.Aie
= 1;
658 RegisterB
.Bits
.Aie
= 0;
660 // if the alarm is disable, record the current setting.
662 RtcTime
.Second
= RtcRead (RTC_ADDRESS_SECONDS_ALARM
);
663 RtcTime
.Minute
= RtcRead (RTC_ADDRESS_MINUTES_ALARM
);
664 RtcTime
.Hour
= RtcRead (RTC_ADDRESS_HOURS_ALARM
);
665 RtcTime
.Day
= RtcRead (RTC_ADDRESS_DAY_OF_THE_MONTH
);
666 RtcTime
.Month
= RtcRead (RTC_ADDRESS_MONTH
);
667 RtcTime
.Year
= RtcRead (RTC_ADDRESS_YEAR
);
668 RtcTime
.TimeZone
= Global
->SavedTimeZone
;
669 RtcTime
.Daylight
= Global
->Daylight
;
672 // Allow updates of the RTC registers
674 RegisterB
.Bits
.Set
= 0;
675 RtcWrite (RTC_ADDRESS_REGISTER_B
, RegisterB
.Data
);
678 // Set the Y/M/D info to variable as it has no corresponding hw registers.
680 Status
= EfiSetVariable (
683 EFI_VARIABLE_BOOTSERVICE_ACCESS
| EFI_VARIABLE_RUNTIME_ACCESS
| EFI_VARIABLE_NON_VOLATILE
,
687 if (EFI_ERROR (Status
)) {
688 return EFI_DEVICE_ERROR
;
694 if (!EfiAtRuntime ()) {
695 EfiReleaseLock (&Global
->RtcLock
);
702 Checks an 8-bit BCD value, and converts to an 8-bit value if valid.
704 This function checks the 8-bit BCD value specified by Value.
705 If valid, the function converts it to an 8-bit value and returns it.
706 Otherwise, return 0xff.
708 @param Value The 8-bit BCD value to check and convert
710 @return The 8-bit value converted. Or 0xff if Value is invalid.
714 CheckAndConvertBcd8ToDecimal8 (
718 if ((Value
< 0xa0) && ((Value
& 0xf) < 0xa)) {
719 return BcdToDecimal8 (Value
);
726 Converts time read from RTC to EFI_TIME format defined by UEFI spec.
728 This function converts raw time data read from RTC to the EFI_TIME format
729 defined by UEFI spec.
730 If data mode of RTC is BCD, then converts it to decimal,
731 If RTC is in 12-hour format, then converts it to 24-hour format.
733 @param Time On input, the time data read from RTC to convert
734 On output, the time converted to UEFI format
735 @param Century Value of century read from RTC.
736 @param RegisterB Value of Register B of RTC, indicating data mode
739 @retval EFI_INVALID_PARAMETER Parameters passed in are invalid.
740 @retval EFI_SUCCESS Convert RTC time to EFI time successfully.
744 ConvertRtcTimeToEfiTime (
745 IN OUT EFI_TIME
*Time
,
747 IN RTC_REGISTER_B RegisterB
752 if ((Time
->Hour
& 0x80) != 0) {
758 Time
->Hour
= (UINT8
) (Time
->Hour
& 0x7f);
760 if (RegisterB
.Bits
.Dm
== 0) {
761 Time
->Year
= CheckAndConvertBcd8ToDecimal8 ((UINT8
) Time
->Year
);
762 Time
->Month
= CheckAndConvertBcd8ToDecimal8 (Time
->Month
);
763 Time
->Day
= CheckAndConvertBcd8ToDecimal8 (Time
->Day
);
764 Time
->Hour
= CheckAndConvertBcd8ToDecimal8 (Time
->Hour
);
765 Time
->Minute
= CheckAndConvertBcd8ToDecimal8 (Time
->Minute
);
766 Time
->Second
= CheckAndConvertBcd8ToDecimal8 (Time
->Second
);
768 Century
= CheckAndConvertBcd8ToDecimal8 (Century
);
770 if (Time
->Year
== 0xff || Time
->Month
== 0xff || Time
->Day
== 0xff ||
771 Time
->Hour
== 0xff || Time
->Minute
== 0xff || Time
->Second
== 0xff ||
773 return EFI_INVALID_PARAMETER
;
776 Time
->Year
= (UINT16
) (Century
* 100 + Time
->Year
);
779 // If time is in 12 hour format, convert it to 24 hour format
781 if (RegisterB
.Bits
.Mil
== 0) {
782 if (IsPM
&& Time
->Hour
< 12) {
783 Time
->Hour
= (UINT8
) (Time
->Hour
+ 12);
786 if (!IsPM
&& Time
->Hour
== 12) {
791 Time
->Nanosecond
= 0;
797 Wait for a period for the RTC to be ready.
799 @param Timeout Tell how long it should take to wait.
801 @retval EFI_DEVICE_ERROR RTC device error.
802 @retval EFI_SUCCESS RTC is updated and ready.
809 RTC_REGISTER_A RegisterA
;
810 RTC_REGISTER_D RegisterD
;
813 // See if the RTC is functioning correctly
815 RegisterD
.Data
= RtcRead (RTC_ADDRESS_REGISTER_D
);
817 if (RegisterD
.Bits
.Vrt
== 0) {
818 return EFI_DEVICE_ERROR
;
821 // Wait for up to 0.1 seconds for the RTC to be ready.
823 Timeout
= (Timeout
/ 10) + 1;
824 RegisterA
.Data
= RtcRead (RTC_ADDRESS_REGISTER_A
);
825 while (RegisterA
.Bits
.Uip
== 1 && Timeout
> 0) {
826 MicroSecondDelay (10);
827 RegisterA
.Data
= RtcRead (RTC_ADDRESS_REGISTER_A
);
831 RegisterD
.Data
= RtcRead (RTC_ADDRESS_REGISTER_D
);
832 if (Timeout
== 0 || RegisterD
.Bits
.Vrt
== 0) {
833 return EFI_DEVICE_ERROR
;
840 See if all fields of a variable of EFI_TIME type is correct.
842 @param Time The time to be checked.
844 @retval EFI_INVALID_PARAMETER Some fields of Time are not correct.
845 @retval EFI_SUCCESS Time is a valid EFI_TIME variable.
853 if (Time
->Year
< 1998 ||
857 (!DayValid (Time
)) ||
861 Time
->Nanosecond
> 999999999 ||
862 (!(Time
->TimeZone
== EFI_UNSPECIFIED_TIMEZONE
|| (Time
->TimeZone
>= -1440 && Time
->TimeZone
<= 1440))) ||
863 ((Time
->Daylight
& (~(EFI_TIME_ADJUST_DAYLIGHT
| EFI_TIME_IN_DAYLIGHT
))) != 0)) {
864 return EFI_INVALID_PARAMETER
;
871 See if field Day of an EFI_TIME is correct.
873 @param Time Its Day field is to be checked.
875 @retval TRUE Day field of Time is correct.
876 @retval FALSE Day field of Time is NOT correct.
899 // The validity of Time->Month field should be checked before
901 ASSERT (Time
->Month
>=1);
902 ASSERT (Time
->Month
<=12);
904 Time
->Day
> DayOfMonth
[Time
->Month
- 1] ||
905 (Time
->Month
== 2 && (!IsLeapYear (Time
) && Time
->Day
> 28))
914 Check if it is a leap year.
916 @param Time The time to be checked.
918 @retval TRUE It is a leap year.
919 @retval FALSE It is NOT a leap year.
926 if (Time
->Year
% 4 == 0) {
927 if (Time
->Year
% 100 == 0) {
928 if (Time
->Year
% 400 == 0) {
942 Converts time from EFI_TIME format defined by UEFI spec to RTC's.
944 This function converts time from EFI_TIME format defined by UEFI spec to RTC's.
945 If data mode of RTC is BCD, then converts EFI_TIME to it.
946 If RTC is in 12-hour format, then converts EFI_TIME to it.
948 @param Time On input, the time data read from UEFI to convert
949 On output, the time converted to RTC format
950 @param RegisterB Value of Register B of RTC, indicating data mode
951 @param Century It is set according to EFI_TIME Time.
955 ConvertEfiTimeToRtcTime (
956 IN OUT EFI_TIME
*Time
,
957 IN RTC_REGISTER_B RegisterB
,
965 // Adjust hour field if RTC is in 12 hour mode
967 if (RegisterB
.Bits
.Mil
== 0) {
968 if (Time
->Hour
< 12) {
972 if (Time
->Hour
>= 13) {
973 Time
->Hour
= (UINT8
) (Time
->Hour
- 12);
974 } else if (Time
->Hour
== 0) {
979 // Set the Time/Date/Daylight Savings values.
981 *Century
= DecimalToBcd8 ((UINT8
) (Time
->Year
/ 100));
983 Time
->Year
= (UINT16
) (Time
->Year
% 100);
985 if (RegisterB
.Bits
.Dm
== 0) {
986 Time
->Year
= DecimalToBcd8 ((UINT8
) Time
->Year
);
987 Time
->Month
= DecimalToBcd8 (Time
->Month
);
988 Time
->Day
= DecimalToBcd8 (Time
->Day
);
989 Time
->Hour
= DecimalToBcd8 (Time
->Hour
);
990 Time
->Minute
= DecimalToBcd8 (Time
->Minute
);
991 Time
->Second
= DecimalToBcd8 (Time
->Second
);
994 // If we are in 12 hour mode and PM is set, then set bit 7 of the Hour field.
996 if (RegisterB
.Bits
.Mil
== 0 && IsPM
) {
997 Time
->Hour
= (UINT8
) (Time
->Hour
| 0x80);
1002 Compare the Hour, Minute and Second of the From time and the To time.
1004 Only compare H/M/S in EFI_TIME and ignore other fields here.
1006 @param From the first time
1007 @param To the second time
1009 @return >0 The H/M/S of the From time is later than those of To time
1010 @return ==0 The H/M/S of the From time is same as those of To time
1011 @return <0 The H/M/S of the From time is earlier than those of To time
1019 if ((From
->Hour
> To
->Hour
) ||
1020 ((From
->Hour
== To
->Hour
) && (From
->Minute
> To
->Minute
)) ||
1021 ((From
->Hour
== To
->Hour
) && (From
->Minute
== To
->Minute
) && (From
->Second
> To
->Second
))) {
1023 } else if ((From
->Hour
== To
->Hour
) && (From
->Minute
== To
->Minute
) && (From
->Second
== To
->Second
)) {
1031 To check if second date is later than first date within 24 hours.
1033 @param From the first date
1034 @param To the second date
1036 @retval TRUE From is previous to To within 24 hours.
1037 @retval FALSE From is later, or it is previous to To more than 24 hours.
1045 UINT8 DayOfMonth
[12];
1058 DayOfMonth
[10] = 30;
1059 DayOfMonth
[11] = 31;
1064 // The validity of From->Month field should be checked before
1066 ASSERT (From
->Month
>=1);
1067 ASSERT (From
->Month
<=12);
1069 if (From
->Year
== To
->Year
) {
1070 if (From
->Month
== To
->Month
) {
1071 if ((From
->Day
+ 1) == To
->Day
) {
1072 if ((CompareHMS(From
, To
) >= 0)) {
1075 } else if (From
->Day
== To
->Day
) {
1076 if ((CompareHMS(From
, To
) <= 0)) {
1080 } else if (((From
->Month
+ 1) == To
->Month
) && (To
->Day
== 1)) {
1081 if ((From
->Month
== 2) && !IsLeapYear(From
)) {
1082 if (From
->Day
== 28) {
1083 if ((CompareHMS(From
, To
) >= 0)) {
1087 } else if (From
->Day
== DayOfMonth
[From
->Month
- 1]) {
1088 if ((CompareHMS(From
, To
) >= 0)) {
1093 } else if (((From
->Year
+ 1) == To
->Year
) &&
1094 (From
->Month
== 12) &&
1095 (From
->Day
== 31) &&
1098 if ((CompareHMS(From
, To
) >= 0)) {