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