]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Universal/Metronome/Metronome.c
Update the copyright notice format
[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
e5eed7d3
HT
14Copyright (c) 2008, Intel Corporation. All rights reserved.<BR>\r
15This program and the accompanying materials \r
045c8b9a 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
96268f28 25#include "Metronome.h"\r
26\r
fbfd91e6 27//\r
28// Handle for the Metronome Architectural Protocol instance produced by this driver\r
29//\r
30EFI_HANDLE mMetronomeHandle = NULL;\r
31\r
32//\r
33// The Metronome Architectural Protocol instance produced by this driver\r
34//\r
35EFI_METRONOME_ARCH_PROTOCOL mMetronome = {\r
36 WaitForTick,\r
9738656b 37 1 // TickPeriod = 1*100 ns units\r
fbfd91e6 38};\r
39\r
40/**\r
92733d45 41 Waits for the specified number of ticks.\r
42 \r
43 This function implements EFI_METRONOME_ARCH_PROTOCOL.WaitForTick().\r
fbfd91e6 44 The WaitForTick() function waits for the number of ticks specified by \r
45 TickNumber from a known time source in the platform. If TickNumber of \r
46 ticks are detected, then EFI_SUCCESS is returned. The actual time passed \r
47 between entry of this function and the first tick is between 0 and \r
48 TickPeriod 100 nS units. If you want to guarantee that at least TickPeriod \r
49 time has elapsed, wait for two ticks. This function waits for a hardware \r
50 event to determine when a tick occurs. It is possible for interrupt \r
51 processing, or exception processing to interrupt the execution of the \r
52 WaitForTick() function. Depending on the hardware source for the ticks, it \r
53 is possible for a tick to be missed. This function cannot guarantee that \r
54 ticks will not be missed. If a timeout occurs waiting for the specified \r
55 number of ticks, then EFI_TIMEOUT is returned.\r
56\r
57 @param This The EFI_METRONOME_ARCH_PROTOCOL instance.\r
58 @param TickNumber Number of ticks to wait.\r
59\r
60 @retval EFI_SUCCESS The wait for the number of ticks specified by TickNumber\r
61 succeeded.\r
62 @retval EFI_TIMEOUT A timeout occurred waiting for the specified number of ticks.\r
63\r
64**/\r
65EFI_STATUS\r
66EFIAPI\r
67WaitForTick (\r
68 IN EFI_METRONOME_ARCH_PROTOCOL *This,\r
69 IN UINT32 TickNumber\r
70 )\r
71{\r
72 //\r
73 // Check the value of TickNumber, so a 32-bit overflow can be avoided\r
74 // when TickNumber of converted to nanosecond units\r
75 //\r
76 if (TickNumber < 10000000) {\r
77 //\r
78 // If TickNumber is small, then use NanoSecondDelay()\r
79 //\r
80 NanoSecondDelay (TickNumber * 100);\r
81 } else {\r
82 //\r
83 // If TickNumber is large, then use MicroSecondDelay()\r
84 //\r
85 MicroSecondDelay (TickNumber / 10);\r
86 }\r
87 return EFI_SUCCESS;\r
88}\r
89\r
90/**\r
91 The user Entry Point for module Metronome. The user code starts with this function.\r
92\r
93 @param[in] ImageHandle The firmware allocated handle for the EFI image. \r
94 @param[in] SystemTable A pointer to the EFI System Table.\r
95 \r
96 @retval EFI_SUCCESS The entry point is executed successfully.\r
97 @retval other Some error occurs when executing this entry point.\r
98\r
99**/\r
100EFI_STATUS\r
101EFIAPI\r
102InstallMetronome (\r
103 IN EFI_HANDLE ImageHandle,\r
104 IN EFI_SYSTEM_TABLE *SystemTable\r
105 )\r
106{\r
107 EFI_STATUS Status;\r
108\r
109 //\r
110 // Make sure the Metronome Architectural Protocol is not already installed in the system\r
111 //\r
112 ASSERT_PROTOCOL_ALREADY_INSTALLED (NULL, &gEfiMetronomeArchProtocolGuid);\r
113\r
114 //\r
115 // Install on a new handle\r
116 //\r
117 Status = gBS->InstallMultipleProtocolInterfaces (\r
118 &mMetronomeHandle,\r
119 &gEfiMetronomeArchProtocolGuid, &mMetronome,\r
120 NULL\r
121 );\r
122 ASSERT_EFI_ERROR (Status);\r
123\r
124 return Status;\r
125}\r