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
)) {
207 Time
.Second
= RTC_INIT_SECOND
;
208 Time
.Minute
= RTC_INIT_MINUTE
;
209 Time
.Hour
= RTC_INIT_HOUR
;
210 Time
.Day
= RTC_INIT_DAY
;
211 Time
.Month
= RTC_INIT_MONTH
;
212 Time
.Year
= RTC_INIT_YEAR
;
214 Time
.TimeZone
= EFI_UNSPECIFIED_TIMEZONE
;
219 // Reset time value according to new RTC configuration
221 Status
= PcRtcSetTime (&Time
, Global
);
222 if(!EFI_ERROR (Status
)) {
225 return EFI_DEVICE_ERROR
;
230 Returns the current time and date information, and the time-keeping capabilities
231 of the hardware platform.
233 @param Time A pointer to storage to receive a snapshot of the current time.
234 @param Capabilities An optional pointer to a buffer to receive the real time clock
235 device's capabilities.
236 @param Global For global use inside this module.
238 @retval EFI_SUCCESS The operation completed successfully.
239 @retval EFI_INVALID_PARAMETER Time is NULL.
240 @retval EFI_DEVICE_ERROR The time could not be retrieved due to hardware error.
246 OUT EFI_TIME_CAPABILITIES
*Capabilities
, OPTIONAL
247 IN PC_RTC_MODULE_GLOBALS
*Global
251 RTC_REGISTER_B RegisterB
;
255 // Check parameters for null pointer
258 return EFI_INVALID_PARAMETER
;
262 // Acquire RTC Lock to make access to RTC atomic
264 if (!EfiAtRuntime ()) {
265 EfiAcquireLock (&Global
->RtcLock
);
268 // Wait for up to 0.1 seconds for the RTC to be updated
270 Status
= RtcWaitToUpdate (PcdGet32 (PcdRealTimeClockUpdateTimeout
));
271 if (EFI_ERROR (Status
)) {
272 if (!EfiAtRuntime ()) {
273 EfiReleaseLock (&Global
->RtcLock
);
280 RegisterB
.Data
= RtcRead (RTC_ADDRESS_REGISTER_B
);
283 // Get the Time/Date/Daylight Savings values.
285 Time
->Second
= RtcRead (RTC_ADDRESS_SECONDS
);
286 Time
->Minute
= RtcRead (RTC_ADDRESS_MINUTES
);
287 Time
->Hour
= RtcRead (RTC_ADDRESS_HOURS
);
288 Time
->Day
= RtcRead (RTC_ADDRESS_DAY_OF_THE_MONTH
);
289 Time
->Month
= RtcRead (RTC_ADDRESS_MONTH
);
290 Time
->Year
= RtcRead (RTC_ADDRESS_YEAR
);
292 Century
= RtcRead (RTC_ADDRESS_CENTURY
);
297 if (!EfiAtRuntime ()) {
298 EfiReleaseLock (&Global
->RtcLock
);
302 // Get the variable that contains the TimeZone and Daylight fields
304 Time
->TimeZone
= Global
->SavedTimeZone
;
305 Time
->Daylight
= Global
->Daylight
;
308 // Make sure all field values are in correct range
310 Status
= ConvertRtcTimeToEfiTime (Time
, Century
, RegisterB
);
311 if (!EFI_ERROR (Status
)) {
312 Status
= RtcTimeFieldsValid (Time
);
314 if (EFI_ERROR (Status
)) {
315 return EFI_DEVICE_ERROR
;
319 // Fill in Capabilities if it was passed in
321 if (Capabilities
!= NULL
) {
322 Capabilities
->Resolution
= 1;
326 Capabilities
->Accuracy
= 50000000;
330 Capabilities
->SetsToZero
= FALSE
;
337 Sets the current local time and date information.
339 @param Time A pointer to the current time.
340 @param Global For global use inside this module.
342 @retval EFI_SUCCESS The operation completed successfully.
343 @retval EFI_INVALID_PARAMETER A time field is out of range.
344 @retval EFI_DEVICE_ERROR The time could not be set due due to hardware error.
350 IN PC_RTC_MODULE_GLOBALS
*Global
355 RTC_REGISTER_B RegisterB
;
360 return EFI_INVALID_PARAMETER
;
363 // Make sure that the time fields are valid
365 Status
= RtcTimeFieldsValid (Time
);
366 if (EFI_ERROR (Status
)) {
370 CopyMem (&RtcTime
, Time
, sizeof (EFI_TIME
));
373 // Acquire RTC Lock to make access to RTC atomic
375 if (!EfiAtRuntime ()) {
376 EfiAcquireLock (&Global
->RtcLock
);
379 // Wait for up to 0.1 seconds for the RTC to be updated
381 Status
= RtcWaitToUpdate (PcdGet32 (PcdRealTimeClockUpdateTimeout
));
382 if (EFI_ERROR (Status
)) {
383 if (!EfiAtRuntime ()) {
384 EfiReleaseLock (&Global
->RtcLock
);
389 // Read Register B, and inhibit updates of the RTC
391 RegisterB
.Data
= RtcRead (RTC_ADDRESS_REGISTER_B
);
392 RegisterB
.Bits
.Set
= 1;
393 RtcWrite (RTC_ADDRESS_REGISTER_B
, RegisterB
.Data
);
395 ConvertEfiTimeToRtcTime (&RtcTime
, RegisterB
, &Century
);
397 RtcWrite (RTC_ADDRESS_SECONDS
, RtcTime
.Second
);
398 RtcWrite (RTC_ADDRESS_MINUTES
, RtcTime
.Minute
);
399 RtcWrite (RTC_ADDRESS_HOURS
, RtcTime
.Hour
);
400 RtcWrite (RTC_ADDRESS_DAY_OF_THE_MONTH
, RtcTime
.Day
);
401 RtcWrite (RTC_ADDRESS_MONTH
, RtcTime
.Month
);
402 RtcWrite (RTC_ADDRESS_YEAR
, (UINT8
) RtcTime
.Year
);
403 RtcWrite (RTC_ADDRESS_CENTURY
, Century
);
406 // Allow updates of the RTC registers
408 RegisterB
.Bits
.Set
= 0;
409 RtcWrite (RTC_ADDRESS_REGISTER_B
, RegisterB
.Data
);
414 if (!EfiAtRuntime ()) {
415 EfiReleaseLock (&Global
->RtcLock
);
418 // Set the variable that contains the TimeZone and Daylight fields
420 Global
->SavedTimeZone
= Time
->TimeZone
;
421 Global
->Daylight
= Time
->Daylight
;
423 TimerVar
= Time
->Daylight
;
424 TimerVar
= (UINT32
) ((TimerVar
<< 16) | (UINT16
)(Time
->TimeZone
));
425 Status
= EfiSetVariable (
428 EFI_VARIABLE_BOOTSERVICE_ACCESS
| EFI_VARIABLE_RUNTIME_ACCESS
| EFI_VARIABLE_NON_VOLATILE
,
432 ASSERT_EFI_ERROR (Status
);
438 Returns the current wakeup alarm clock setting.
440 @param Enabled Indicates if the alarm is currently enabled or disabled.
441 @param Pending Indicates if the alarm signal is pending and requires acknowledgment.
442 @param Time The current alarm setting.
443 @param Global For global use inside this module.
445 @retval EFI_SUCCESS The alarm settings were returned.
446 @retval EFI_INVALID_PARAMETER Enabled is NULL.
447 @retval EFI_INVALID_PARAMETER Pending is NULL.
448 @retval EFI_INVALID_PARAMETER Time is NULL.
449 @retval EFI_DEVICE_ERROR The wakeup time could not be retrieved due to a hardware error.
450 @retval EFI_UNSUPPORTED A wakeup timer is not supported on this platform.
455 OUT BOOLEAN
*Enabled
,
456 OUT BOOLEAN
*Pending
,
458 IN PC_RTC_MODULE_GLOBALS
*Global
462 RTC_REGISTER_B RegisterB
;
463 RTC_REGISTER_C RegisterC
;
469 // Check parameters for null pointers
471 if ((Enabled
== NULL
) || (Pending
== NULL
) || (Time
== NULL
)) {
472 return EFI_INVALID_PARAMETER
;
476 // Acquire RTC Lock to make access to RTC atomic
478 if (!EfiAtRuntime ()) {
479 EfiAcquireLock (&Global
->RtcLock
);
482 // Wait for up to 0.1 seconds for the RTC to be updated
484 Status
= RtcWaitToUpdate (PcdGet32 (PcdRealTimeClockUpdateTimeout
));
485 if (EFI_ERROR (Status
)) {
486 if (!EfiAtRuntime ()) {
487 EfiReleaseLock (&Global
->RtcLock
);
489 return EFI_DEVICE_ERROR
;
492 // Read Register B and Register C
494 RegisterB
.Data
= RtcRead (RTC_ADDRESS_REGISTER_B
);
495 RegisterC
.Data
= RtcRead (RTC_ADDRESS_REGISTER_C
);
498 // Get the Time/Date/Daylight Savings values.
500 *Enabled
= RegisterB
.Bits
.Aie
;
501 *Pending
= RegisterC
.Bits
.Af
;
503 Time
->Second
= RtcRead (RTC_ADDRESS_SECONDS_ALARM
);
504 Time
->Minute
= RtcRead (RTC_ADDRESS_MINUTES_ALARM
);
505 Time
->Hour
= RtcRead (RTC_ADDRESS_HOURS_ALARM
);
506 Time
->Day
= RtcRead (RTC_ADDRESS_DAY_OF_THE_MONTH
);
507 Time
->Month
= RtcRead (RTC_ADDRESS_MONTH
);
508 Time
->Year
= RtcRead (RTC_ADDRESS_YEAR
);
509 Time
->TimeZone
= Global
->SavedTimeZone
;
510 Time
->Daylight
= Global
->Daylight
;
512 Century
= RtcRead (RTC_ADDRESS_CENTURY
);
515 // Get the alarm info from variable
517 DataSize
= sizeof (EFI_TIME
);
518 Status
= EfiGetVariable (
525 if (!EFI_ERROR (Status
)) {
527 // The alarm variable exists. In this case, we read variable to get info.
529 Time
->Day
= RtcTime
.Day
;
530 Time
->Month
= RtcTime
.Month
;
531 Time
->Year
= RtcTime
.Year
;
537 if (!EfiAtRuntime ()) {
538 EfiReleaseLock (&Global
->RtcLock
);
542 // Make sure all field values are in correct range
544 Status
= ConvertRtcTimeToEfiTime (Time
, Century
, RegisterB
);
545 if (!EFI_ERROR (Status
)) {
546 Status
= RtcTimeFieldsValid (Time
);
548 if (EFI_ERROR (Status
)) {
549 return EFI_DEVICE_ERROR
;
556 Sets the system wakeup alarm clock time.
558 @param Enabled Enable or disable the wakeup alarm.
559 @param Time If Enable is TRUE, the time to set the wakeup alarm for.
560 If Enable is FALSE, then this parameter is optional, and may be NULL.
561 @param Global For global use inside this module.
563 @retval EFI_SUCCESS If Enable is TRUE, then the wakeup alarm was enabled.
564 If Enable is FALSE, then the wakeup alarm was disabled.
565 @retval EFI_INVALID_PARAMETER A time field is out of range.
566 @retval EFI_DEVICE_ERROR The wakeup time could not be set due to a hardware error.
567 @retval EFI_UNSUPPORTED A wakeup timer is not supported on this platform.
573 IN EFI_TIME
*Time
, OPTIONAL
574 IN PC_RTC_MODULE_GLOBALS
*Global
579 RTC_REGISTER_B RegisterB
;
581 EFI_TIME_CAPABILITIES Capabilities
;
583 ZeroMem (&RtcTime
, sizeof (RtcTime
));
588 return EFI_INVALID_PARAMETER
;
591 // Make sure that the time fields are valid
593 Status
= RtcTimeFieldsValid (Time
);
594 if (EFI_ERROR (Status
)) {
595 return EFI_INVALID_PARAMETER
;
598 // Just support set alarm time within 24 hours
600 PcRtcGetTime (&RtcTime
, &Capabilities
, Global
);
601 Status
= RtcTimeFieldsValid (&RtcTime
);
602 if (EFI_ERROR (Status
)) {
603 return EFI_DEVICE_ERROR
;
605 if (!IsWithinOneDay (&RtcTime
, Time
)) {
606 return EFI_UNSUPPORTED
;
609 // Make a local copy of the time and date
611 CopyMem (&RtcTime
, Time
, sizeof (EFI_TIME
));
615 // Acquire RTC Lock to make access to RTC atomic
617 if (!EfiAtRuntime ()) {
618 EfiAcquireLock (&Global
->RtcLock
);
621 // Wait for up to 0.1 seconds for the RTC to be updated
623 Status
= RtcWaitToUpdate (PcdGet32 (PcdRealTimeClockUpdateTimeout
));
624 if (EFI_ERROR (Status
)) {
625 if (!EfiAtRuntime ()) {
626 EfiReleaseLock (&Global
->RtcLock
);
628 return EFI_DEVICE_ERROR
;
631 // Read Register B, and inhibit updates of the RTC
633 RegisterB
.Data
= RtcRead (RTC_ADDRESS_REGISTER_B
);
635 RegisterB
.Bits
.Set
= 1;
636 RtcWrite (RTC_ADDRESS_REGISTER_B
, RegisterB
.Data
);
639 ConvertEfiTimeToRtcTime (&RtcTime
, RegisterB
, &Century
);
642 // Set RTC alarm time
644 RtcWrite (RTC_ADDRESS_SECONDS_ALARM
, RtcTime
.Second
);
645 RtcWrite (RTC_ADDRESS_MINUTES_ALARM
, RtcTime
.Minute
);
646 RtcWrite (RTC_ADDRESS_HOURS_ALARM
, RtcTime
.Hour
);
648 RegisterB
.Bits
.Aie
= 1;
651 RegisterB
.Bits
.Aie
= 0;
653 // if the alarm is disable, record the current setting.
655 RtcTime
.Second
= RtcRead (RTC_ADDRESS_SECONDS_ALARM
);
656 RtcTime
.Minute
= RtcRead (RTC_ADDRESS_MINUTES_ALARM
);
657 RtcTime
.Hour
= RtcRead (RTC_ADDRESS_HOURS_ALARM
);
658 RtcTime
.Day
= RtcRead (RTC_ADDRESS_DAY_OF_THE_MONTH
);
659 RtcTime
.Month
= RtcRead (RTC_ADDRESS_MONTH
);
660 RtcTime
.Year
= RtcRead (RTC_ADDRESS_YEAR
);
661 RtcTime
.TimeZone
= Global
->SavedTimeZone
;
662 RtcTime
.Daylight
= Global
->Daylight
;
665 // Allow updates of the RTC registers
667 RegisterB
.Bits
.Set
= 0;
668 RtcWrite (RTC_ADDRESS_REGISTER_B
, RegisterB
.Data
);
671 // Set the Y/M/D info to variable as it has no corresponding hw registers.
673 Status
= EfiSetVariable (
676 EFI_VARIABLE_BOOTSERVICE_ACCESS
| EFI_VARIABLE_RUNTIME_ACCESS
| EFI_VARIABLE_NON_VOLATILE
,
680 if (EFI_ERROR (Status
)) {
681 return EFI_DEVICE_ERROR
;
687 if (!EfiAtRuntime ()) {
688 EfiReleaseLock (&Global
->RtcLock
);
695 Checks an 8-bit BCD value, and converts to an 8-bit value if valid.
697 This function checks the 8-bit BCD value specified by Value.
698 If valid, the function converts it to an 8-bit value and returns it.
699 Otherwise, return 0xff.
701 @param Value The 8-bit BCD value to check and convert
703 @return The 8-bit value converted. Or 0xff if Value is invalid.
707 CheckAndConvertBcd8ToDecimal8 (
711 if ((Value
< 0xa0) && ((Value
& 0xf) < 0xa)) {
712 return BcdToDecimal8 (Value
);
719 Converts time read from RTC to EFI_TIME format defined by UEFI spec.
721 This function converts raw time data read from RTC to the EFI_TIME format
722 defined by UEFI spec.
723 If data mode of RTC is BCD, then converts it to decimal,
724 If RTC is in 12-hour format, then converts it to 24-hour format.
726 @param Time On input, the time data read from RTC to convert
727 On output, the time converted to UEFI format
728 @param Century Value of century read from RTC.
729 @param RegisterB Value of Register B of RTC, indicating data mode
732 @retval EFI_INVALID_PARAMETER Parameters passed in are invalid.
733 @retval EFI_SUCCESS Convert RTC time to EFI time successfully.
737 ConvertRtcTimeToEfiTime (
738 IN OUT EFI_TIME
*Time
,
740 IN RTC_REGISTER_B RegisterB
745 if ((Time
->Hour
& 0x80) != 0) {
751 Time
->Hour
= (UINT8
) (Time
->Hour
& 0x7f);
753 if (RegisterB
.Bits
.Dm
== 0) {
754 Time
->Year
= CheckAndConvertBcd8ToDecimal8 ((UINT8
) Time
->Year
);
755 Time
->Month
= CheckAndConvertBcd8ToDecimal8 (Time
->Month
);
756 Time
->Day
= CheckAndConvertBcd8ToDecimal8 (Time
->Day
);
757 Time
->Hour
= CheckAndConvertBcd8ToDecimal8 (Time
->Hour
);
758 Time
->Minute
= CheckAndConvertBcd8ToDecimal8 (Time
->Minute
);
759 Time
->Second
= CheckAndConvertBcd8ToDecimal8 (Time
->Second
);
761 Century
= CheckAndConvertBcd8ToDecimal8 (Century
);
763 if (Time
->Year
== 0xff || Time
->Month
== 0xff || Time
->Day
== 0xff ||
764 Time
->Hour
== 0xff || Time
->Minute
== 0xff || Time
->Second
== 0xff ||
766 return EFI_INVALID_PARAMETER
;
769 Time
->Year
= (UINT16
) (Century
* 100 + Time
->Year
);
772 // If time is in 12 hour format, convert it to 24 hour format
774 if (RegisterB
.Bits
.Mil
== 0) {
775 if (IsPM
&& Time
->Hour
< 12) {
776 Time
->Hour
= (UINT8
) (Time
->Hour
+ 12);
779 if (!IsPM
&& Time
->Hour
== 12) {
784 Time
->Nanosecond
= 0;
790 Wait for a period for the RTC to be ready.
792 @param Timeout Tell how long it should take to wait.
794 @retval EFI_DEVICE_ERROR RTC device error.
795 @retval EFI_SUCCESS RTC is updated and ready.
802 RTC_REGISTER_A RegisterA
;
803 RTC_REGISTER_D RegisterD
;
806 // See if the RTC is functioning correctly
808 RegisterD
.Data
= RtcRead (RTC_ADDRESS_REGISTER_D
);
810 if (RegisterD
.Bits
.Vrt
== 0) {
811 return EFI_DEVICE_ERROR
;
814 // Wait for up to 0.1 seconds for the RTC to be ready.
816 Timeout
= (Timeout
/ 10) + 1;
817 RegisterA
.Data
= RtcRead (RTC_ADDRESS_REGISTER_A
);
818 while (RegisterA
.Bits
.Uip
== 1 && Timeout
> 0) {
819 MicroSecondDelay (10);
820 RegisterA
.Data
= RtcRead (RTC_ADDRESS_REGISTER_A
);
824 RegisterD
.Data
= RtcRead (RTC_ADDRESS_REGISTER_D
);
825 if (Timeout
== 0 || RegisterD
.Bits
.Vrt
== 0) {
826 return EFI_DEVICE_ERROR
;
833 See if all fields of a variable of EFI_TIME type is correct.
835 @param Time The time to be checked.
837 @retval EFI_INVALID_PARAMETER Some fields of Time are not correct.
838 @retval EFI_SUCCESS Time is a valid EFI_TIME variable.
846 if (Time
->Year
< 1998 ||
850 (!DayValid (Time
)) ||
854 Time
->Nanosecond
> 999999999 ||
855 (!(Time
->TimeZone
== EFI_UNSPECIFIED_TIMEZONE
|| (Time
->TimeZone
>= -1440 && Time
->TimeZone
<= 1440))) ||
856 ((Time
->Daylight
& (~(EFI_TIME_ADJUST_DAYLIGHT
| EFI_TIME_IN_DAYLIGHT
))) != 0)) {
857 return EFI_INVALID_PARAMETER
;
864 See if field Day of an EFI_TIME is correct.
866 @param Time Its Day field is to be checked.
868 @retval TRUE Day field of Time is correct.
869 @retval FALSE Day field of Time is NOT correct.
892 // The validity of Time->Month field should be checked before
894 ASSERT (Time
->Month
>=1);
895 ASSERT (Time
->Month
<=12);
897 Time
->Day
> DayOfMonth
[Time
->Month
- 1] ||
898 (Time
->Month
== 2 && (!IsLeapYear (Time
) && Time
->Day
> 28))
907 Check if it is a leap year.
909 @param Time The time to be checked.
911 @retval TRUE It is a leap year.
912 @retval FALSE It is NOT a leap year.
919 if (Time
->Year
% 4 == 0) {
920 if (Time
->Year
% 100 == 0) {
921 if (Time
->Year
% 400 == 0) {
935 Converts time from EFI_TIME format defined by UEFI spec to RTC's.
937 This function converts time from EFI_TIME format defined by UEFI spec to RTC's.
938 If data mode of RTC is BCD, then converts EFI_TIME to it.
939 If RTC is in 12-hour format, then converts EFI_TIME to it.
941 @param Time On input, the time data read from UEFI to convert
942 On output, the time converted to RTC format
943 @param RegisterB Value of Register B of RTC, indicating data mode
944 @param Century It is set according to EFI_TIME Time.
948 ConvertEfiTimeToRtcTime (
949 IN OUT EFI_TIME
*Time
,
950 IN RTC_REGISTER_B RegisterB
,
958 // Adjust hour field if RTC is in 12 hour mode
960 if (RegisterB
.Bits
.Mil
== 0) {
961 if (Time
->Hour
< 12) {
965 if (Time
->Hour
>= 13) {
966 Time
->Hour
= (UINT8
) (Time
->Hour
- 12);
967 } else if (Time
->Hour
== 0) {
972 // Set the Time/Date/Daylight Savings values.
974 *Century
= DecimalToBcd8 ((UINT8
) (Time
->Year
/ 100));
976 Time
->Year
= (UINT16
) (Time
->Year
% 100);
978 if (RegisterB
.Bits
.Dm
== 0) {
979 Time
->Year
= DecimalToBcd8 ((UINT8
) Time
->Year
);
980 Time
->Month
= DecimalToBcd8 (Time
->Month
);
981 Time
->Day
= DecimalToBcd8 (Time
->Day
);
982 Time
->Hour
= DecimalToBcd8 (Time
->Hour
);
983 Time
->Minute
= DecimalToBcd8 (Time
->Minute
);
984 Time
->Second
= DecimalToBcd8 (Time
->Second
);
987 // If we are in 12 hour mode and PM is set, then set bit 7 of the Hour field.
989 if (RegisterB
.Bits
.Mil
== 0 && IsPM
) {
990 Time
->Hour
= (UINT8
) (Time
->Hour
| 0x80);
995 Compare the Hour, Minute and Second of the From time and the To time.
997 Only compare H/M/S in EFI_TIME and ignore other fields here.
999 @param From the first time
1000 @param To the second time
1002 @return >0 The H/M/S of the From time is later than those of To time
1003 @return ==0 The H/M/S of the From time is same as those of To time
1004 @return <0 The H/M/S of the From time is earlier than those of To time
1012 if ((From
->Hour
> To
->Hour
) ||
1013 ((From
->Hour
== To
->Hour
) && (From
->Minute
> To
->Minute
)) ||
1014 ((From
->Hour
== To
->Hour
) && (From
->Minute
== To
->Minute
) && (From
->Second
> To
->Second
))) {
1016 } else if ((From
->Hour
== To
->Hour
) && (From
->Minute
== To
->Minute
) && (From
->Second
== To
->Second
)) {
1024 To check if second date is later than first date within 24 hours.
1026 @param From the first date
1027 @param To the second date
1029 @retval TRUE From is previous to To within 24 hours.
1030 @retval FALSE From is later, or it is previous to To more than 24 hours.
1038 UINT8 DayOfMonth
[12];
1051 DayOfMonth
[10] = 30;
1052 DayOfMonth
[11] = 31;
1057 // The validity of From->Month field should be checked before
1059 ASSERT (From
->Month
>=1);
1060 ASSERT (From
->Month
<=12);
1062 if (From
->Year
== To
->Year
) {
1063 if (From
->Month
== To
->Month
) {
1064 if ((From
->Day
+ 1) == To
->Day
) {
1065 if ((CompareHMS(From
, To
) >= 0)) {
1068 } else if (From
->Day
== To
->Day
) {
1069 if ((CompareHMS(From
, To
) <= 0)) {
1073 } else if (((From
->Month
+ 1) == To
->Month
) && (To
->Day
== 1)) {
1074 if ((From
->Month
== 2) && !IsLeapYear(From
)) {
1075 if (From
->Day
== 28) {
1076 if ((CompareHMS(From
, To
) >= 0)) {
1080 } else if (From
->Day
== DayOfMonth
[From
->Month
- 1]) {
1081 if ((CompareHMS(From
, To
) >= 0)) {
1086 } else if (((From
->Year
+ 1) == To
->Year
) &&
1087 (From
->Month
== 12) &&
1088 (From
->Day
== 31) &&
1091 if ((CompareHMS(From
, To
) >= 0)) {