1 | /* |
---|
2 | * This file implements a benchmark timer using a TX39 timer. |
---|
3 | * |
---|
4 | * NOTE: On the simulator, the count directly reflects instructions. |
---|
5 | * |
---|
6 | * COPYRIGHT (c) 1989-2000. |
---|
7 | * On-Line Applications Research Corporation (OAR). |
---|
8 | * |
---|
9 | * The license and distribution terms for this file may be |
---|
10 | * found in the file LICENSE in this distribution or at |
---|
11 | * http://www.rtems.org/license/LICENSE. |
---|
12 | */ |
---|
13 | |
---|
14 | #include <assert.h> |
---|
15 | |
---|
16 | #include <bsp.h> |
---|
17 | #include <rtems/btimer.h> |
---|
18 | |
---|
19 | bool benchmark_timer_find_average_overhead; |
---|
20 | |
---|
21 | void benchmark_timer_initialize(void) |
---|
22 | { |
---|
23 | /* |
---|
24 | * Programming the compare register as the maximum value should let |
---|
25 | * it run long enough and accurate enough not to require an interrupt. |
---|
26 | * but if it ever does generate an interrupt, we will simply fault. |
---|
27 | * |
---|
28 | * NOTE: This is similar to the clock driver initialization |
---|
29 | * with the exception that the divider is disabled and |
---|
30 | * the compare register is set to the maximum value. |
---|
31 | */ |
---|
32 | |
---|
33 | TX3904_TIMER_WRITE( TX3904_TIMER1_BASE, TX3904_TIMER_TCR, 0x20 ); |
---|
34 | TX3904_TIMER_WRITE( TX3904_TIMER1_BASE, TX3904_TIMER_CCDR, 0x3 ); |
---|
35 | TX3904_TIMER_WRITE( TX3904_TIMER1_BASE, TX3904_TIMER_TRR, 0x0 ); |
---|
36 | TX3904_TIMER_WRITE( TX3904_TIMER1_BASE, TX3904_TIMER_CPRA, 0xFFFFFFFF ); |
---|
37 | TX3904_TIMER_WRITE( TX3904_TIMER1_BASE, TX3904_TIMER_TISR, 0x00 ); |
---|
38 | TX3904_TIMER_WRITE( TX3904_TIMER1_BASE, TX3904_TIMER_ITMR, 0x0001 ); |
---|
39 | TX3904_TIMER_WRITE( TX3904_TIMER1_BASE, TX3904_TIMER_TCR, 0xe0 ); |
---|
40 | } |
---|
41 | |
---|
42 | #define AVG_OVERHEAD 0 /* It typically takes N instructions */ |
---|
43 | /* to start/stop the timer. */ |
---|
44 | #define LEAST_VALID 1 /* Don't trust a value lower than this */ |
---|
45 | /* tx39 simulator can count instructions. :) */ |
---|
46 | |
---|
47 | uint32_t benchmark_timer_read(void) |
---|
48 | { |
---|
49 | uint32_t total; |
---|
50 | |
---|
51 | total = TX3904_TIMER_READ( TX3904_TIMER1_BASE, TX3904_TIMER_TRR ); |
---|
52 | |
---|
53 | if ( benchmark_timer_find_average_overhead == true ) |
---|
54 | return total; /* in one microsecond units */ |
---|
55 | |
---|
56 | if ( total < LEAST_VALID ) |
---|
57 | return 0; /* below timer resolution */ |
---|
58 | |
---|
59 | return total - AVG_OVERHEAD; |
---|
60 | } |
---|
61 | |
---|
62 | void benchmark_timer_disable_subtracting_average_overhead( |
---|
63 | bool find_flag |
---|
64 | ) |
---|
65 | { |
---|
66 | benchmark_timer_find_average_overhead = find_flag; |
---|
67 | } |
---|