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