1 | /* Timer for Blackfin |
---|
2 | * |
---|
3 | * This file manages the benchmark timer used by the RTEMS Timing Test |
---|
4 | * Suite. Each measured time period is demarcated by calls to |
---|
5 | * benchmark_timer_initialize() and benchmark_timer_read(). benchmark_timer_read() usually returns |
---|
6 | * the number of microseconds since benchmark_timer_initialize() exitted. |
---|
7 | * |
---|
8 | * Copyright (c) 2006 by Atos Automacao Industrial Ltda. |
---|
9 | * written by Alain Schaefer <alain.schaefer@easc.ch> |
---|
10 | * and Antonio Giovanini <antonio@atos.com.br> |
---|
11 | * |
---|
12 | * The license and distribution terms for this file may be |
---|
13 | * found in the file LICENSE in this distribution or at |
---|
14 | * http://www.rtems.com/license/LICENSE. |
---|
15 | * |
---|
16 | * $Id$ |
---|
17 | */ |
---|
18 | |
---|
19 | |
---|
20 | #include <rtems.h> |
---|
21 | #include <bsp.h> |
---|
22 | |
---|
23 | |
---|
24 | uint32_t Timer_interrupts; |
---|
25 | bool benchmark_timer_find_average_overhead; |
---|
26 | |
---|
27 | /* |
---|
28 | * benchmark_timer_initialize |
---|
29 | * |
---|
30 | * Blackfin processor has a counter for clock cycles. |
---|
31 | */ |
---|
32 | void benchmark_timer_initialize( void ) |
---|
33 | { |
---|
34 | |
---|
35 | /*reset counters*/ |
---|
36 | __asm__ ("R2 = 0;"); |
---|
37 | __asm__ ("CYCLES = R2;"); |
---|
38 | __asm__ ("CYCLES2 = R2;"); |
---|
39 | /*start counters*/ |
---|
40 | __asm__ ("R2 = SYSCFG;"); |
---|
41 | __asm__ ("BITSET(R2,1);"); |
---|
42 | __asm__ ("SYSCFG = R2"); |
---|
43 | |
---|
44 | } |
---|
45 | |
---|
46 | /* |
---|
47 | * The following controls the behavior of benchmark_timer_read(). |
---|
48 | * |
---|
49 | * AVG_OVEREHAD is the overhead for starting and stopping the timer. It |
---|
50 | * is usually deducted from the number returned. |
---|
51 | * |
---|
52 | * LEAST_VALID is the lowest number this routine should trust. Numbers |
---|
53 | * below this are "noise" and zero is returned. |
---|
54 | */ |
---|
55 | |
---|
56 | #define AVG_OVERHEAD 0 /* It typically takes X.X microseconds */ |
---|
57 | /* (Y countdowns) to start/stop the timer. */ |
---|
58 | /* This value is in microseconds. */ |
---|
59 | #define LEAST_VALID 1 /* Don't trust a clicks value lower than this */ |
---|
60 | |
---|
61 | int benchmark_timer_read( void ) |
---|
62 | { |
---|
63 | uint32_t clicks; |
---|
64 | uint32_t total; |
---|
65 | register uint32_t cycles __asm__ ("R2"); |
---|
66 | |
---|
67 | /* stop counter */ |
---|
68 | __asm__ ("R2 = SYSCFG;"); |
---|
69 | __asm__ ("BITCLR(R2,1);"); |
---|
70 | __asm__ ("SYSCFG = R2;"); |
---|
71 | __asm__ ("R2 = CYCLES;"); |
---|
72 | |
---|
73 | |
---|
74 | clicks = cycles; /* Clock cycles */ |
---|
75 | |
---|
76 | /* converting to microseconds */ |
---|
77 | total = clicks / (CCLK/1000000); |
---|
78 | |
---|
79 | if ( benchmark_timer_find_average_overhead == 1 ) |
---|
80 | return total; /* in XXX microsecond units */ |
---|
81 | else { |
---|
82 | if ( total < LEAST_VALID ) |
---|
83 | return 0; /* below timer resolution */ |
---|
84 | /* |
---|
85 | * Somehow convert total into microseconds |
---|
86 | */ |
---|
87 | return (total - AVG_OVERHEAD); |
---|
88 | } |
---|
89 | } |
---|
90 | |
---|
91 | void benchmark_timer_disable_subtracting_average_overhead(bool find_flag) |
---|
92 | { |
---|
93 | benchmark_timer_find_average_overhead = find_flag; |
---|
94 | } |
---|