]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ArmEbPkg/Library/TimerLib/TimerLib.c
A better template, with some build scripts, for ArmEbPkg. New libraries are just...
[mirror_edk2.git] / ArmEbPkg / Library / TimerLib / TimerLib.c
diff --git a/ArmEbPkg/Library/TimerLib/TimerLib.c b/ArmEbPkg/Library/TimerLib/TimerLib.c
new file mode 100755 (executable)
index 0000000..c2a2a90
--- /dev/null
@@ -0,0 +1,97 @@
+/** @file\r
+\r
+  Copyright (c) 2008 - 2010, Apple Inc. All rights reserved.<BR>\r
+  \r
+  This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#include <Base.h>\r
+\r
+#include <Library/BaseLib.h>\r
+#include <Library/TimerLib.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/PcdLib.h>\r
+#include <Library/IoLib.h>\r
+\r
+\r
+UINTN\r
+EFIAPI\r
+MicroSecondDelay (\r
+  IN  UINTN MicroSeconds\r
+  )\r
+{\r
+  UINT64  NanoSeconds;\r
+  \r
+  NanoSeconds = MultU64x32 (MicroSeconds, 1000);\r
+\r
+  while (NanoSeconds > (UINTN)-1) { \r
+    NanoSecondDelay((UINTN)-1);\r
+    NanoSeconds -= (UINTN)-1;\r
+  }\r
+\r
+  NanoSecondDelay (NanoSeconds);\r
+\r
+  return MicroSeconds;\r
+}\r
+\r
+UINTN\r
+EFIAPI\r
+NanoSecondDelay (\r
+  IN  UINTN NanoSeconds\r
+  )\r
+{\r
+  UINT32  Delay;\r
+  UINT32  StartTime;\r
+  UINT32  CurrentTime;\r
+  UINT32  ElapsedTime;\r
+\r
\r
+  Delay = (NanoSeconds / PcdGet32(PcdEmbeddedPerformanceCounterPeriodInNanoseconds)) + 1;\r
+\r
+  StartTime = MmioRead32 (0);\r
+  do \r
+  {\r
+    CurrentTime = 0ULL;\r
+    ElapsedTime = CurrentTime - StartTime;\r
+  } while (ElapsedTime < Delay);\r
+\r
+  NanoSeconds = ElapsedTime * PcdGet32 (PcdEmbeddedPerformanceCounterPeriodInNanoseconds);\r
+\r
+  return NanoSeconds;\r
+}\r
+\r
+UINT64\r
+EFIAPI\r
+GetPerformanceCounter (\r
+  VOID\r
+  )\r
+{ \r
+  return (UINT64)0ULL;\r
+}\r
+\r
+UINT64\r
+EFIAPI\r
+GetPerformanceCounterProperties (\r
+  OUT UINT64  *StartValue,  OPTIONAL\r
+  OUT UINT64  *EndValue     OPTIONAL\r
+  )\r
+{\r
+  if (StartValue != NULL) {\r
+    // Timer starts with the reload value\r
+    *StartValue = (UINT64)0ULL;\r
+  }\r
+  \r
+  if (EndValue != NULL) {\r
+    // Timer counts up to 0xFFFFFFFF\r
+    *EndValue = 0xFFFFFFFF;\r
+  }\r
+  \r
+  return PcdGet64(PcdEmbeddedPerformanceCounterFrequencyInHz);\r
+}\r