On Thu, Aug 17, 2017 at 11:43:37PM +0800, Jun Nie wrote:
On 2017年08月10日 22:03, Leif Lindholm wrote:
On Wed, Aug 09, 2017 at 10:12:37PM +0800, Jun Nie wrote:
Runtime service is not supported yet.
Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Jun Nie jun.nie@linaro.org
.../Zx6718RealTimeClockLib/Zx296718RealTimeClock.c | 376 +++++++++++++++++++++ .../Zx6718RealTimeClockLib/Zx296718RealTimeClock.h | 102 ++++++ .../Zx296718RealTimeClock.inf | 42 +++ 3 files changed, 520 insertions(+) create mode 100644 Silicon/Sanchip/Library/Zx6718RealTimeClockLib/Zx296718RealTimeClock.c create mode 100644 Silicon/Sanchip/Library/Zx6718RealTimeClockLib/Zx296718RealTimeClock.h create mode 100644 Silicon/Sanchip/Library/Zx6718RealTimeClockLib/Zx296718RealTimeClock.inf
diff --git a/Silicon/Sanchip/Library/Zx6718RealTimeClockLib/Zx296718RealTimeClock.c b/Silicon/Sanchip/Library/Zx6718RealTimeClockLib/Zx296718RealTimeClock.c new file mode 100644 index 0000000..af6e5bd --- /dev/null +++ b/Silicon/Sanchip/Library/Zx6718RealTimeClockLib/Zx296718RealTimeClock.c @@ -0,0 +1,376 @@ +/** @file
- Implement EFI RealTimeClock runtime services via RTC Lib.
- Currently this driver does not support runtime virtual calling.
- Copyright (C) 2017 Sanechips Technology Co., Ltd.
- Copyright (c) 2017, Linaro Limited.
- 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
- http://opensource.org/licenses/bsd-license.php
- THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
- WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
- Based on the files under ArmPlatformPkg/Library/PL031RealTimeClockLib/PL031RealTimeClockLib.inf
+**/
+#include <Uefi.h> +#include <PiDxe.h>
P before U.
+#include <Library/BaseLib.h> +#include <Library/BaseMemoryLib.h> +#include <Library/DebugLib.h> +#include <Library/IoLib.h> +#include <Library/MemoryAllocationLib.h> +#include <Library/PcdLib.h> +#include <Library/TimerLib.h> +#include <Library/UefiBootServicesTableLib.h> +#include <Library/UefiLib.h> +#include <Library/UefiRuntimeServicesTableLib.h> +// Use EfiAtRuntime to check stage +#include <Library/UefiRuntimeLib.h>
L (UefiRuntimeLib) before S (UefiRuntimeServices...). No need for a comment explaining why we include headers.
+#include <Protocol/RealTimeClock.h> +#include "Zx296718RealTimeClock.h"
+STATIC UINTN RtcBase;
mRtcBase.
+STATIC BOOLEAN RTCInitialized = FALSE;
mRTCInitialized.
+BOOLEAN +EFIAPI +IsTimeValid(
- IN EFI_TIME *Time
- )
+{
- // Check the input parameters are within the range specified by UEFI
- if ((Time->Year < 2000) ||
(Time->Year > 2099) ||
(Time->Month < 1 ) ||
(Time->Month > 12 ) ||
(Time->Day < 1 ) ||
(Time->Day > 31 ) ||
(Time->Hour > 23 ) ||
(Time->Minute > 59 ) ||
(Time->Second > 59 ) ||
(Time->Nanosecond > 999999999) ||
(!((Time->TimeZone == EFI_UNSPECIFIED_TIMEZONE) || ((Time->TimeZone >= -1440) && (Time->TimeZone <= 1440)))) ||
(Time->Daylight & (~(EFI_TIME_ADJUST_DAYLIGHT | EFI_TIME_IN_DAYLIGHT)))
- ) {
- return FALSE;
- }
- return TRUE;
+}
This appears a direct copy of the version in EmbeddedPkg/Library/TimeBaseLib. Can you add that TimeBaseLib library dependency to decrease duplication? (This may not have existed as a standalone library at the time you started this port.)
+VOID
A lot of the functions in this file could do with a STATIC prefix, since they are only used internally.
+Wait4Busy (
Semantically, this name is incorrect. The function is waiting _while_ the state is RTC_BUSY, so seems to me it should be called WaitBusy.
- VOID
- )
+{
- UINT32 Val, Retry = 1000;
- do {
- MicroSecondDelay (200);
Why 200?
It is just a suggested delay time according to RTC clock frequency. You want a RTC_WAIT_DELAY macro here for better understanding, right?
That would be more clear, yes. It is also good if next to that definition there is some description of how the value was detemined. (I.e., are we waiting for a particular number of cycles, or is this simply a determined to be "good enough".)
/ Leif