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.
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
)) {
144 if (!EfiAtRuntime ()) {
145 EfiReleaseLock (&Global
->RtcLock
);
147 return EFI_DEVICE_ERROR
;
150 // Get the Time/Date/Daylight Savings values.
152 Time
.Second
= RtcRead (RTC_ADDRESS_SECONDS
);
153 Time
.Minute
= RtcRead (RTC_ADDRESS_MINUTES
);
154 Time
.Hour
= RtcRead (RTC_ADDRESS_HOURS
);
155 Time
.Day
= RtcRead (RTC_ADDRESS_DAY_OF_THE_MONTH
);
156 Time
.Month
= RtcRead (RTC_ADDRESS_MONTH
);
157 Time
.Year
= RtcRead (RTC_ADDRESS_YEAR
);
159 Century
= RtcRead (RTC_ADDRESS_CENTURY
);
162 // Set RTC configuration after get original time
163 // The value of bit AIE should be reserved.
165 RtcWrite (RTC_ADDRESS_REGISTER_B
, (UINT8
)(RTC_INIT_REGISTER_B
| (RegisterB
.Data
& BIT5
)));
170 if (!EfiAtRuntime ()) {
171 EfiReleaseLock (&Global
->RtcLock
);
175 // Get the data of Daylight saving and time zone, if they have been
176 // stored in NV variable during previous boot.
178 DataSize
= sizeof (UINT32
);
179 Status
= EfiGetVariable (
186 if (!EFI_ERROR (Status
)) {
187 Time
.TimeZone
= (INT16
) TimerVar
;
188 Time
.Daylight
= (UINT8
) (TimerVar
>> 16);
190 Time
.TimeZone
= EFI_UNSPECIFIED_TIMEZONE
;
195 // Validate time fields
197 Status
= ConvertRtcTimeToEfiTime (&Time
, Century
, RegisterB
);
198 if (!EFI_ERROR (Status
)) {
199 Status
= RtcTimeFieldsValid (&Time
);
201 if (EFI_ERROR (Status
)) {
202 Time
.Second
= RTC_INIT_SECOND
;
203 Time
.Minute
= RTC_INIT_MINUTE
;
204 Time
.Hour
= RTC_INIT_HOUR
;
205 Time
.Day
= RTC_INIT_DAY
;
206 Time
.Month
= RTC_INIT_MONTH
;
207 Time
.Year
= RTC_INIT_YEAR
;
211 // Reset time value according to new RTC configuration
213 PcRtcSetTime (&Time
, Global
);
219 Returns the current time and date information, and the time-keeping capabilities
220 of the hardware platform.
222 @param Time A pointer to storage to receive a snapshot of the current time.
223 @param Capabilities An optional pointer to a buffer to receive the real time clock
224 device's capabilities.
225 @param Global For global use inside this module.
227 @retval EFI_SUCCESS The operation completed successfully.
228 @retval EFI_INVALID_PARAMETER Time is NULL.
229 @retval EFI_DEVICE_ERROR The time could not be retrieved due to hardware error.
235 OUT EFI_TIME_CAPABILITIES
*Capabilities
, OPTIONAL
236 IN PC_RTC_MODULE_GLOBALS
*Global
240 RTC_REGISTER_B RegisterB
;
244 // Check parameters for null pointer
247 return EFI_INVALID_PARAMETER
;
251 // Acquire RTC Lock to make access to RTC atomic
253 if (!EfiAtRuntime ()) {
254 EfiAcquireLock (&Global
->RtcLock
);
257 // Wait for up to 0.1 seconds for the RTC to be updated
259 Status
= RtcWaitToUpdate (PcdGet32 (PcdRealTimeClockUpdateTimeout
));
260 if (EFI_ERROR (Status
)) {
261 if (!EfiAtRuntime ()) {
262 EfiReleaseLock (&Global
->RtcLock
);
269 RegisterB
.Data
= RtcRead (RTC_ADDRESS_REGISTER_B
);
272 // Get the Time/Date/Daylight Savings values.
274 Time
->Second
= RtcRead (RTC_ADDRESS_SECONDS
);
275 Time
->Minute
= RtcRead (RTC_ADDRESS_MINUTES
);
276 Time
->Hour
= RtcRead (RTC_ADDRESS_HOURS
);
277 Time
->Day
= RtcRead (RTC_ADDRESS_DAY_OF_THE_MONTH
);
278 Time
->Month
= RtcRead (RTC_ADDRESS_MONTH
);
279 Time
->Year
= RtcRead (RTC_ADDRESS_YEAR
);
281 Century
= RtcRead (RTC_ADDRESS_CENTURY
);
286 if (!EfiAtRuntime ()) {
287 EfiReleaseLock (&Global
->RtcLock
);
291 // Get the variable that contains the TimeZone and Daylight fields
293 Time
->TimeZone
= Global
->SavedTimeZone
;
294 Time
->Daylight
= Global
->Daylight
;
297 // Make sure all field values are in correct range
299 Status
= ConvertRtcTimeToEfiTime (Time
, Century
, RegisterB
);
300 if (!EFI_ERROR (Status
)) {
301 Status
= RtcTimeFieldsValid (Time
);
303 if (EFI_ERROR (Status
)) {
304 return EFI_DEVICE_ERROR
;
308 // Fill in Capabilities if it was passed in
310 if (Capabilities
!= NULL
) {
311 Capabilities
->Resolution
= 1;
315 Capabilities
->Accuracy
= 50000000;
319 Capabilities
->SetsToZero
= FALSE
;
326 Sets the current local time and date information.
328 @param Time A pointer to the current time.
329 @param Global For global use inside this module.
331 @retval EFI_SUCCESS The operation completed successfully.
332 @retval EFI_INVALID_PARAMETER A time field is out of range.
333 @retval EFI_DEVICE_ERROR The time could not be set due due to hardware error.
339 IN PC_RTC_MODULE_GLOBALS
*Global
344 RTC_REGISTER_B RegisterB
;
349 return EFI_INVALID_PARAMETER
;
352 // Make sure that the time fields are valid
354 Status
= RtcTimeFieldsValid (Time
);
355 if (EFI_ERROR (Status
)) {
359 CopyMem (&RtcTime
, Time
, sizeof (EFI_TIME
));
362 // Acquire RTC Lock to make access to RTC atomic
364 if (!EfiAtRuntime ()) {
365 EfiAcquireLock (&Global
->RtcLock
);
368 // Wait for up to 0.1 seconds for the RTC to be updated
370 Status
= RtcWaitToUpdate (PcdGet32 (PcdRealTimeClockUpdateTimeout
));
371 if (EFI_ERROR (Status
)) {
372 if (!EfiAtRuntime ()) {
373 EfiReleaseLock (&Global
->RtcLock
);
378 // Read Register B, and inhibit updates of the RTC
380 RegisterB
.Data
= RtcRead (RTC_ADDRESS_REGISTER_B
);
381 RegisterB
.Bits
.SET
= 1;
382 RtcWrite (RTC_ADDRESS_REGISTER_B
, RegisterB
.Data
);
384 ConvertEfiTimeToRtcTime (&RtcTime
, RegisterB
, &Century
);
386 RtcWrite (RTC_ADDRESS_SECONDS
, RtcTime
.Second
);
387 RtcWrite (RTC_ADDRESS_MINUTES
, RtcTime
.Minute
);
388 RtcWrite (RTC_ADDRESS_HOURS
, RtcTime
.Hour
);
389 RtcWrite (RTC_ADDRESS_DAY_OF_THE_MONTH
, RtcTime
.Day
);
390 RtcWrite (RTC_ADDRESS_MONTH
, RtcTime
.Month
);
391 RtcWrite (RTC_ADDRESS_YEAR
, (UINT8
) RtcTime
.Year
);
392 RtcWrite (RTC_ADDRESS_CENTURY
, Century
);
395 // Allow updates of the RTC registers
397 RegisterB
.Bits
.SET
= 0;
398 RtcWrite (RTC_ADDRESS_REGISTER_B
, RegisterB
.Data
);
403 if (!EfiAtRuntime ()) {
404 EfiReleaseLock (&Global
->RtcLock
);
407 // Set the variable that contains the TimeZone and Daylight fields
409 Global
->SavedTimeZone
= Time
->TimeZone
;
410 Global
->Daylight
= Time
->Daylight
;
412 TimerVar
= Time
->Daylight
;
413 TimerVar
= (UINT32
) ((TimerVar
<< 16) | Time
->TimeZone
);
414 Status
= EfiSetVariable (
417 EFI_VARIABLE_BOOTSERVICE_ACCESS
| EFI_VARIABLE_RUNTIME_ACCESS
| EFI_VARIABLE_NON_VOLATILE
,
421 ASSERT_EFI_ERROR (Status
);
427 Returns the current wakeup alarm clock setting.
429 @param Enabled Indicates if the alarm is currently enabled or disabled.
430 @param Pending Indicates if the alarm signal is pending and requires acknowledgment.
431 @param Time The current alarm setting.
432 @param Global For global use inside this module.
434 @retval EFI_SUCCESS The alarm settings were returned.
435 @retval EFI_INVALID_PARAMETER Enabled is NULL.
436 @retval EFI_INVALID_PARAMETER Pending is NULL.
437 @retval EFI_INVALID_PARAMETER Time is NULL.
438 @retval EFI_DEVICE_ERROR The wakeup time could not be retrieved due to a hardware error.
439 @retval EFI_UNSUPPORTED A wakeup timer is not supported on this platform.
444 OUT BOOLEAN
*Enabled
,
445 OUT BOOLEAN
*Pending
,
447 IN PC_RTC_MODULE_GLOBALS
*Global
451 RTC_REGISTER_B RegisterB
;
452 RTC_REGISTER_C RegisterC
;
456 // Check parameters for null pointers
458 if ((Enabled
== NULL
) || (Pending
== NULL
) || (Time
== NULL
)) {
459 return EFI_INVALID_PARAMETER
;
463 // Acquire RTC Lock to make access to RTC atomic
465 if (!EfiAtRuntime ()) {
466 EfiAcquireLock (&Global
->RtcLock
);
469 // Wait for up to 0.1 seconds for the RTC to be updated
471 Status
= RtcWaitToUpdate (PcdGet32 (PcdRealTimeClockUpdateTimeout
));
472 if (EFI_ERROR (Status
)) {
473 if (!EfiAtRuntime ()) {
474 EfiReleaseLock (&Global
->RtcLock
);
476 return EFI_DEVICE_ERROR
;
479 // Read Register B and Register C
481 RegisterB
.Data
= RtcRead (RTC_ADDRESS_REGISTER_B
);
482 RegisterC
.Data
= RtcRead (RTC_ADDRESS_REGISTER_C
);
485 // Get the Time/Date/Daylight Savings values.
487 *Enabled
= RegisterB
.Bits
.AIE
;
489 Time
->Second
= RtcRead (RTC_ADDRESS_SECONDS_ALARM
);
490 Time
->Minute
= RtcRead (RTC_ADDRESS_MINUTES_ALARM
);
491 Time
->Hour
= RtcRead (RTC_ADDRESS_HOURS_ALARM
);
492 Time
->Day
= RtcRead (RTC_ADDRESS_DAY_OF_THE_MONTH
);
493 Time
->Month
= RtcRead (RTC_ADDRESS_MONTH
);
494 Time
->Year
= RtcRead (RTC_ADDRESS_YEAR
);
499 Time
->Day
= RtcRead (RTC_ADDRESS_DAY_OF_THE_MONTH
);
500 Time
->Month
= RtcRead (RTC_ADDRESS_MONTH
);
501 Time
->Year
= RtcRead (RTC_ADDRESS_YEAR
);
504 Century
= RtcRead (RTC_ADDRESS_CENTURY
);
509 if (!EfiAtRuntime ()) {
510 EfiReleaseLock (&Global
->RtcLock
);
514 // Get the variable that contains the TimeZone and Daylight fields
516 Time
->TimeZone
= Global
->SavedTimeZone
;
517 Time
->Daylight
= Global
->Daylight
;
520 // Make sure all field values are in correct range
522 Status
= ConvertRtcTimeToEfiTime (Time
, Century
, RegisterB
);
523 if (!EFI_ERROR (Status
)) {
524 Status
= RtcTimeFieldsValid (Time
);
526 if (EFI_ERROR (Status
)) {
527 return EFI_DEVICE_ERROR
;
530 *Pending
= RegisterC
.Bits
.AF
;
536 Sets the system wakeup alarm clock time.
538 @param Enabled Enable or disable the wakeup alarm.
539 @param Time If Enable is TRUE, the time to set the wakeup alarm for.
540 If Enable is FALSE, then this parameter is optional, and may be NULL.
541 @param Global For global use inside this module.
543 @retval EFI_SUCCESS If Enable is TRUE, then the wakeup alarm was enabled.
544 If Enable is FALSE, then the wakeup alarm was disabled.
545 @retval EFI_INVALID_PARAMETER A time field is out of range.
546 @retval EFI_DEVICE_ERROR The wakeup time could not be set due to a hardware error.
547 @retval EFI_UNSUPPORTED A wakeup timer is not supported on this platform.
553 IN EFI_TIME
*Time
, OPTIONAL
554 IN PC_RTC_MODULE_GLOBALS
*Global
559 RTC_REGISTER_B RegisterB
;
561 EFI_TIME_CAPABILITIES Capabilities
;
566 return EFI_INVALID_PARAMETER
;
569 // Make sure that the time fields are valid
571 Status
= RtcTimeFieldsValid (Time
);
572 if (EFI_ERROR (Status
)) {
573 return EFI_INVALID_PARAMETER
;
576 // Just support set alarm time within 24 hours
578 PcRtcGetTime (&RtcTime
, &Capabilities
, Global
);
579 Status
= RtcTimeFieldsValid (&RtcTime
);
580 if (EFI_ERROR (Status
)) {
581 return EFI_DEVICE_ERROR
;
583 if (!IsWithinOneDay (&RtcTime
, Time
)) {
584 return EFI_UNSUPPORTED
;
587 // Make a local copy of the time and date
589 CopyMem (&RtcTime
, Time
, sizeof (EFI_TIME
));
593 // Acquire RTC Lock to make access to RTC atomic
595 if (!EfiAtRuntime ()) {
596 EfiAcquireLock (&Global
->RtcLock
);
599 // Wait for up to 0.1 seconds for the RTC to be updated
601 Status
= RtcWaitToUpdate (PcdGet32 (PcdRealTimeClockUpdateTimeout
));
602 if (EFI_ERROR (Status
)) {
603 if (!EfiAtRuntime ()) {
604 EfiReleaseLock (&Global
->RtcLock
);
606 return EFI_DEVICE_ERROR
;
609 // Read Register B, and inhibit updates of the RTC
611 RegisterB
.Data
= RtcRead (RTC_ADDRESS_REGISTER_B
);
613 RegisterB
.Bits
.SET
= 1;
614 RtcWrite (RTC_ADDRESS_REGISTER_B
, RegisterB
.Data
);
617 ConvertEfiTimeToRtcTime (&RtcTime
, RegisterB
, &Century
);
620 // Set RTC alarm time
622 RtcWrite (RTC_ADDRESS_SECONDS_ALARM
, RtcTime
.Second
);
623 RtcWrite (RTC_ADDRESS_MINUTES_ALARM
, RtcTime
.Minute
);
624 RtcWrite (RTC_ADDRESS_HOURS_ALARM
, RtcTime
.Hour
);
626 RegisterB
.Bits
.AIE
= 1;
629 RegisterB
.Bits
.AIE
= 0;
632 // Allow updates of the RTC registers
634 RegisterB
.Bits
.SET
= 0;
635 RtcWrite (RTC_ADDRESS_REGISTER_B
, RegisterB
.Data
);
640 if (!EfiAtRuntime ()) {
641 EfiReleaseLock (&Global
->RtcLock
);
648 Checks an 8-bit BCD value, and converts to an 8-bit value if valid.
650 This function checks the 8-bit BCD value specified by Value.
651 If valid, the function converts it to an 8-bit value and returns it.
652 Otherwise, return 0xff.
654 @param Value The 8-bit BCD value to check and convert
656 @return The 8-bit value converted. Or 0xff if Value is invalid.
660 CheckAndConvertBcd8ToDecimal8 (
664 if ((Value
< 0xa0) && ((Value
& 0xf) < 0xa)) {
665 return BcdToDecimal8 (Value
);
672 Converts time read from RTC to EFI_TIME format defined by UEFI spec.
674 This function converts raw time data read from RTC to the EFI_TIME format
675 defined by UEFI spec.
676 If data mode of RTC is BCD, then converts it to decimal,
677 If RTC is in 12-hour format, then converts it to 24-hour format.
679 @param Time On input, the time data read from RTC to convert
680 On output, the time converted to UEFI format
681 @param Century Value of century read from RTC.
682 @param RegisterB Value of Register B of RTC, indicating data mode
685 @retval EFI_INVALID_PARAMETER Parameters passed in are invalid.
686 @retval EFI_SUCCESS Convert RTC time to EFI time successfully.
690 ConvertRtcTimeToEfiTime (
691 IN OUT EFI_TIME
*Time
,
693 IN RTC_REGISTER_B RegisterB
698 if ((Time
->Hour
& 0x80) != 0) {
704 Time
->Hour
= (UINT8
) (Time
->Hour
& 0x7f);
706 if (RegisterB
.Bits
.DM
== 0) {
707 Time
->Year
= CheckAndConvertBcd8ToDecimal8 ((UINT8
) Time
->Year
);
708 Time
->Month
= CheckAndConvertBcd8ToDecimal8 (Time
->Month
);
709 Time
->Day
= CheckAndConvertBcd8ToDecimal8 (Time
->Day
);
710 Time
->Hour
= CheckAndConvertBcd8ToDecimal8 (Time
->Hour
);
711 Time
->Minute
= CheckAndConvertBcd8ToDecimal8 (Time
->Minute
);
712 Time
->Second
= CheckAndConvertBcd8ToDecimal8 (Time
->Second
);
714 Century
= CheckAndConvertBcd8ToDecimal8 (Century
);
716 if (Time
->Year
== 0xff || Time
->Month
== 0xff || Time
->Day
== 0xff ||
717 Time
->Hour
== 0xff || Time
->Minute
== 0xff || Time
->Second
== 0xff ||
719 return EFI_INVALID_PARAMETER
;
722 Time
->Year
= (UINT16
) (Century
* 100 + Time
->Year
);
725 // If time is in 12 hour format, convert it to 24 hour format
727 if (RegisterB
.Bits
.MIL
== 0) {
728 if (IsPM
&& Time
->Hour
< 12) {
729 Time
->Hour
= (UINT8
) (Time
->Hour
+ 12);
732 if (!IsPM
&& Time
->Hour
== 12) {
737 Time
->Nanosecond
= 0;
743 Wait for a period for the RTC to be ready.
745 @param Timeout Tell how long it should take to wait.
747 @retval EFI_DEVICE_ERROR RTC device error.
748 @retval EFI_SUCCESS RTC is updated and ready.
755 RTC_REGISTER_A RegisterA
;
756 RTC_REGISTER_D RegisterD
;
759 // See if the RTC is functioning correctly
761 RegisterD
.Data
= RtcRead (RTC_ADDRESS_REGISTER_D
);
763 if (RegisterD
.Bits
.VRT
== 0) {
764 return EFI_DEVICE_ERROR
;
767 // Wait for up to 0.1 seconds for the RTC to be ready.
769 Timeout
= (Timeout
/ 10) + 1;
770 RegisterA
.Data
= RtcRead (RTC_ADDRESS_REGISTER_A
);
771 while (RegisterA
.Bits
.UIP
== 1 && Timeout
> 0) {
772 MicroSecondDelay (10);
773 RegisterA
.Data
= RtcRead (RTC_ADDRESS_REGISTER_A
);
777 RegisterD
.Data
= RtcRead (RTC_ADDRESS_REGISTER_D
);
778 if (Timeout
== 0 || RegisterD
.Bits
.VRT
== 0) {
779 return EFI_DEVICE_ERROR
;
786 See if all fields of a variable of EFI_TIME type is correct.
788 @param Time The time to be checked.
790 @retval EFI_INVALID_PARAMETER Some fields of Time are not correct.
791 @retval EFI_SUCCESS Time is a valid EFI_TIME variable.
799 if (Time
->Year
< 1998 ||
803 (!DayValid (Time
)) ||
807 Time
->Nanosecond
> 999999999 ||
808 (!(Time
->TimeZone
== EFI_UNSPECIFIED_TIMEZONE
|| (Time
->TimeZone
>= -1440 && Time
->TimeZone
<= 1440))) ||
809 ((Time
->Daylight
& (~(EFI_TIME_ADJUST_DAYLIGHT
| EFI_TIME_IN_DAYLIGHT
))) != 0)) {
810 return EFI_INVALID_PARAMETER
;
817 See if field Day of an EFI_TIME is correct.
819 @param Time Its Day field is to be checked.
821 @retval TRUE Day field of Time is correct.
822 @retval FALSE Day field of Time is NOT correct.
845 // The validity of Time->Month field should be checked before
847 ASSERT (Time
->Month
>=1);
848 ASSERT (Time
->Month
<=12);
850 Time
->Day
> DayOfMonth
[Time
->Month
- 1] ||
851 (Time
->Month
== 2 && (!IsLeapYear (Time
) && Time
->Day
> 28))
860 Check if it is a leap year.
862 @param Time The time to be checked.
864 @retval TRUE It is a leap year.
865 @retval FALSE It is NOT a leap year.
872 if (Time
->Year
% 4 == 0) {
873 if (Time
->Year
% 100 == 0) {
874 if (Time
->Year
% 400 == 0) {
888 Converts time from EFI_TIME format defined by UEFI spec to RTC's.
890 This function converts time from EFI_TIME format defined by UEFI spec to RTC's.
891 If data mode of RTC is BCD, then converts EFI_TIME to it.
892 If RTC is in 12-hour format, then converts EFI_TIME to it.
894 @param Time On input, the time data read from UEFI to convert
895 On output, the time converted to RTC format
896 @param RegisterB Value of Register B of RTC, indicating data mode
897 @param Century It is set according to EFI_TIME Time.
901 ConvertEfiTimeToRtcTime (
902 IN OUT EFI_TIME
*Time
,
903 IN RTC_REGISTER_B RegisterB
,
911 // Adjust hour field if RTC is in 12 hour mode
913 if (RegisterB
.Bits
.MIL
== 0) {
914 if (Time
->Hour
< 12) {
918 if (Time
->Hour
>= 13) {
919 Time
->Hour
= (UINT8
) (Time
->Hour
- 12);
920 } else if (Time
->Hour
== 0) {
925 // Set the Time/Date/Daylight Savings values.
927 *Century
= DecimalToBcd8 ((UINT8
) (Time
->Year
/ 100));
929 Time
->Year
= (UINT16
) (Time
->Year
% 100);
931 if (RegisterB
.Bits
.DM
== 0) {
932 Time
->Year
= DecimalToBcd8 ((UINT8
) Time
->Year
);
933 Time
->Month
= DecimalToBcd8 (Time
->Month
);
934 Time
->Day
= DecimalToBcd8 (Time
->Day
);
935 Time
->Hour
= DecimalToBcd8 (Time
->Hour
);
936 Time
->Minute
= DecimalToBcd8 (Time
->Minute
);
937 Time
->Second
= DecimalToBcd8 (Time
->Second
);
940 // If we are in 12 hour mode and PM is set, then set bit 7 of the Hour field.
942 if (RegisterB
.Bits
.MIL
== 0 && IsPM
) {
943 Time
->Hour
= (UINT8
) (Time
->Hour
| 0x80);
948 Compare the Hour, Minute and Second of the From time and the To time.
950 Only compare H/M/S in EFI_TIME and ignore other fields here.
952 @param From the first time
953 @param To the second time
955 @return >0 The H/M/S of the From time is later than those of To time
956 @return ==0 The H/M/S of the From time is same as those of To time
957 @return <0 The H/M/S of the From time is earlier than those of To time
965 if ((From
->Hour
> To
->Hour
) ||
966 ((From
->Hour
== To
->Hour
) && (From
->Minute
> To
->Minute
)) ||
967 ((From
->Hour
== To
->Hour
) && (From
->Minute
== To
->Minute
) && (From
->Second
> To
->Second
))) {
969 } else if ((From
->Hour
== To
->Hour
) && (From
->Minute
== To
->Minute
) && (From
->Second
== To
->Second
)) {
977 To check if second date is later than first date within 24 hours.
979 @param From the first date
980 @param To the second date
982 @retval TRUE From is previous to To within 24 hours.
983 @retval FALSE From is later, or it is previous to To more than 24 hours.
991 UINT8 DayOfMonth
[12];
1004 DayOfMonth
[10] = 30;
1005 DayOfMonth
[11] = 31;
1010 // The validity of From->Month field should be checked before
1012 ASSERT (From
->Month
>=1);
1013 ASSERT (From
->Month
<=12);
1015 if (From
->Year
== To
->Year
) {
1016 if (From
->Month
== To
->Month
) {
1017 if ((From
->Day
+ 1) == To
->Day
) {
1018 if ((CompareHMS(From
, To
) >= 0)) {
1021 } else if (From
->Day
== To
->Day
) {
1022 if ((CompareHMS(From
, To
) <= 0)) {
1026 } else if (((From
->Month
+ 1) == To
->Month
) && (To
->Day
== 1)) {
1027 if ((From
->Month
== 2) && !IsLeapYear(From
)) {
1028 if (From
->Day
== 28) {
1029 if ((CompareHMS(From
, To
) >= 0)) {
1033 } else if (From
->Day
== DayOfMonth
[From
->Month
- 1]) {
1034 if ((CompareHMS(From
, To
) >= 0)) {
1039 } else if (((From
->Year
+ 1) == To
->Year
) &&
1040 (From
->Month
== 12) &&
1041 (From
->Day
== 31) &&
1044 if ((CompareHMS(From
, To
) >= 0)) {