/** @file
RTC Architectural Protocol GUID as defined in DxeCis 0.96.
Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#include "PcRtc.h"
/**
Compare the Hour, Minute and Second of the From time and the To time.
Only compare H/M/S in EFI_TIME and ignore other fields here.
@param From the first time
@param To the second time
@return >0 The H/M/S of the From time is later than those of To time
@return ==0 The H/M/S of the From time is same as those of To time
@return <0 The H/M/S of the From time is earlier than those of To time
**/
);
/**
To check if second date is later than first date within 24 hours.
@param From the first date
@param To the second date
@retval TRUE From is previous to To within 24 hours.
@retval FALSE From is later, or it is previous to To more than 24 hours.
**/
);
/**
Read RTC content through its registers.
@param Address Address offset of RTC. It is recommended to use macros such as
RTC_ADDRESS_SECONDS.
@return The data of UINT8 type read from RTC.
**/
RtcRead (
)
{
IoWrite8 (PCAT_RTC_ADDRESS_REGISTER, (UINT8) (Address | (UINT8) (IoRead8 (PCAT_RTC_ADDRESS_REGISTER) & 0x80)));
return IoRead8 (PCAT_RTC_DATA_REGISTER);
}
/**
Write RTC through its registers.
@param Address Address offset of RTC. It is recommended to use macros such as
RTC_ADDRESS_SECONDS.
@param Data The content you want to write into RTC.
**/
RtcWrite (
)
{
IoWrite8 (PCAT_RTC_ADDRESS_REGISTER, (UINT8) (Address | (UINT8) (IoRead8 (PCAT_RTC_ADDRESS_REGISTER) & 0x80)));
}
/**
Initialize RTC.
@param Global For global use inside this module.
@retval EFI_DEVICE_ERROR Initialization failed due to device error.
@retval EFI_SUCCESS Initialization successful.
**/
)
{
//
// Acquire RTC Lock to make access to RTC atomic
//
if (!EfiAtRuntime ()) {
}
//
// Initialize RTC Register
//
// Make sure Division Chain is properly configured,
// or RTC clock won't "tick" -- time won't increment
//
//
// Read Register B
//
//
// Clear RTC flag register
//
//
// Clear RTC register D
//
//
// Wait for up to 0.1 seconds for the RTC to be updated
//
//
// Set the variable with default value if the RTC is functioning incorrectly.
//
if (!EfiAtRuntime ()) {
}
return EFI_DEVICE_ERROR;
}
//
//
//
// Set RTC configuration after get original time
// The value of bit AIE should be reserved.
//
//
// Release RTC Lock.
//
if (!EfiAtRuntime ()) {
}
//
// Get the data of Daylight saving and time zone, if they have been
// stored in NV variable during previous boot.
//
Status = EfiGetVariable (
L"RTC",
NULL,
&DataSize,
);
} else {
}
//
// Validate time fields
//
}
Time.Nanosecond = 0;
}
//
// Reset time value according to new RTC configuration
//
return EFI_SUCCESS;
} else {
return EFI_DEVICE_ERROR;
}
}
/**
Returns the current time and date information, and the time-keeping capabilities
of the hardware platform.
@param Time A pointer to storage to receive a snapshot of the current time.
@param Capabilities An optional pointer to a buffer to receive the real time clock
device's capabilities.
@param Global For global use inside this module.
@retval EFI_SUCCESS The operation completed successfully.
@retval EFI_INVALID_PARAMETER Time is NULL.
@retval EFI_DEVICE_ERROR The time could not be retrieved due to hardware error.
**/
)
{
//
// Check parameters for null pointer
//
return EFI_INVALID_PARAMETER;
}
//
// Acquire RTC Lock to make access to RTC atomic
//
if (!EfiAtRuntime ()) {
}
//
// Wait for up to 0.1 seconds for the RTC to be updated
//
if (!EfiAtRuntime ()) {
}
return Status;
}
//
// Read Register B
//
//
//
//
// Release RTC Lock.
//
if (!EfiAtRuntime ()) {
}
//
// Get the variable that contains the TimeZone and Daylight fields
//
//
// Make sure all field values are in correct range
//
}
return EFI_DEVICE_ERROR;
}
//
// Fill in Capabilities if it was passed in
//
if (Capabilities != NULL) {
//
// 1 hertz
//
//
// 50 ppm
//
}
return EFI_SUCCESS;
}
/**
Sets the current local time and date information.
@param Time A pointer to the current time.
@param Global For global use inside this module.
@retval EFI_SUCCESS The operation completed successfully.
@retval EFI_INVALID_PARAMETER A time field is out of range.
@retval EFI_DEVICE_ERROR The time could not be set due due to hardware error.
**/
)
{
return EFI_INVALID_PARAMETER;
}
//
// Make sure that the time fields are valid
//
return Status;
}
//
// Acquire RTC Lock to make access to RTC atomic
//
if (!EfiAtRuntime ()) {
}
//
// Wait for up to 0.1 seconds for the RTC to be updated
//
if (!EfiAtRuntime ()) {
}
return Status;
}
//
// Read Register B, and inhibit updates of the RTC
//
//
// Allow updates of the RTC registers
//
//
// Release RTC Lock.
//
if (!EfiAtRuntime ()) {
}
//
// Set the variable that contains the TimeZone and Daylight fields
//
Status = EfiSetVariable (
L"RTC",
sizeof (TimerVar),
);
return EFI_SUCCESS;
}
/**
Returns the current wakeup alarm clock setting.
@param Enabled Indicates if the alarm is currently enabled or disabled.
@param Pending Indicates if the alarm signal is pending and requires acknowledgment.
@param Time The current alarm setting.
@param Global For global use inside this module.
@retval EFI_SUCCESS The alarm settings were returned.
@retval EFI_INVALID_PARAMETER Enabled is NULL.
@retval EFI_INVALID_PARAMETER Pending is NULL.
@retval EFI_INVALID_PARAMETER Time is NULL.
@retval EFI_DEVICE_ERROR The wakeup time could not be retrieved due to a hardware error.
@retval EFI_UNSUPPORTED A wakeup timer is not supported on this platform.
**/
)
{
//
// Check parameters for null pointers
//
return EFI_INVALID_PARAMETER;
}
//
// Acquire RTC Lock to make access to RTC atomic
//
if (!EfiAtRuntime ()) {
}
//
// Wait for up to 0.1 seconds for the RTC to be updated
//
if (!EfiAtRuntime ()) {
}
return EFI_DEVICE_ERROR;
}
//
// Read Register B and Register C
//
//
//
//
// Get the alarm info from variable
//
Status = EfiGetVariable (
L"RTCALARM",
NULL,
&DataSize,
);
//
// The alarm variable exists. In this case, we read variable to get info.
//
}
//
// Release RTC Lock.
//
if (!EfiAtRuntime ()) {
}
//
// Make sure all field values are in correct range
//
}
return EFI_DEVICE_ERROR;
}
return EFI_SUCCESS;
}
/**
Sets the system wakeup alarm clock time.
@param Enabled Enable or disable the wakeup alarm.
@param Time If Enable is TRUE, the time to set the wakeup alarm for.
If Enable is FALSE, then this parameter is optional, and may be NULL.
@param Global For global use inside this module.
@retval EFI_SUCCESS If Enable is TRUE, then the wakeup alarm was enabled.
If Enable is FALSE, then the wakeup alarm was disabled.
@retval EFI_INVALID_PARAMETER A time field is out of range.
@retval EFI_DEVICE_ERROR The wakeup time could not be set due to a hardware error.
@retval EFI_UNSUPPORTED A wakeup timer is not supported on this platform.
**/
)
{
if (Enable) {
return EFI_INVALID_PARAMETER;
}
//
// Make sure that the time fields are valid
//
return EFI_INVALID_PARAMETER;
}
//
// Just support set alarm time within 24 hours
//
return EFI_DEVICE_ERROR;
}
return EFI_UNSUPPORTED;
}
//
// Make a local copy of the time and date
//
}
//
// Acquire RTC Lock to make access to RTC atomic
//
if (!EfiAtRuntime ()) {
}
//
// Wait for up to 0.1 seconds for the RTC to be updated
//
if (!EfiAtRuntime ()) {
}
return EFI_DEVICE_ERROR;
}
//
// Read Register B, and inhibit updates of the RTC
//
if (Enable) {
//
// Set RTC alarm time
//
} else {
//
// if the alarm is disable, record the current setting.
//
}
//
// Allow updates of the RTC registers
//
//
// Set the Y/M/D info to variable as it has no corresponding hw registers.
//
Status = EfiSetVariable (
L"RTCALARM",
sizeof (RtcTime),
);
return EFI_DEVICE_ERROR;
}
//
// Release RTC Lock.
//
if (!EfiAtRuntime ()) {
}
return EFI_SUCCESS;
}
/**
Checks an 8-bit BCD value, and converts to an 8-bit value if valid.
This function checks the 8-bit BCD value specified by Value.
If valid, the function converts it to an 8-bit value and returns it.
Otherwise, return 0xff.
@param Value The 8-bit BCD value to check and convert
@return The 8-bit value converted. Or 0xff if Value is invalid.
**/
)
{
return BcdToDecimal8 (Value);
}
return 0xff;
}
/**
Converts time read from RTC to EFI_TIME format defined by UEFI spec.
This function converts raw time data read from RTC to the EFI_TIME format
defined by UEFI spec.
If data mode of RTC is BCD, then converts it to decimal,
If RTC is in 12-hour format, then converts it to 24-hour format.
@param Time On input, the time data read from RTC to convert
On output, the time converted to UEFI format
@param Century Value of century read from RTC.
@param RegisterB Value of Register B of RTC, indicating data mode
and hour format.
@retval EFI_INVALID_PARAMETER Parameters passed in are invalid.
@retval EFI_SUCCESS Convert RTC time to EFI time successfully.
**/
)
{
} else {
}
}
Century == 0xff) {
return EFI_INVALID_PARAMETER;
}
//
// If time is in 12 hour format, convert it to 24 hour format
//
}
}
}
Time->Nanosecond = 0;
return EFI_SUCCESS;
}
/**
Wait for a period for the RTC to be ready.
@param Timeout Tell how long it should take to wait.
@retval EFI_DEVICE_ERROR RTC device error.
@retval EFI_SUCCESS RTC is updated and ready.
**/
)
{
//
// See if the RTC is functioning correctly
//
return EFI_DEVICE_ERROR;
}
//
// Wait for up to 0.1 seconds for the RTC to be ready.
//
MicroSecondDelay (10);
Timeout--;
}
return EFI_DEVICE_ERROR;
}
return EFI_SUCCESS;
}
/**
See if all fields of a variable of EFI_TIME type is correct.
@param Time The time to be checked.
@retval EFI_INVALID_PARAMETER Some fields of Time are not correct.
@retval EFI_SUCCESS Time is a valid EFI_TIME variable.
**/
)
{
(!(Time->TimeZone == EFI_UNSPECIFIED_TIMEZONE || (Time->TimeZone >= -1440 && Time->TimeZone <= 1440))) ||
return EFI_INVALID_PARAMETER;
}
return EFI_SUCCESS;
}
/**
See if field Day of an EFI_TIME is correct.
@param Time Its Day field is to be checked.
@retval TRUE Day field of Time is correct.
@retval FALSE Day field of Time is NOT correct.
**/
DayValid (
)
{
DayOfMonth[0] = 31;
//
// The validity of Time->Month field should be checked before
//
) {
return FALSE;
}
return TRUE;
}
/**
Check if it is a leap year.
@param Time The time to be checked.
@retval TRUE It is a leap year.
@retval FALSE It is NOT a leap year.
**/
)
{
return TRUE;
} else {
return FALSE;
}
} else {
return TRUE;
}
} else {
return FALSE;
}
}
/**
Converts time from EFI_TIME format defined by UEFI spec to RTC's.
This function converts time from EFI_TIME format defined by UEFI spec to RTC's.
If data mode of RTC is BCD, then converts EFI_TIME to it.
If RTC is in 12-hour format, then converts EFI_TIME to it.
@param Time On input, the time data read from UEFI to convert
On output, the time converted to RTC format
@param RegisterB Value of Register B of RTC, indicating data mode
@param Century It is set according to EFI_TIME Time.
**/
)
{
//
// Adjust hour field if RTC is in 12 hour mode
//
}
}
}
//
//
}
//
// If we are in 12 hour mode and PM is set, then set bit 7 of the Hour field.
//
}
}
/**
Compare the Hour, Minute and Second of the From time and the To time.
Only compare H/M/S in EFI_TIME and ignore other fields here.
@param From the first time
@param To the second time
@return >0 The H/M/S of the From time is later than those of To time
@return ==0 The H/M/S of the From time is same as those of To time
@return <0 The H/M/S of the From time is earlier than those of To time
**/
)
{
return 1;
} else if ((From->Hour == To->Hour) && (From->Minute == To->Minute) && (From->Second == To->Second)) {
return 0;
} else {
return -1;
}
}
/**
To check if second date is later than first date within 24 hours.
@param From the first date
@param To the second date
@retval TRUE From is previous to To within 24 hours.
@retval FALSE From is later, or it is previous to To more than 24 hours.
**/
)
{
DayOfMonth[0] = 31;
//
// The validity of From->Month field should be checked before
//
}
}
}
}
}
}
}
}
}
}
return Adjacent;
}