]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Universal/Metronome/Metronome.c
1, Add missing header file reference in source code section
[mirror_edk2.git] / MdeModulePkg / Universal / Metronome / Metronome.c
CommitLineData
045c8b9a 1/** @file\r
2 Produces the Metronome Architectural Protocol on top of Timer Library.\r
fbfd91e6 3\r
4 This is a generic implementation of the Metronome Architectural Protocol that\r
5 layers on top of an instance of the Timer Library. The Timer Library provides\r
6 functions for nanosecond and microsecond delays. This generic implementation\r
7 produces a fixed TickPeriod of 1 100ns unit, and when the WaitForTick() service\r
8 is called, the number of ticks passed in is converted to either nanosecond or\r
9 microsecond units. If the number of ticks is small, then nanoseconds are used.\r
10 If the number of ticks is large, then microseconds are used. This prevents\r
11 overflows that could occur for long delays if only nanoseconds were used and also\r
12 provides the greatest accuracy for small delays. \r
13\r
045c8b9a 14Copyright (c) 2008, Intel Corporation \r
15All rights reserved. This program and the accompanying materials \r
16are licensed and made available under the terms and conditions of the BSD License \r
17which accompanies this distribution. The full text of the license may be found at \r
18http://opensource.org/licenses/bsd-license.php \r
19 \r
20THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r
21WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. \r
22\r
23**/\r
fbfd91e6 24\r
25#include <PiDxe.h>\r
26#include <Protocol/Metronome.h>\r
27#include <Library/UefiBootServicesTableLib.h>\r
28#include <Library/TimerLib.h>\r
29#include <Library/DebugLib.h>\r
30\r
31//\r
32// Function Prototypes\r
33//\r
34EFI_STATUS\r
35EFIAPI\r
36WaitForTick (\r
37 IN EFI_METRONOME_ARCH_PROTOCOL *This,\r
38 IN UINT32 TickNumber\r
39 );\r
40\r
41//\r
42// Handle for the Metronome Architectural Protocol instance produced by this driver\r
43//\r
44EFI_HANDLE mMetronomeHandle = NULL;\r
45\r
46//\r
47// The Metronome Architectural Protocol instance produced by this driver\r
48//\r
49EFI_METRONOME_ARCH_PROTOCOL mMetronome = {\r
50 WaitForTick,\r
51 1 // TickPeriod = 1*100 ns units\r
52};\r
53\r
54/**\r
55 The WaitForTick() function waits for the number of ticks specified by \r
56 TickNumber from a known time source in the platform. If TickNumber of \r
57 ticks are detected, then EFI_SUCCESS is returned. The actual time passed \r
58 between entry of this function and the first tick is between 0 and \r
59 TickPeriod 100 nS units. If you want to guarantee that at least TickPeriod \r
60 time has elapsed, wait for two ticks. This function waits for a hardware \r
61 event to determine when a tick occurs. It is possible for interrupt \r
62 processing, or exception processing to interrupt the execution of the \r
63 WaitForTick() function. Depending on the hardware source for the ticks, it \r
64 is possible for a tick to be missed. This function cannot guarantee that \r
65 ticks will not be missed. If a timeout occurs waiting for the specified \r
66 number of ticks, then EFI_TIMEOUT is returned.\r
67\r
68 @param This The EFI_METRONOME_ARCH_PROTOCOL instance.\r
69 @param TickNumber Number of ticks to wait.\r
70\r
71 @retval EFI_SUCCESS The wait for the number of ticks specified by TickNumber\r
72 succeeded.\r
73 @retval EFI_TIMEOUT A timeout occurred waiting for the specified number of ticks.\r
74\r
75**/\r
76EFI_STATUS\r
77EFIAPI\r
78WaitForTick (\r
79 IN EFI_METRONOME_ARCH_PROTOCOL *This,\r
80 IN UINT32 TickNumber\r
81 )\r
82{\r
83 //\r
84 // Check the value of TickNumber, so a 32-bit overflow can be avoided\r
85 // when TickNumber of converted to nanosecond units\r
86 //\r
87 if (TickNumber < 10000000) {\r
88 //\r
89 // If TickNumber is small, then use NanoSecondDelay()\r
90 //\r
91 NanoSecondDelay (TickNumber * 100);\r
92 } else {\r
93 //\r
94 // If TickNumber is large, then use MicroSecondDelay()\r
95 //\r
96 MicroSecondDelay (TickNumber / 10);\r
97 }\r
98 return EFI_SUCCESS;\r
99}\r
100\r
101/**\r
102 The user Entry Point for module Metronome. The user code starts with this function.\r
103\r
104 @param[in] ImageHandle The firmware allocated handle for the EFI image. \r
105 @param[in] SystemTable A pointer to the EFI System Table.\r
106 \r
107 @retval EFI_SUCCESS The entry point is executed successfully.\r
108 @retval other Some error occurs when executing this entry point.\r
109\r
110**/\r
111EFI_STATUS\r
112EFIAPI\r
113InstallMetronome (\r
114 IN EFI_HANDLE ImageHandle,\r
115 IN EFI_SYSTEM_TABLE *SystemTable\r
116 )\r
117{\r
118 EFI_STATUS Status;\r
119\r
120 //\r
121 // Make sure the Metronome Architectural Protocol is not already installed in the system\r
122 //\r
123 ASSERT_PROTOCOL_ALREADY_INSTALLED (NULL, &gEfiMetronomeArchProtocolGuid);\r
124\r
125 //\r
126 // Install on a new handle\r
127 //\r
128 Status = gBS->InstallMultipleProtocolInterfaces (\r
129 &mMetronomeHandle,\r
130 &gEfiMetronomeArchProtocolGuid, &mMetronome,\r
131 NULL\r
132 );\r
133 ASSERT_EFI_ERROR (Status);\r
134\r
135 return Status;\r
136}\r