3 Copyright (c) 2008-2009, Apple Inc. All rights reserved.
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
17 #include <Library/BaseLib.h>
18 #include <Library/TimerLib.h>
19 #include <Library/DebugLib.h>
20 #include <Library/PcdLib.h>
21 #include <Library/IoLib.h>
22 #include <Library/OmapLib.h>
24 #include <Omap3530/Omap3530.h>
34 NanoSeconds
= MultU64x32(MicroSeconds
, 1000);
36 while (NanoSeconds
> (UINTN
)-1) {
37 NanoSecondDelay((UINTN
)-1);
38 NanoSeconds
-= (UINTN
)-1;
41 NanoSecondDelay(NanoSeconds
);
56 UINT32 TimerCountRegister
;
58 Delay
= (NanoSeconds
/ PcdGet32(PcdEmbeddedFdPerformanceCounterPeriodInNanoseconds
)) + 1;
60 TimerCountRegister
= TimerBase(PcdGet32(PcdOmap35xxFreeTimer
)) + GPTIMER_TCRR
;
62 StartTime
= MmioRead32 (TimerCountRegister
);
66 CurrentTime
= MmioRead32 (TimerCountRegister
);
67 ElapsedTime
= CurrentTime
- StartTime
;
68 } while (ElapsedTime
< Delay
);
70 NanoSeconds
= ElapsedTime
* PcdGet32(PcdEmbeddedFdPerformanceCounterPeriodInNanoseconds
);
77 GetPerformanceCounter (
81 return (UINT64
)MmioRead32 (TimerBase(PcdGet32(PcdOmap35xxFreeTimer
)) + GPTIMER_TCRR
);
86 GetPerformanceCounterProperties (
87 OUT UINT64
*StartValue
, OPTIONAL
88 OUT UINT64
*EndValue OPTIONAL
91 if (StartValue
!= NULL
) {
92 // Timer starts with the reload value
93 *StartValue
= (UINT64
)MmioRead32 (TimerBase(PcdGet32(PcdOmap35xxFreeTimer
)) + GPTIMER_TLDR
);
96 if (EndValue
!= NULL
) {
97 // Timer counts up to 0xFFFFFFFF
98 *EndValue
= 0xFFFFFFFF;
101 return PcdGet64(PcdEmbeddedPerformanceCounterFreqencyInHz
);