1 | /* |
---|
2 | * PXA255 timer by Yang Xi <hiyangxi@gmail.com> |
---|
3 | * Copyright (c) 2004 by Jay Monkman <jtm@lopingdog.com> |
---|
4 | * |
---|
5 | * Notes: |
---|
6 | * This file manages the benchmark timer used by the RTEMS Timing Test |
---|
7 | * Suite. Each measured time period is demarcated by calls to |
---|
8 | * Timer_initialize() and Read_timer(). Read_timer() usually returns |
---|
9 | * the number of microseconds since Timer_initialize() exitted. |
---|
10 | * |
---|
11 | * It is important that the timer start/stop overhead be determined |
---|
12 | * when porting or modifying this code. |
---|
13 | * |
---|
14 | * The license and distribution terms for this file may be |
---|
15 | * found in the file LICENSE in this distribution or at |
---|
16 | * http://www.rtems.com/license/LICENSE. |
---|
17 | * |
---|
18 | * $Id$ |
---|
19 | */ |
---|
20 | |
---|
21 | #include <rtems.h> |
---|
22 | #include <bsp.h> |
---|
23 | #include <pxa255.h> |
---|
24 | |
---|
25 | uint32_t tstart; |
---|
26 | static uint32_t tick_time; |
---|
27 | bool benchmark_timer_find_average_overhead; |
---|
28 | |
---|
29 | bool benchmark_timer_is_initialized = false; |
---|
30 | |
---|
31 | /* |
---|
32 | * Use the timer count register to measure. |
---|
33 | * The frequency of it is 3.4864MHZ |
---|
34 | * The longest period we are able to capture is 4G/3.4864MHZ |
---|
35 | */ |
---|
36 | void benchmark_timer_initialize(void) |
---|
37 | { |
---|
38 | tick_time = XSCALE_OS_TIMER_TCR; |
---|
39 | } |
---|
40 | |
---|
41 | /* |
---|
42 | * The following controls the behavior of Read_timer(). |
---|
43 | * |
---|
44 | * AVG_OVEREHAD is the overhead for starting and stopping the timer. It |
---|
45 | * is usually deducted from the number returned. |
---|
46 | * |
---|
47 | * LEAST_VALID is the lowest number this routine should trust. Numbers |
---|
48 | * below this are "noise" and zero is returned. |
---|
49 | */ |
---|
50 | |
---|
51 | #define AVG_OVERHEAD 0 /* It typically takes X.X microseconds */ |
---|
52 | /* (Y countdowns) to start/stop the timer. */ |
---|
53 | /* This value is in microseconds. */ |
---|
54 | #define LEAST_VALID 1 /* Don't trust a clicks value lower than this */ |
---|
55 | |
---|
56 | int benchmark_timer_read(void) |
---|
57 | { |
---|
58 | |
---|
59 | uint32_t total; |
---|
60 | total = XSCALE_OS_TIMER_TCR; |
---|
61 | if(total>=tick_time) |
---|
62 | total -= tick_time; |
---|
63 | else |
---|
64 | total += 0xffffffff - tick_time; /*Round up but not overflow*/ |
---|
65 | |
---|
66 | if ( benchmark_timer_find_average_overhead == true ) |
---|
67 | return total; /*Counter cycles*/ |
---|
68 | |
---|
69 | if ( total < LEAST_VALID ) |
---|
70 | return 0; /* below timer resolution */ |
---|
71 | |
---|
72 | return total; |
---|
73 | } |
---|
74 | |
---|
75 | void benchmark_timer_disable_subtracting_average_overhead( |
---|
76 | bool find_flag |
---|
77 | ) |
---|
78 | { |
---|
79 | benchmark_timer_find_average_overhead = find_flag; |
---|
80 | } |
---|