1 | /* |
---|
2 | * This file implements a benchmark timer using a MONGOOSE-V 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 | #if defined(USE_TIMER2_FOR_CLOCK) |
---|
23 | #define TIMER_BASE MONGOOSEV_TIMER1_BASE |
---|
24 | #define TIMER_VECTOR MONGOOSEV_IRQ_TIMER1 |
---|
25 | #else |
---|
26 | #define TIMER_BASE MONGOOSEV_TIMER2_BASE |
---|
27 | #define TIMER_VECTOR MONGOOSEV_IRQ_TIMER2 |
---|
28 | #endif |
---|
29 | |
---|
30 | void Timer_initialize() |
---|
31 | { |
---|
32 | /* |
---|
33 | * Programming the compare register as the maximum value should let |
---|
34 | * it run long enough and accurate enough not to require an interrupt. |
---|
35 | * but if it ever does generate an interrupt, we will simply fault. |
---|
36 | * |
---|
37 | * NOTE: This is similar to the clock driver initialization |
---|
38 | * with the exception that the divider is disabled and |
---|
39 | * the compare register is set to the maximum value. |
---|
40 | */ |
---|
41 | |
---|
42 | MONGOOSEV_WRITE_REGISTER( |
---|
43 | TIMER_BASE, |
---|
44 | MONGOOSEV_TIMER_INITIAL_COUNTER_REGISTER, |
---|
45 | 0xffffffff |
---|
46 | ); |
---|
47 | MONGOOSEV_WRITE_REGISTER( |
---|
48 | TIMER_BASE, |
---|
49 | MONGOOSEV_TIMER_CONTROL_REGISTER, |
---|
50 | MONGOOSEV_TIMER_CONTROL_COUNTER_ENABLE |
---|
51 | ); |
---|
52 | } |
---|
53 | |
---|
54 | #define AVG_OVERHEAD 0 /* It typically takes N instructions */ |
---|
55 | /* to start/stop the timer. */ |
---|
56 | #define LEAST_VALID 1 /* Don't trust a value lower than this */ |
---|
57 | /* mongoose-v can count cycles. :) */ |
---|
58 | #include <bspIo.h> |
---|
59 | |
---|
60 | int Read_timer() |
---|
61 | { |
---|
62 | rtems_unsigned32 clicks; |
---|
63 | rtems_unsigned32 total; |
---|
64 | rtems_unsigned32 tcr; |
---|
65 | |
---|
66 | clicks = MONGOOSEV_READ_REGISTER( |
---|
67 | TIMER_BASE, |
---|
68 | MONGOOSEV_TIMER_INITIAL_COUNTER_REGISTER |
---|
69 | ); |
---|
70 | total = 0xffffffff - clicks; |
---|
71 | |
---|
72 | tcr = MONGOOSEV_READ_REGISTER( TIMER_BASE, MONGOOSEV_TIMER_CONTROL_REGISTER ); |
---|
73 | if ( tcr & MONGOOSEV_TIMER_CONTROL_TIMEOUT ) |
---|
74 | printk( "MG5 timer overran\n" ); |
---|
75 | |
---|
76 | if ( Timer_driver_Find_average_overhead == 1 ) |
---|
77 | return total; /* in cycle units */ |
---|
78 | |
---|
79 | if ( total < LEAST_VALID ) |
---|
80 | return 0; /* below timer resolution */ |
---|
81 | |
---|
82 | return total - AVG_OVERHEAD; |
---|
83 | } |
---|
84 | |
---|
85 | rtems_status_code Empty_function( void ) |
---|
86 | { |
---|
87 | return RTEMS_SUCCESSFUL; |
---|
88 | } |
---|
89 | |
---|
90 | void Set_find_average_overhead( |
---|
91 | rtems_boolean find_flag |
---|
92 | ) |
---|
93 | { |
---|
94 | Timer_driver_Find_average_overhead = find_flag; |
---|
95 | } |
---|