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
;
212 // Reset time value according to new RTC configuration
214 Status
= PcRtcSetTime (&Time
, Global
);
215 if(!EFI_ERROR (Status
)) {
218 return EFI_DEVICE_ERROR
;
223 Returns the current time and date information, and the time-keeping capabilities
224 of the hardware platform.
226 @param Time A pointer to storage to receive a snapshot of the current time.
227 @param Capabilities An optional pointer to a buffer to receive the real time clock
228 device's capabilities.
229 @param Global For global use inside this module.
231 @retval EFI_SUCCESS The operation completed successfully.
232 @retval EFI_INVALID_PARAMETER Time is NULL.
233 @retval EFI_DEVICE_ERROR The time could not be retrieved due to hardware error.
239 OUT EFI_TIME_CAPABILITIES
*Capabilities
, OPTIONAL
240 IN PC_RTC_MODULE_GLOBALS
*Global
244 RTC_REGISTER_B RegisterB
;
248 // Check parameters for null pointer
251 return EFI_INVALID_PARAMETER
;
255 // Acquire RTC Lock to make access to RTC atomic
257 if (!EfiAtRuntime ()) {
258 EfiAcquireLock (&Global
->RtcLock
);
261 // Wait for up to 0.1 seconds for the RTC to be updated
263 Status
= RtcWaitToUpdate (PcdGet32 (PcdRealTimeClockUpdateTimeout
));
264 if (EFI_ERROR (Status
)) {
265 if (!EfiAtRuntime ()) {
266 EfiReleaseLock (&Global
->RtcLock
);
273 RegisterB
.Data
= RtcRead (RTC_ADDRESS_REGISTER_B
);
276 // Get the Time/Date/Daylight Savings values.
278 Time
->Second
= RtcRead (RTC_ADDRESS_SECONDS
);
279 Time
->Minute
= RtcRead (RTC_ADDRESS_MINUTES
);
280 Time
->Hour
= RtcRead (RTC_ADDRESS_HOURS
);
281 Time
->Day
= RtcRead (RTC_ADDRESS_DAY_OF_THE_MONTH
);
282 Time
->Month
= RtcRead (RTC_ADDRESS_MONTH
);
283 Time
->Year
= RtcRead (RTC_ADDRESS_YEAR
);
285 Century
= RtcRead (RTC_ADDRESS_CENTURY
);
290 if (!EfiAtRuntime ()) {
291 EfiReleaseLock (&Global
->RtcLock
);
295 // Get the variable that contains the TimeZone and Daylight fields
297 Time
->TimeZone
= Global
->SavedTimeZone
;
298 Time
->Daylight
= Global
->Daylight
;
301 // Make sure all field values are in correct range
303 Status
= ConvertRtcTimeToEfiTime (Time
, Century
, RegisterB
);
304 if (!EFI_ERROR (Status
)) {
305 Status
= RtcTimeFieldsValid (Time
);
307 if (EFI_ERROR (Status
)) {
308 return EFI_DEVICE_ERROR
;
312 // Fill in Capabilities if it was passed in
314 if (Capabilities
!= NULL
) {
315 Capabilities
->Resolution
= 1;
319 Capabilities
->Accuracy
= 50000000;
323 Capabilities
->SetsToZero
= FALSE
;
330 Sets the current local time and date information.
332 @param Time A pointer to the current time.
333 @param Global For global use inside this module.
335 @retval EFI_SUCCESS The operation completed successfully.
336 @retval EFI_INVALID_PARAMETER A time field is out of range.
337 @retval EFI_DEVICE_ERROR The time could not be set due due to hardware error.
343 IN PC_RTC_MODULE_GLOBALS
*Global
348 RTC_REGISTER_B RegisterB
;
353 return EFI_INVALID_PARAMETER
;
356 // Make sure that the time fields are valid
358 Status
= RtcTimeFieldsValid (Time
);
359 if (EFI_ERROR (Status
)) {
363 CopyMem (&RtcTime
, Time
, sizeof (EFI_TIME
));
366 // Acquire RTC Lock to make access to RTC atomic
368 if (!EfiAtRuntime ()) {
369 EfiAcquireLock (&Global
->RtcLock
);
372 // Wait for up to 0.1 seconds for the RTC to be updated
374 Status
= RtcWaitToUpdate (PcdGet32 (PcdRealTimeClockUpdateTimeout
));
375 if (EFI_ERROR (Status
)) {
376 if (!EfiAtRuntime ()) {
377 EfiReleaseLock (&Global
->RtcLock
);
382 // Read Register B, and inhibit updates of the RTC
384 RegisterB
.Data
= RtcRead (RTC_ADDRESS_REGISTER_B
);
385 RegisterB
.Bits
.SET
= 1;
386 RtcWrite (RTC_ADDRESS_REGISTER_B
, RegisterB
.Data
);
388 ConvertEfiTimeToRtcTime (&RtcTime
, RegisterB
, &Century
);
390 RtcWrite (RTC_ADDRESS_SECONDS
, RtcTime
.Second
);
391 RtcWrite (RTC_ADDRESS_MINUTES
, RtcTime
.Minute
);
392 RtcWrite (RTC_ADDRESS_HOURS
, RtcTime
.Hour
);
393 RtcWrite (RTC_ADDRESS_DAY_OF_THE_MONTH
, RtcTime
.Day
);
394 RtcWrite (RTC_ADDRESS_MONTH
, RtcTime
.Month
);
395 RtcWrite (RTC_ADDRESS_YEAR
, (UINT8
) RtcTime
.Year
);
396 RtcWrite (RTC_ADDRESS_CENTURY
, Century
);
399 // Allow updates of the RTC registers
401 RegisterB
.Bits
.SET
= 0;
402 RtcWrite (RTC_ADDRESS_REGISTER_B
, RegisterB
.Data
);
407 if (!EfiAtRuntime ()) {
408 EfiReleaseLock (&Global
->RtcLock
);
411 // Set the variable that contains the TimeZone and Daylight fields
413 Global
->SavedTimeZone
= Time
->TimeZone
;
414 Global
->Daylight
= Time
->Daylight
;
416 TimerVar
= Time
->Daylight
;
417 TimerVar
= (UINT32
) ((TimerVar
<< 16) | Time
->TimeZone
);
418 Status
= EfiSetVariable (
421 EFI_VARIABLE_BOOTSERVICE_ACCESS
| EFI_VARIABLE_RUNTIME_ACCESS
| EFI_VARIABLE_NON_VOLATILE
,
425 ASSERT_EFI_ERROR (Status
);
431 Returns the current wakeup alarm clock setting.
433 @param Enabled Indicates if the alarm is currently enabled or disabled.
434 @param Pending Indicates if the alarm signal is pending and requires acknowledgment.
435 @param Time The current alarm setting.
436 @param Global For global use inside this module.
438 @retval EFI_SUCCESS The alarm settings were returned.
439 @retval EFI_INVALID_PARAMETER Enabled is NULL.
440 @retval EFI_INVALID_PARAMETER Pending is NULL.
441 @retval EFI_INVALID_PARAMETER Time is NULL.
442 @retval EFI_DEVICE_ERROR The wakeup time could not be retrieved due to a hardware error.
443 @retval EFI_UNSUPPORTED A wakeup timer is not supported on this platform.
448 OUT BOOLEAN
*Enabled
,
449 OUT BOOLEAN
*Pending
,
451 IN PC_RTC_MODULE_GLOBALS
*Global
455 RTC_REGISTER_B RegisterB
;
456 RTC_REGISTER_C RegisterC
;
460 // Check parameters for null pointers
462 if ((Enabled
== NULL
) || (Pending
== NULL
) || (Time
== NULL
)) {
463 return EFI_INVALID_PARAMETER
;
467 // Acquire RTC Lock to make access to RTC atomic
469 if (!EfiAtRuntime ()) {
470 EfiAcquireLock (&Global
->RtcLock
);
473 // Wait for up to 0.1 seconds for the RTC to be updated
475 Status
= RtcWaitToUpdate (PcdGet32 (PcdRealTimeClockUpdateTimeout
));
476 if (EFI_ERROR (Status
)) {
477 if (!EfiAtRuntime ()) {
478 EfiReleaseLock (&Global
->RtcLock
);
480 return EFI_DEVICE_ERROR
;
483 // Read Register B and Register C
485 RegisterB
.Data
= RtcRead (RTC_ADDRESS_REGISTER_B
);
486 RegisterC
.Data
= RtcRead (RTC_ADDRESS_REGISTER_C
);
489 // Get the Time/Date/Daylight Savings values.
491 *Enabled
= RegisterB
.Bits
.AIE
;
493 Time
->Second
= RtcRead (RTC_ADDRESS_SECONDS_ALARM
);
494 Time
->Minute
= RtcRead (RTC_ADDRESS_MINUTES_ALARM
);
495 Time
->Hour
= RtcRead (RTC_ADDRESS_HOURS_ALARM
);
496 Time
->Day
= RtcRead (RTC_ADDRESS_DAY_OF_THE_MONTH
);
497 Time
->Month
= RtcRead (RTC_ADDRESS_MONTH
);
498 Time
->Year
= RtcRead (RTC_ADDRESS_YEAR
);
503 Time
->Day
= RtcRead (RTC_ADDRESS_DAY_OF_THE_MONTH
);
504 Time
->Month
= RtcRead (RTC_ADDRESS_MONTH
);
505 Time
->Year
= RtcRead (RTC_ADDRESS_YEAR
);
508 Century
= RtcRead (RTC_ADDRESS_CENTURY
);
513 if (!EfiAtRuntime ()) {
514 EfiReleaseLock (&Global
->RtcLock
);
518 // Get the variable that contains the TimeZone and Daylight fields
520 Time
->TimeZone
= Global
->SavedTimeZone
;
521 Time
->Daylight
= Global
->Daylight
;
524 // Make sure all field values are in correct range
526 Status
= ConvertRtcTimeToEfiTime (Time
, Century
, RegisterB
);
527 if (!EFI_ERROR (Status
)) {
528 Status
= RtcTimeFieldsValid (Time
);
530 if (EFI_ERROR (Status
)) {
531 return EFI_DEVICE_ERROR
;
534 *Pending
= RegisterC
.Bits
.AF
;
540 Sets the system wakeup alarm clock time.
542 @param Enabled Enable or disable the wakeup alarm.
543 @param Time If Enable is TRUE, the time to set the wakeup alarm for.
544 If Enable is FALSE, then this parameter is optional, and may be NULL.
545 @param Global For global use inside this module.
547 @retval EFI_SUCCESS If Enable is TRUE, then the wakeup alarm was enabled.
548 If Enable is FALSE, then the wakeup alarm was disabled.
549 @retval EFI_INVALID_PARAMETER A time field is out of range.
550 @retval EFI_DEVICE_ERROR The wakeup time could not be set due to a hardware error.
551 @retval EFI_UNSUPPORTED A wakeup timer is not supported on this platform.
557 IN EFI_TIME
*Time
, OPTIONAL
558 IN PC_RTC_MODULE_GLOBALS
*Global
563 RTC_REGISTER_B RegisterB
;
565 EFI_TIME_CAPABILITIES Capabilities
;
570 return EFI_INVALID_PARAMETER
;
573 // Make sure that the time fields are valid
575 Status
= RtcTimeFieldsValid (Time
);
576 if (EFI_ERROR (Status
)) {
577 return EFI_INVALID_PARAMETER
;
580 // Just support set alarm time within 24 hours
582 PcRtcGetTime (&RtcTime
, &Capabilities
, Global
);
583 Status
= RtcTimeFieldsValid (&RtcTime
);
584 if (EFI_ERROR (Status
)) {
585 return EFI_DEVICE_ERROR
;
587 if (!IsWithinOneDay (&RtcTime
, Time
)) {
588 return EFI_UNSUPPORTED
;
591 // Make a local copy of the time and date
593 CopyMem (&RtcTime
, Time
, sizeof (EFI_TIME
));
597 // Acquire RTC Lock to make access to RTC atomic
599 if (!EfiAtRuntime ()) {
600 EfiAcquireLock (&Global
->RtcLock
);
603 // Wait for up to 0.1 seconds for the RTC to be updated
605 Status
= RtcWaitToUpdate (PcdGet32 (PcdRealTimeClockUpdateTimeout
));
606 if (EFI_ERROR (Status
)) {
607 if (!EfiAtRuntime ()) {
608 EfiReleaseLock (&Global
->RtcLock
);
610 return EFI_DEVICE_ERROR
;
613 // Read Register B, and inhibit updates of the RTC
615 RegisterB
.Data
= RtcRead (RTC_ADDRESS_REGISTER_B
);
617 RegisterB
.Bits
.SET
= 1;
618 RtcWrite (RTC_ADDRESS_REGISTER_B
, RegisterB
.Data
);
621 ConvertEfiTimeToRtcTime (&RtcTime
, RegisterB
, &Century
);
624 // Set RTC alarm time
626 RtcWrite (RTC_ADDRESS_SECONDS_ALARM
, RtcTime
.Second
);
627 RtcWrite (RTC_ADDRESS_MINUTES_ALARM
, RtcTime
.Minute
);
628 RtcWrite (RTC_ADDRESS_HOURS_ALARM
, RtcTime
.Hour
);
630 RegisterB
.Bits
.AIE
= 1;
633 RegisterB
.Bits
.AIE
= 0;
636 // Allow updates of the RTC registers
638 RegisterB
.Bits
.SET
= 0;
639 RtcWrite (RTC_ADDRESS_REGISTER_B
, RegisterB
.Data
);
644 if (!EfiAtRuntime ()) {
645 EfiReleaseLock (&Global
->RtcLock
);
652 Checks an 8-bit BCD value, and converts to an 8-bit value if valid.
654 This function checks the 8-bit BCD value specified by Value.
655 If valid, the function converts it to an 8-bit value and returns it.
656 Otherwise, return 0xff.
658 @param Value The 8-bit BCD value to check and convert
660 @return The 8-bit value converted. Or 0xff if Value is invalid.
664 CheckAndConvertBcd8ToDecimal8 (
668 if ((Value
< 0xa0) && ((Value
& 0xf) < 0xa)) {
669 return BcdToDecimal8 (Value
);
676 Converts time read from RTC to EFI_TIME format defined by UEFI spec.
678 This function converts raw time data read from RTC to the EFI_TIME format
679 defined by UEFI spec.
680 If data mode of RTC is BCD, then converts it to decimal,
681 If RTC is in 12-hour format, then converts it to 24-hour format.
683 @param Time On input, the time data read from RTC to convert
684 On output, the time converted to UEFI format
685 @param Century Value of century read from RTC.
686 @param RegisterB Value of Register B of RTC, indicating data mode
689 @retval EFI_INVALID_PARAMETER Parameters passed in are invalid.
690 @retval EFI_SUCCESS Convert RTC time to EFI time successfully.
694 ConvertRtcTimeToEfiTime (
695 IN OUT EFI_TIME
*Time
,
697 IN RTC_REGISTER_B RegisterB
702 if ((Time
->Hour
& 0x80) != 0) {
708 Time
->Hour
= (UINT8
) (Time
->Hour
& 0x7f);
710 if (RegisterB
.Bits
.DM
== 0) {
711 Time
->Year
= CheckAndConvertBcd8ToDecimal8 ((UINT8
) Time
->Year
);
712 Time
->Month
= CheckAndConvertBcd8ToDecimal8 (Time
->Month
);
713 Time
->Day
= CheckAndConvertBcd8ToDecimal8 (Time
->Day
);
714 Time
->Hour
= CheckAndConvertBcd8ToDecimal8 (Time
->Hour
);
715 Time
->Minute
= CheckAndConvertBcd8ToDecimal8 (Time
->Minute
);
716 Time
->Second
= CheckAndConvertBcd8ToDecimal8 (Time
->Second
);
718 Century
= CheckAndConvertBcd8ToDecimal8 (Century
);
720 if (Time
->Year
== 0xff || Time
->Month
== 0xff || Time
->Day
== 0xff ||
721 Time
->Hour
== 0xff || Time
->Minute
== 0xff || Time
->Second
== 0xff ||
723 return EFI_INVALID_PARAMETER
;
726 Time
->Year
= (UINT16
) (Century
* 100 + Time
->Year
);
729 // If time is in 12 hour format, convert it to 24 hour format
731 if (RegisterB
.Bits
.MIL
== 0) {
732 if (IsPM
&& Time
->Hour
< 12) {
733 Time
->Hour
= (UINT8
) (Time
->Hour
+ 12);
736 if (!IsPM
&& Time
->Hour
== 12) {
741 Time
->Nanosecond
= 0;
747 Wait for a period for the RTC to be ready.
749 @param Timeout Tell how long it should take to wait.
751 @retval EFI_DEVICE_ERROR RTC device error.
752 @retval EFI_SUCCESS RTC is updated and ready.
759 RTC_REGISTER_A RegisterA
;
760 RTC_REGISTER_D RegisterD
;
763 // See if the RTC is functioning correctly
765 RegisterD
.Data
= RtcRead (RTC_ADDRESS_REGISTER_D
);
767 if (RegisterD
.Bits
.VRT
== 0) {
768 return EFI_DEVICE_ERROR
;
771 // Wait for up to 0.1 seconds for the RTC to be ready.
773 Timeout
= (Timeout
/ 10) + 1;
774 RegisterA
.Data
= RtcRead (RTC_ADDRESS_REGISTER_A
);
775 while (RegisterA
.Bits
.UIP
== 1 && Timeout
> 0) {
776 MicroSecondDelay (10);
777 RegisterA
.Data
= RtcRead (RTC_ADDRESS_REGISTER_A
);
781 RegisterD
.Data
= RtcRead (RTC_ADDRESS_REGISTER_D
);
782 if (Timeout
== 0 || RegisterD
.Bits
.VRT
== 0) {
783 return EFI_DEVICE_ERROR
;
790 See if all fields of a variable of EFI_TIME type is correct.
792 @param Time The time to be checked.
794 @retval EFI_INVALID_PARAMETER Some fields of Time are not correct.
795 @retval EFI_SUCCESS Time is a valid EFI_TIME variable.
803 if (Time
->Year
< 1998 ||
807 (!DayValid (Time
)) ||
811 Time
->Nanosecond
> 999999999 ||
812 (!(Time
->TimeZone
== EFI_UNSPECIFIED_TIMEZONE
|| (Time
->TimeZone
>= -1440 && Time
->TimeZone
<= 1440))) ||
813 ((Time
->Daylight
& (~(EFI_TIME_ADJUST_DAYLIGHT
| EFI_TIME_IN_DAYLIGHT
))) != 0)) {
814 return EFI_INVALID_PARAMETER
;
821 See if field Day of an EFI_TIME is correct.
823 @param Time Its Day field is to be checked.
825 @retval TRUE Day field of Time is correct.
826 @retval FALSE Day field of Time is NOT correct.
849 // The validity of Time->Month field should be checked before
851 ASSERT (Time
->Month
>=1);
852 ASSERT (Time
->Month
<=12);
854 Time
->Day
> DayOfMonth
[Time
->Month
- 1] ||
855 (Time
->Month
== 2 && (!IsLeapYear (Time
) && Time
->Day
> 28))
864 Check if it is a leap year.
866 @param Time The time to be checked.
868 @retval TRUE It is a leap year.
869 @retval FALSE It is NOT a leap year.
876 if (Time
->Year
% 4 == 0) {
877 if (Time
->Year
% 100 == 0) {
878 if (Time
->Year
% 400 == 0) {
892 Converts time from EFI_TIME format defined by UEFI spec to RTC's.
894 This function converts time from EFI_TIME format defined by UEFI spec to RTC's.
895 If data mode of RTC is BCD, then converts EFI_TIME to it.
896 If RTC is in 12-hour format, then converts EFI_TIME to it.
898 @param Time On input, the time data read from UEFI to convert
899 On output, the time converted to RTC format
900 @param RegisterB Value of Register B of RTC, indicating data mode
901 @param Century It is set according to EFI_TIME Time.
905 ConvertEfiTimeToRtcTime (
906 IN OUT EFI_TIME
*Time
,
907 IN RTC_REGISTER_B RegisterB
,
915 // Adjust hour field if RTC is in 12 hour mode
917 if (RegisterB
.Bits
.MIL
== 0) {
918 if (Time
->Hour
< 12) {
922 if (Time
->Hour
>= 13) {
923 Time
->Hour
= (UINT8
) (Time
->Hour
- 12);
924 } else if (Time
->Hour
== 0) {
929 // Set the Time/Date/Daylight Savings values.
931 *Century
= DecimalToBcd8 ((UINT8
) (Time
->Year
/ 100));
933 Time
->Year
= (UINT16
) (Time
->Year
% 100);
935 if (RegisterB
.Bits
.DM
== 0) {
936 Time
->Year
= DecimalToBcd8 ((UINT8
) Time
->Year
);
937 Time
->Month
= DecimalToBcd8 (Time
->Month
);
938 Time
->Day
= DecimalToBcd8 (Time
->Day
);
939 Time
->Hour
= DecimalToBcd8 (Time
->Hour
);
940 Time
->Minute
= DecimalToBcd8 (Time
->Minute
);
941 Time
->Second
= DecimalToBcd8 (Time
->Second
);
944 // If we are in 12 hour mode and PM is set, then set bit 7 of the Hour field.
946 if (RegisterB
.Bits
.MIL
== 0 && IsPM
) {
947 Time
->Hour
= (UINT8
) (Time
->Hour
| 0x80);
952 Compare the Hour, Minute and Second of the From time and the To time.
954 Only compare H/M/S in EFI_TIME and ignore other fields here.
956 @param From the first time
957 @param To the second time
959 @return >0 The H/M/S of the From time is later than those of To time
960 @return ==0 The H/M/S of the From time is same as those of To time
961 @return <0 The H/M/S of the From time is earlier than those of To time
969 if ((From
->Hour
> To
->Hour
) ||
970 ((From
->Hour
== To
->Hour
) && (From
->Minute
> To
->Minute
)) ||
971 ((From
->Hour
== To
->Hour
) && (From
->Minute
== To
->Minute
) && (From
->Second
> To
->Second
))) {
973 } else if ((From
->Hour
== To
->Hour
) && (From
->Minute
== To
->Minute
) && (From
->Second
== To
->Second
)) {
981 To check if second date is later than first date within 24 hours.
983 @param From the first date
984 @param To the second date
986 @retval TRUE From is previous to To within 24 hours.
987 @retval FALSE From is later, or it is previous to To more than 24 hours.
995 UINT8 DayOfMonth
[12];
1008 DayOfMonth
[10] = 30;
1009 DayOfMonth
[11] = 31;
1014 // The validity of From->Month field should be checked before
1016 ASSERT (From
->Month
>=1);
1017 ASSERT (From
->Month
<=12);
1019 if (From
->Year
== To
->Year
) {
1020 if (From
->Month
== To
->Month
) {
1021 if ((From
->Day
+ 1) == To
->Day
) {
1022 if ((CompareHMS(From
, To
) >= 0)) {
1025 } else if (From
->Day
== To
->Day
) {
1026 if ((CompareHMS(From
, To
) <= 0)) {
1030 } else if (((From
->Month
+ 1) == To
->Month
) && (To
->Day
== 1)) {
1031 if ((From
->Month
== 2) && !IsLeapYear(From
)) {
1032 if (From
->Day
== 28) {
1033 if ((CompareHMS(From
, To
) >= 0)) {
1037 } else if (From
->Day
== DayOfMonth
[From
->Month
- 1]) {
1038 if ((CompareHMS(From
, To
) >= 0)) {
1043 } else if (((From
->Year
+ 1) == To
->Year
) &&
1044 (From
->Month
== 12) &&
1045 (From
->Day
== 31) &&
1048 if ((CompareHMS(From
, To
) >= 0)) {