[6128a4a] | 1 | /* |
---|
[8f81248c] | 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 |
---|
[86f8ee90] | 10 | * found in the file LICENSE in this distribution or at |
---|
[c499856] | 11 | * http://www.rtems.org/license/LICENSE. |
---|
[8f81248c] | 12 | */ |
---|
| 13 | |
---|
| 14 | #include <assert.h> |
---|
| 15 | |
---|
| 16 | #include <bsp.h> |
---|
[af3048a] | 17 | #include <rtems/btimer.h> |
---|
[8f81248c] | 18 | |
---|
[e53fbe8d] | 19 | bool benchmark_timer_find_average_overhead; |
---|
[8f81248c] | 20 | |
---|
[25c62b0] | 21 | void benchmark_timer_initialize(void) |
---|
[8f81248c] | 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 | * |
---|
[4d6b3b6] | 28 | * NOTE: This is similar to the clock driver initialization |
---|
[8f81248c] | 29 | * with the exception that the divider is disabled and |
---|
| 30 | * the compare register is set to the maximum value. |
---|
| 31 | */ |
---|
| 32 | |
---|
[b335c503] | 33 | TX3904_TIMER_WRITE( TX3904_TIMER1_BASE, TX3904_TIMER_TCR, 0x20 ); |
---|
[4d6b3b6] | 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 ); |
---|
[b335c503] | 38 | TX3904_TIMER_WRITE( TX3904_TIMER1_BASE, TX3904_TIMER_ITMR, 0x0001 ); |
---|
[4d6b3b6] | 39 | TX3904_TIMER_WRITE( TX3904_TIMER1_BASE, TX3904_TIMER_TCR, 0xe0 ); |
---|
[8f81248c] | 40 | } |
---|
| 41 | |
---|
[4d6b3b6] | 42 | #define AVG_OVERHEAD 0 /* It typically takes N instructions */ |
---|
[8f81248c] | 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 | |
---|
[8fbe2e6] | 47 | benchmark_timer_t benchmark_timer_read(void) |
---|
[8f81248c] | 48 | { |
---|
[d1c60fb] | 49 | uint32_t total; |
---|
[8f81248c] | 50 | |
---|
[4d6b3b6] | 51 | total = TX3904_TIMER_READ( TX3904_TIMER1_BASE, TX3904_TIMER_TRR ); |
---|
[8f81248c] | 52 | |
---|
[e53fbe8d] | 53 | if ( benchmark_timer_find_average_overhead == true ) |
---|
[8f81248c] | 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 | |
---|
[25c62b0] | 62 | void benchmark_timer_disable_subtracting_average_overhead( |
---|
[e53fbe8d] | 63 | bool find_flag |
---|
[8f81248c] | 64 | ) |
---|
| 65 | { |
---|
[25c62b0] | 66 | benchmark_timer_find_average_overhead = find_flag; |
---|
[8f81248c] | 67 | } |
---|