--- /dev/null
+/*++\r
+\r
+Copyright (c) 2005, Intel Corporation \r
+All rights reserved. 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
+Module Name:\r
+\r
+ Metronome.c\r
+\r
+Abstract:\r
+\r
+ This is a generic implementation of the Metronome Architectural Protocol that\r
+ layers on top of an instance of the Timer Library. The Timer Library provides\r
+ functions for nanosecond and microsecond delays. This generic implementation\r
+ produces a fixed TickPeriod of 1 100ns unit, and when the WaitForTick() service\r
+ is called, the number of ticks passed in is converted to either nanosecond or\r
+ microsecond units. If the number of ticks is small, then nanoseconds are used.\r
+ If the number of ticks is large, then microseconds are used. This prevents\r
+ overflows that could occur for long delays if only nanoseconds were used and also\r
+ provides the greatest accuracy for small delays. \r
+\r
+--*/\r
+\r
+#include <PiDxe.h>\r
+#include <Protocol/Metronome.h>\r
+#include <Library/UefiBootServicesTableLib.h>\r
+#include <Library/TimerLib.h>\r
+#include <Library/DebugLib.h>\r
+\r
+//\r
+// Function Prototypes\r
+//\r
+EFI_STATUS\r
+EFIAPI\r
+WaitForTick (\r
+ IN EFI_METRONOME_ARCH_PROTOCOL *This,\r
+ IN UINT32 TickNumber\r
+ );\r
+\r
+//\r
+// Handle for the Metronome Architectural Protocol instance produced by this driver\r
+//\r
+EFI_HANDLE mMetronomeHandle = NULL;\r
+\r
+//\r
+// The Metronome Architectural Protocol instance produced by this driver\r
+//\r
+EFI_METRONOME_ARCH_PROTOCOL mMetronome = {\r
+ WaitForTick,\r
+ 1 // TickPeriod = 1*100 ns units\r
+};\r
+\r
+/**\r
+ The WaitForTick() function waits for the number of ticks specified by \r
+ TickNumber from a known time source in the platform. If TickNumber of \r
+ ticks are detected, then EFI_SUCCESS is returned. The actual time passed \r
+ between entry of this function and the first tick is between 0 and \r
+ TickPeriod 100 nS units. If you want to guarantee that at least TickPeriod \r
+ time has elapsed, wait for two ticks. This function waits for a hardware \r
+ event to determine when a tick occurs. It is possible for interrupt \r
+ processing, or exception processing to interrupt the execution of the \r
+ WaitForTick() function. Depending on the hardware source for the ticks, it \r
+ is possible for a tick to be missed. This function cannot guarantee that \r
+ ticks will not be missed. If a timeout occurs waiting for the specified \r
+ number of ticks, then EFI_TIMEOUT is returned.\r
+\r
+ @param This The EFI_METRONOME_ARCH_PROTOCOL instance.\r
+ @param TickNumber Number of ticks to wait.\r
+\r
+ @retval EFI_SUCCESS The wait for the number of ticks specified by TickNumber\r
+ succeeded.\r
+ @retval EFI_TIMEOUT A timeout occurred waiting for the specified number of ticks.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+WaitForTick (\r
+ IN EFI_METRONOME_ARCH_PROTOCOL *This,\r
+ IN UINT32 TickNumber\r
+ )\r
+{\r
+ //\r
+ // Check the value of TickNumber, so a 32-bit overflow can be avoided\r
+ // when TickNumber of converted to nanosecond units\r
+ //\r
+ if (TickNumber < 10000000) {\r
+ //\r
+ // If TickNumber is small, then use NanoSecondDelay()\r
+ //\r
+ NanoSecondDelay (TickNumber * 100);\r
+ } else {\r
+ //\r
+ // If TickNumber is large, then use MicroSecondDelay()\r
+ //\r
+ MicroSecondDelay (TickNumber / 10);\r
+ }\r
+ return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+ The user Entry Point for module Metronome. The user code starts with this function.\r
+\r
+ @param[in] ImageHandle The firmware allocated handle for the EFI image. \r
+ @param[in] SystemTable A pointer to the EFI System Table.\r
+ \r
+ @retval EFI_SUCCESS The entry point is executed successfully.\r
+ @retval other Some error occurs when executing this entry point.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+InstallMetronome (\r
+ IN EFI_HANDLE ImageHandle,\r
+ IN EFI_SYSTEM_TABLE *SystemTable\r
+ )\r
+{\r
+ EFI_STATUS Status;\r
+\r
+ //\r
+ // Make sure the Metronome Architectural Protocol is not already installed in the system\r
+ //\r
+ ASSERT_PROTOCOL_ALREADY_INSTALLED (NULL, &gEfiMetronomeArchProtocolGuid);\r
+\r
+ //\r
+ // Install on a new handle\r
+ //\r
+ Status = gBS->InstallMultipleProtocolInterfaces (\r
+ &mMetronomeHandle,\r
+ &gEfiMetronomeArchProtocolGuid, &mMetronome,\r
+ NULL\r
+ );\r
+ ASSERT_EFI_ERROR (Status);\r
+\r
+ return Status;\r
+}\r
--- /dev/null
+#/*++\r
+# \r
+# Copyright (c) 2005, Intel Corporation \r
+# All rights reserved. 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
+# Module Name:\r
+#\r
+# Abstract:\r
+#\r
+#--*/\r
+\r
+[Defines]\r
+ INF_VERSION = 0x00010005\r
+ BASE_NAME = Metronome\r
+ FILE_GUID = C8339973-A563-4561-B858-D8476F9DEFC4\r
+ MODULE_TYPE = DXE_DRIVER\r
+ VERSION_STRING = 1.0\r
+ EDK_RELEASE_VERSION = 0x00020000\r
+ EFI_SPECIFICATION_VERSION = 0x00020000\r
+ ENTRY_POINT = InstallMetronome\r
+\r
+[Packages]\r
+ MdePkg/MdePkg.dec\r
+\r
+[LibraryClasses]\r
+ UefiDriverEntryPoint\r
+ UefiBootServicesTableLib\r
+ TimerLib\r
+ DebugLib\r
+\r
+[Sources.common]\r
+ Metronome.c\r
+\r
+[Protocols]\r
+ gEfiMetronomeArchProtocolGuid\r
+\r
+[Depex]\r
+ TRUE\r