|
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 * ne1_tb\nktest\hw_init.cia |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 |
|
21 #include <arm.h> |
|
22 #include <nkutils.h> |
|
23 #include <diag.h> |
|
24 |
|
25 #ifdef __SMP__ |
|
26 #include <arm_gic.h> |
|
27 #endif |
|
28 |
|
29 |
|
30 /****************************************************************************** |
|
31 * Fast counter |
|
32 ******************************************************************************/ |
|
33 extern "C" __NAKED__ TUint64 fast_counter() |
|
34 { |
|
35 // Return a 64 bit high resolution timestamp count |
|
36 // Timer 1 counts from 00000000 to FFFFFEFF and then wraps back to 0 |
|
37 // Timer 2 counts from 00000000 to FFFFFFFF and then wraps back to 0 |
|
38 // Both timers increment at 16.667MHz (60ns period) |
|
39 // Algorithm: |
|
40 // volatile TUint32 t2 = Timer2Count; // must read t2 first |
|
41 // volatile TUint32 t1 = Timer1Count; |
|
42 // TUint32 n = (t1-t2)>>8; // number of times T1 has wrapped |
|
43 // return t1 + n * 0xFFFFFF00; |
|
44 |
|
45 asm("ldr r3, 1f "); // r3 = address of T1 counter |
|
46 asm("mrs r12, cpsr "); |
|
47 __ASM_CLI(); // interrupts off |
|
48 asm("ldr r1, [r3, #0x400] "); // r1 = t2 |
|
49 asm("ldr r0, [r3] "); // r0 = t1 |
|
50 asm("msr cpsr, r12 "); // restore interrupts |
|
51 asm("sub r1, r0, r1 "); // t1-t2 |
|
52 asm("mov r1, r1, lsr #8 "); // n = (t1-t2)>>8, now have r1:r0 = 2^32*n + t1 |
|
53 asm("subs r0, r0, r1, lsl #8 "); // subtract 256*n |
|
54 asm("sbcs r1, r1, #0 "); // propagate borrow |
|
55 __JUMP(,lr); |
|
56 |
|
57 asm("1: "); |
|
58 asm(".word 0x18036400 "); // address of timer 1 counter |
|
59 } |
|
60 |
|
61 extern "C" __NAKED__ TUint64 fast_counter_x(TUint32*) |
|
62 { |
|
63 // Return a 64 bit high resolution timestamp count |
|
64 // Timer 1 counts from 00000000 to FFFFFEFF and then wraps back to 0 |
|
65 // Timer 2 counts from 00000000 to FFFFFFFF and then wraps back to 0 |
|
66 // Both timers increment at 16.667MHz (60ns period) |
|
67 // Algorithm: |
|
68 // volatile TUint32 t1 = Timer1Count; |
|
69 // volatile TUint32 t2 = Timer2Count; |
|
70 // TUint32 n = (t1-t2)>>8; // number of times T1 has wrapped |
|
71 // return t1 + n * 0xFFFFFF00; |
|
72 |
|
73 asm("ldr r3, 1f "); // r3 = address of T1 counter |
|
74 asm("mov r2, r0 "); |
|
75 asm("mrs r12, cpsr "); |
|
76 __ASM_CLI(); // interrupts off |
|
77 asm("ldr r1, [r3, #0x400] "); // r1 = t2 |
|
78 asm("ldr r0, [r3] "); // r0 = t1 |
|
79 asm("msr cpsr, r12 "); // restore interrupts |
|
80 asm("stmia r2, {r0,r1} "); |
|
81 asm("sub r1, r0, r1 "); // t1-t2 |
|
82 asm("mov r1, r1, lsr #8 "); // n = (t1-t2)>>8, now have r1:r0 = 2^32*n + t1 |
|
83 asm("subs r0, r0, r1, lsl #8 "); // subtract 256*n |
|
84 asm("sbcs r1, r1, #0 "); // propagate borrow |
|
85 __JUMP(,lr); |
|
86 |
|
87 asm("1: "); |
|
88 asm(".word 0x18036400 "); // address of timer 1 counter |
|
89 } |