3 Copyright (c) 2005, Intel Corporation
4 All rights reserved. This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
18 This is a generic implementation of the Metronome Architectural Protocol that
19 layers on top of an instance of the Timer Library. The Timer Library provides
20 functions for nanosecond and microsecond delays. This generic implementation
21 produces a fixed TickPeriod of 1 100ns unit, and when the WaitForTick() service
22 is called, the number of ticks passed in is converted to either nanosecond or
23 microsecond units. If the number of ticks is small, then nanoseconds are used.
24 If the number of ticks is large, then microseconds are used. This prevents
25 overflows that could occur for long delays if only nanoseconds were used and also
26 provides the greatest accuracy for small delays.
31 #include <Protocol/Metronome.h>
32 #include <Library/UefiBootServicesTableLib.h>
33 #include <Library/TimerLib.h>
34 #include <Library/DebugLib.h>
37 // Function Prototypes
42 IN EFI_METRONOME_ARCH_PROTOCOL
*This
,
47 // Handle for the Metronome Architectural Protocol instance produced by this driver
49 EFI_HANDLE mMetronomeHandle
= NULL
;
52 // The Metronome Architectural Protocol instance produced by this driver
54 EFI_METRONOME_ARCH_PROTOCOL mMetronome
= {
56 1 // TickPeriod = 1*100 ns units
60 The WaitForTick() function waits for the number of ticks specified by
61 TickNumber from a known time source in the platform. If TickNumber of
62 ticks are detected, then EFI_SUCCESS is returned. The actual time passed
63 between entry of this function and the first tick is between 0 and
64 TickPeriod 100 nS units. If you want to guarantee that at least TickPeriod
65 time has elapsed, wait for two ticks. This function waits for a hardware
66 event to determine when a tick occurs. It is possible for interrupt
67 processing, or exception processing to interrupt the execution of the
68 WaitForTick() function. Depending on the hardware source for the ticks, it
69 is possible for a tick to be missed. This function cannot guarantee that
70 ticks will not be missed. If a timeout occurs waiting for the specified
71 number of ticks, then EFI_TIMEOUT is returned.
73 @param This The EFI_METRONOME_ARCH_PROTOCOL instance.
74 @param TickNumber Number of ticks to wait.
76 @retval EFI_SUCCESS The wait for the number of ticks specified by TickNumber
78 @retval EFI_TIMEOUT A timeout occurred waiting for the specified number of ticks.
84 IN EFI_METRONOME_ARCH_PROTOCOL
*This
,
89 // Check the value of TickNumber, so a 32-bit overflow can be avoided
90 // when TickNumber of converted to nanosecond units
92 if (TickNumber
< 10000000) {
94 // If TickNumber is small, then use NanoSecondDelay()
96 NanoSecondDelay (TickNumber
* 100);
99 // If TickNumber is large, then use MicroSecondDelay()
101 MicroSecondDelay (TickNumber
/ 10);
107 The user Entry Point for module Metronome. The user code starts with this function.
109 @param[in] ImageHandle The firmware allocated handle for the EFI image.
110 @param[in] SystemTable A pointer to the EFI System Table.
112 @retval EFI_SUCCESS The entry point is executed successfully.
113 @retval other Some error occurs when executing this entry point.
119 IN EFI_HANDLE ImageHandle
,
120 IN EFI_SYSTEM_TABLE
*SystemTable
126 // Make sure the Metronome Architectural Protocol is not already installed in the system
128 ASSERT_PROTOCOL_ALREADY_INSTALLED (NULL
, &gEfiMetronomeArchProtocolGuid
);
131 // Install on a new handle
133 Status
= gBS
->InstallMultipleProtocolInterfaces (
135 &gEfiMetronomeArchProtocolGuid
, &mMetronome
,
138 ASSERT_EFI_ERROR (Status
);