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