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 found in the file LICENSE in this distribution or at |
---|
11 | * http://www.OARcorp.com/rtems/license.html. |
---|
12 | * |
---|
13 | * $Id$ |
---|
14 | */ |
---|
15 | |
---|
16 | #include <assert.h> |
---|
17 | |
---|
18 | #include <bsp.h> |
---|
19 | |
---|
20 | rtems_boolean Timer_driver_Find_average_overhead; |
---|
21 | |
---|
22 | void Timer_initialize() |
---|
23 | { |
---|
24 | /* |
---|
25 | * Programming the compare register as the maximum value should let |
---|
26 | * it run long enough and accurate enough not to require an interrupt. |
---|
27 | * but if it ever does generate an interrupt, we will simply fault. |
---|
28 | * |
---|
29 | * NOTE: This is similar to the clock driver initialization |
---|
30 | * with the exception that the divider is disabled and |
---|
31 | * the compare register is set to the maximum value. |
---|
32 | */ |
---|
33 | |
---|
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, 0x8001 ); |
---|
39 | TX3904_TIMER_WRITE( TX3904_TIMER1_BASE, TX3904_TIMER_TCR, 0x20 ); |
---|
40 | TX3904_TIMER_WRITE( TX3904_TIMER1_BASE, TX3904_TIMER_TCR, 0xe0 ); |
---|
41 | } |
---|
42 | |
---|
43 | #define AVG_OVERHEAD 0 /* It typically takes N instructions */ |
---|
44 | /* to start/stop the timer. */ |
---|
45 | #define LEAST_VALID 1 /* Don't trust a value lower than this */ |
---|
46 | /* tx39 simulator can count instructions. :) */ |
---|
47 | |
---|
48 | int Read_timer() |
---|
49 | { |
---|
50 | rtems_unsigned32 total; |
---|
51 | |
---|
52 | TX3904_TIMER_WRITE( TX3904_TIMER1_BASE, TX3904_TIMER_TCR, 0x03 ); |
---|
53 | total = TX3904_TIMER_READ( TX3904_TIMER1_BASE, TX3904_TIMER_TRR ); |
---|
54 | |
---|
55 | if ( Timer_driver_Find_average_overhead == 1 ) |
---|
56 | return total; /* in one microsecond units */ |
---|
57 | |
---|
58 | if ( total < LEAST_VALID ) |
---|
59 | return 0; /* below timer resolution */ |
---|
60 | |
---|
61 | return total - AVG_OVERHEAD; |
---|
62 | } |
---|
63 | |
---|
64 | rtems_status_code Empty_function( void ) |
---|
65 | { |
---|
66 | return RTEMS_SUCCESSFUL; |
---|
67 | } |
---|
68 | |
---|
69 | void Set_find_average_overhead( |
---|
70 | rtems_boolean find_flag |
---|
71 | ) |
---|
72 | { |
---|
73 | Timer_driver_Find_average_overhead = find_flag; |
---|
74 | } |
---|