[bec7ba52] | 1 | /* timer.c |
---|
| 2 | * |
---|
| 3 | * This file implements a benchmark timer using timer 2. |
---|
| 4 | * |
---|
| 5 | * COPYRIGHT (c) 1989-1998. |
---|
| 6 | * On-Line Applications Research Corporation (OAR). |
---|
| 7 | * |
---|
| 8 | * The license and distribution terms for this file may be |
---|
| 9 | * found in the file LICENSE in this distribution or at |
---|
| 10 | * http://www.rtems.com/license/LICENSE. |
---|
| 11 | * |
---|
| 12 | * Ported to LEON implementation of the SPARC by On-Line Applications |
---|
| 13 | * Research Corporation (OAR) under contract to the European Space |
---|
| 14 | * Agency (ESA). |
---|
| 15 | * |
---|
| 16 | * LEON modifications of respective RTEMS file: COPYRIGHT (c) 1995. |
---|
| 17 | * European Space Agency. |
---|
| 18 | * |
---|
| 19 | * $Id$ |
---|
| 20 | */ |
---|
| 21 | |
---|
| 22 | |
---|
| 23 | #include <bsp.h> |
---|
| 24 | |
---|
[c8b03dbd] | 25 | bool benchmark_timer_find_average_overhead; |
---|
[bec7ba52] | 26 | |
---|
[86432056] | 27 | bool benchmark_timer_is_initialized = false; |
---|
[bec7ba52] | 28 | |
---|
[e511e126] | 29 | void benchmark_timer_initialize(void) |
---|
[bec7ba52] | 30 | { |
---|
| 31 | /* |
---|
| 32 | * Timer runs long and accurate enough not to require an interrupt. |
---|
| 33 | */ |
---|
| 34 | |
---|
[86432056] | 35 | if ( benchmark_timer_is_initialized == false ) { |
---|
[bec7ba52] | 36 | |
---|
| 37 | /* approximately 1 us per countdown */ |
---|
| 38 | LEON_REG.Timer_Counter_2 = 0xffffff; |
---|
| 39 | LEON_REG.Timer_Reload_2 = 0xffffff; |
---|
| 40 | |
---|
| 41 | } else { |
---|
[86432056] | 42 | benchmark_timer_is_initialized = true; |
---|
[bec7ba52] | 43 | } |
---|
| 44 | |
---|
| 45 | LEON_REG.Timer_Control_2 = ( |
---|
| 46 | LEON_REG_TIMER_COUNTER_ENABLE_COUNTING | |
---|
| 47 | LEON_REG_TIMER_COUNTER_LOAD_COUNTER |
---|
| 48 | ); |
---|
| 49 | |
---|
| 50 | } |
---|
| 51 | |
---|
| 52 | #define AVG_OVERHEAD 3 /* It typically takes 3.0 microseconds */ |
---|
| 53 | /* to start/stop the timer. */ |
---|
| 54 | #define LEAST_VALID 2 /* Don't trust a value lower than this */ |
---|
| 55 | |
---|
[e511e126] | 56 | int benchmark_timer_read(void) |
---|
[bec7ba52] | 57 | { |
---|
[1408ea8d] | 58 | uint32_t total; |
---|
[bec7ba52] | 59 | |
---|
| 60 | total = LEON_REG.Timer_Counter_2; |
---|
| 61 | |
---|
| 62 | total = 0xffffff - total; |
---|
| 63 | |
---|
[86432056] | 64 | if ( benchmark_timer_find_average_overhead == true ) |
---|
[bec7ba52] | 65 | return total; /* in one microsecond units */ |
---|
| 66 | |
---|
| 67 | if ( total < LEAST_VALID ) |
---|
| 68 | return 0; /* below timer resolution */ |
---|
| 69 | |
---|
| 70 | return total - AVG_OVERHEAD; |
---|
| 71 | } |
---|
| 72 | |
---|
[e511e126] | 73 | void benchmark_timer_disable_subtracting_average_overhead( |
---|
[c8b03dbd] | 74 | bool find_flag |
---|
[bec7ba52] | 75 | ) |
---|
| 76 | { |
---|
[e511e126] | 77 | benchmark_timer_find_average_overhead = find_flag; |
---|
[bec7ba52] | 78 | } |
---|