[f849f3e] | 1 | /* |
---|
| 2 | * This file implements a benchmark timer using a MONGOOSE-V timer. |
---|
| 3 | * |
---|
[ef380d3f] | 4 | * COPYRIGHT (c) 1989-2001. |
---|
[f849f3e] | 5 | * On-Line Applications Research Corporation (OAR). |
---|
| 6 | * |
---|
| 7 | * The license and distribution terms for this file may be |
---|
| 8 | * found in found in the file LICENSE in this distribution or at |
---|
[7ed0f19] | 9 | * http://www.rtems.com/license/LICENSE. |
---|
[f849f3e] | 10 | * |
---|
| 11 | * $Id$ |
---|
| 12 | */ |
---|
| 13 | |
---|
| 14 | #include <assert.h> |
---|
| 15 | |
---|
| 16 | #include <bsp.h> |
---|
| 17 | |
---|
| 18 | rtems_boolean Timer_driver_Find_average_overhead; |
---|
| 19 | |
---|
| 20 | #if defined(USE_TIMER2_FOR_CLOCK) |
---|
| 21 | #define TIMER_BASE MONGOOSEV_TIMER1_BASE |
---|
| 22 | #define TIMER_VECTOR MONGOOSEV_IRQ_TIMER1 |
---|
| 23 | #else |
---|
| 24 | #define TIMER_BASE MONGOOSEV_TIMER2_BASE |
---|
| 25 | #define TIMER_VECTOR MONGOOSEV_IRQ_TIMER2 |
---|
| 26 | #endif |
---|
| 27 | |
---|
| 28 | void Timer_initialize() |
---|
| 29 | { |
---|
| 30 | /* |
---|
| 31 | * Programming the compare register as the maximum value should let |
---|
| 32 | * it run long enough and accurate enough not to require an interrupt. |
---|
| 33 | * but if it ever does generate an interrupt, we will simply fault. |
---|
| 34 | * |
---|
| 35 | * NOTE: This is similar to the clock driver initialization |
---|
| 36 | * with the exception that the divider is disabled and |
---|
| 37 | * the compare register is set to the maximum value. |
---|
| 38 | */ |
---|
| 39 | |
---|
[a355e3ea] | 40 | MONGOOSEV_WRITE_REGISTER( TIMER_BASE, MONGOOSEV_TIMER_CONTROL_REGISTER, 0); |
---|
| 41 | |
---|
| 42 | MONGOOSEV_WRITE_REGISTER( TIMER_BASE, |
---|
| 43 | MONGOOSEV_TIMER_INITIAL_COUNTER_REGISTER, |
---|
| 44 | 0xffffffff ); |
---|
| 45 | |
---|
| 46 | MONGOOSEV_WRITE_REGISTER( TIMER_BASE, |
---|
| 47 | MONGOOSEV_TIMER_CONTROL_REGISTER, |
---|
| 48 | MONGOOSEV_TIMER_CONTROL_COUNTER_ENABLE ); |
---|
| 49 | |
---|
[f849f3e] | 50 | } |
---|
| 51 | |
---|
| 52 | #define AVG_OVERHEAD 0 /* It typically takes N instructions */ |
---|
| 53 | /* to start/stop the timer. */ |
---|
[a355e3ea] | 54 | |
---|
[f849f3e] | 55 | #define LEAST_VALID 1 /* Don't trust a value lower than this */ |
---|
| 56 | /* mongoose-v can count cycles. :) */ |
---|
[3774c7f] | 57 | #include <rtems/bspIo.h> |
---|
[f849f3e] | 58 | |
---|
| 59 | int Read_timer() |
---|
| 60 | { |
---|
| 61 | rtems_unsigned32 clicks; |
---|
| 62 | rtems_unsigned32 total; |
---|
| 63 | rtems_unsigned32 tcr; |
---|
| 64 | |
---|
[a355e3ea] | 65 | clicks = MONGOOSEV_READ_REGISTER( TIMER_BASE, |
---|
| 66 | MONGOOSEV_TIMER_INITIAL_COUNTER_REGISTER ); |
---|
[f849f3e] | 67 | total = 0xffffffff - clicks; |
---|
| 68 | |
---|
| 69 | tcr = MONGOOSEV_READ_REGISTER( TIMER_BASE, MONGOOSEV_TIMER_CONTROL_REGISTER ); |
---|
[a355e3ea] | 70 | |
---|
| 71 | MONGOOSEV_WRITE_REGISTER( TIMER_BASE, |
---|
| 72 | MONGOOSEV_TIMER_CONTROL_REGISTER, |
---|
| 73 | 0 ); |
---|
| 74 | |
---|
[f849f3e] | 75 | if ( tcr & MONGOOSEV_TIMER_CONTROL_TIMEOUT ) |
---|
| 76 | printk( "MG5 timer overran\n" ); |
---|
| 77 | |
---|
| 78 | if ( Timer_driver_Find_average_overhead == 1 ) |
---|
| 79 | return total; /* in cycle units */ |
---|
| 80 | |
---|
| 81 | if ( total < LEAST_VALID ) |
---|
| 82 | return 0; /* below timer resolution */ |
---|
| 83 | |
---|
[a355e3ea] | 84 | return (total - AVG_OVERHEAD) / CPU_CLOCK_RATE_MHZ; |
---|
[f849f3e] | 85 | } |
---|
| 86 | |
---|
| 87 | rtems_status_code Empty_function( void ) |
---|
| 88 | { |
---|
| 89 | return RTEMS_SUCCESSFUL; |
---|
| 90 | } |
---|
| 91 | |
---|
| 92 | void Set_find_average_overhead( |
---|
| 93 | rtems_boolean find_flag |
---|
| 94 | ) |
---|
| 95 | { |
---|
| 96 | Timer_driver_Find_average_overhead = find_flag; |
---|
| 97 | } |
---|
[a355e3ea] | 98 | |
---|
| 99 | |
---|
| 100 | /* eof */ |
---|