|
1 /* |
|
2 * Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * The frequency of the system timestamp counter in Hz |
|
16 * The timestamp counter is a 64 bit value which is required to increment at a |
|
17 * constant rate of at least 1MHz and not to wrap in any reasonable amount of time. |
|
18 * |
|
19 */ |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 const TUint32 KTimestampFrequency = 66666667u; |
|
26 |
|
27 #ifdef __DEFINE_NKERN_TIMESTAMP_ASM__ |
|
28 /* If NKern::Timestamp() is written in assembler define it here |
|
29 */ |
|
30 |
|
31 EXPORT_C __NAKED__ TUint64 NKern::Timestamp() |
|
32 { |
|
33 // Return a 64 bit high resolution timestamp count |
|
34 // Timer 1 counts from 00000000 to FFFFFEFF and then wraps back to 0 |
|
35 // Timer 2 counts from 00000000 to FFFFFFFF and then wraps back to 0 |
|
36 // Both timers increment at 66.667MHz (15ns period) |
|
37 // Algorithm: |
|
38 // volatile TUint32 t2 = Timer2Count; // must read t2 first |
|
39 // volatile TUint32 t1 = Timer1Count; |
|
40 // TUint32 n = (t1-t2)>>8; // number of times T1 has wrapped |
|
41 // return t1 + n * 0xFFFFFF00; |
|
42 |
|
43 asm("ldr r3, 1f "); // r3 = address of T1 counter |
|
44 asm("mrs r12, cpsr "); |
|
45 __ASM_CLI(); // interrupts off |
|
46 asm("ldr r1, [r3, #0x400] "); // r1 = t2 |
|
47 asm("ldr r0, [r3] "); // r0 = t1 |
|
48 asm("msr cpsr, r12 "); // restore interrupts |
|
49 asm("sub r1, r0, r1 "); // t1-t2 |
|
50 asm("mov r1, r1, lsr #8 "); // n = (t1-t2)>>8, now have r1:r0 = 2^32*n + t1 |
|
51 asm("subs r0, r0, r1, lsl #8 "); // subtract 256*n |
|
52 asm("sbcs r1, r1, #0 "); // propagate borrow |
|
53 __JUMP(,lr); |
|
54 |
|
55 asm("1: "); |
|
56 #ifdef __MEMMODEL_DIRECT__ |
|
57 asm(".word 0x18036400 "); // address of timer 1 counter |
|
58 #else |
|
59 asm(".word 0xC6003400 "); // address of timer 1 counter |
|
60 #endif |
|
61 } |
|
62 |
|
63 #endif |
|
64 |
|
65 #ifdef __DEFINE_NKERN_TIMESTAMP_CPP__ |
|
66 /* If NKern::Timestamp() is written in C++ define it here |
|
67 */ |
|
68 #endif |
|
69 |