[8fbe2e6] | 1 | /** |
---|
| 2 | * @file |
---|
| 3 | * @brief IDT 4650 Timer Driver. |
---|
[f198c63] | 4 | * |
---|
[8fbe2e6] | 5 | * This file manages the benchmark timer used by the RTEMS Timing Test |
---|
| 6 | * Suite. |
---|
| 7 | */ |
---|
| 8 | |
---|
| 9 | /* |
---|
[f198c63] | 10 | * Author: Craig Lebakken <craigl@transition.com> |
---|
| 11 | * |
---|
| 12 | * COPYRIGHT (c) 1996 by Transition Networks Inc. |
---|
| 13 | * |
---|
| 14 | * To anyone who acknowledges that this file is provided "AS IS" |
---|
| 15 | * without any express or implied warranty: |
---|
| 16 | * permission to use, copy, modify, and distribute this file |
---|
| 17 | * for any purpose is hereby granted without fee, provided that |
---|
| 18 | * the above copyright notice and this notice appears in all |
---|
| 19 | * copies, and that the name of Transition Networks not be used in |
---|
| 20 | * advertising or publicity pertaining to distribution of the |
---|
| 21 | * software without specific, written prior permission. |
---|
| 22 | * Transition Networks makes no representations about the suitability |
---|
| 23 | * of this software for any purpose. |
---|
| 24 | * |
---|
| 25 | * derived from src/lib/libbsp/no_cpu/no_bsp/timer/timer.c |
---|
| 26 | * |
---|
[08311cc3] | 27 | * COPYRIGHT (c) 1989-1999. |
---|
[f198c63] | 28 | * On-Line Applications Research Corporation (OAR). |
---|
| 29 | * |
---|
[98e4ebf5] | 30 | * The license and distribution terms for this file may be |
---|
| 31 | * found in the file LICENSE in this distribution or at |
---|
[c499856] | 32 | * http://www.rtems.org/license/LICENSE. |
---|
[f198c63] | 33 | */ |
---|
| 34 | |
---|
| 35 | #include <rtems.h> |
---|
[8fbe2e6] | 36 | #include <rtems/btimer.h> |
---|
[f198c63] | 37 | |
---|
| 38 | #define CLOCKS_PER_MICROSECOND ( CPU_CLOCK_RATE_MHZ ) |
---|
| 39 | #define TIMER_MAX_VALUE 0xffffffff |
---|
| 40 | |
---|
[35f97010] | 41 | extern uint32_t mips_read_timer( void ); |
---|
[f198c63] | 42 | |
---|
[63e23b6e] | 43 | static bool benchmark_timer_find_average_overhead; |
---|
[290da88f] | 44 | static uint32_t benchmark_timer_initial_value = 0; |
---|
[f198c63] | 45 | |
---|
[a903b7b] | 46 | void benchmark_timer_initialize( void ) |
---|
[f198c63] | 47 | { |
---|
[290da88f] | 48 | benchmark_timer_initial_value = mips_read_timer(); |
---|
[f198c63] | 49 | /* |
---|
| 50 | * Somehow start the timer |
---|
| 51 | */ |
---|
| 52 | |
---|
| 53 | /* Timer on 4650 is always running */ |
---|
| 54 | } |
---|
| 55 | |
---|
| 56 | /* |
---|
[a903b7b] | 57 | * The following controls the behavior of benchmark_timer_read(). |
---|
[f198c63] | 58 | * |
---|
| 59 | * AVG_OVEREHAD is the overhead for starting and stopping the timer. It |
---|
| 60 | * is usually deducted from the number returned. |
---|
| 61 | * |
---|
| 62 | * LEAST_VALID is the lowest number this routine should trust. Numbers |
---|
| 63 | * below this are "noise" and zero is returned. |
---|
| 64 | */ |
---|
| 65 | |
---|
| 66 | #define AVG_OVERHEAD 8 /* It typically takes X.X microseconds */ |
---|
| 67 | /* (Y countdowns) to start/stop the timer. */ |
---|
| 68 | /* This value is in cycles. */ |
---|
| 69 | #define LEAST_VALID 1 /* Don't trust a clicks value lower than this */ |
---|
| 70 | |
---|
[8fbe2e6] | 71 | benchmark_timer_t benchmark_timer_read( void ) |
---|
[f198c63] | 72 | { |
---|
[35f97010] | 73 | uint64_t clicks; |
---|
| 74 | uint32_t total; |
---|
[f198c63] | 75 | |
---|
| 76 | /* |
---|
| 77 | * Read the timer and see how many clicks it has been since we started. |
---|
| 78 | */ |
---|
| 79 | |
---|
| 80 | clicks = mips_read_timer(); /* XXX: read some HW here */ |
---|
[290da88f] | 81 | if (clicks < benchmark_timer_initial_value) |
---|
[f198c63] | 82 | { |
---|
| 83 | clicks += TIMER_MAX_VALUE; |
---|
| 84 | } |
---|
[290da88f] | 85 | clicks -= benchmark_timer_initial_value; |
---|
[f198c63] | 86 | |
---|
| 87 | /* |
---|
| 88 | * Total is calculated by taking into account the number of timer overflow |
---|
| 89 | * interrupts since the timer was initialized and clicks since the last |
---|
| 90 | * interrupts. |
---|
| 91 | */ |
---|
| 92 | #if 0 /* leave total in number of cycles */ |
---|
| 93 | total = clicks / CLOCKS_PER_MICROSECOND; |
---|
| 94 | #else |
---|
| 95 | total = clicks; |
---|
| 96 | #endif |
---|
| 97 | |
---|
[a903b7b] | 98 | if ( benchmark_timer_find_average_overhead == 1 ) |
---|
[f198c63] | 99 | return total; /* in # cycles units */ |
---|
| 100 | else { |
---|
| 101 | if ( total < LEAST_VALID ) |
---|
| 102 | return 0; /* below timer resolution */ |
---|
| 103 | /* |
---|
| 104 | * leave total in cycles |
---|
| 105 | */ |
---|
| 106 | return (total - AVG_OVERHEAD); |
---|
| 107 | } |
---|
| 108 | } |
---|
| 109 | |
---|
[63e23b6e] | 110 | void benchmark_timer_disable_subtracting_average_overhead(bool find_flag) |
---|
[f198c63] | 111 | { |
---|
[a903b7b] | 112 | benchmark_timer_find_average_overhead = find_flag; |
---|
[f198c63] | 113 | } |
---|