[3d6669cc] | 1 | /* |
---|
| 2 | * Cirrus EP7312 Timer driver |
---|
| 3 | * |
---|
| 4 | * Copyright (c) 2002 by Jay Monkman <jtm@smoothsmoothie.com> |
---|
[6128a4a] | 5 | * |
---|
[3d6669cc] | 6 | * The license and distribution terms for this file may be |
---|
| 7 | * found in the file LICENSE in this distribution or at |
---|
[c499856] | 8 | * http://www.rtems.org/license/LICENSE. |
---|
[3d6669cc] | 9 | * |
---|
| 10 | * Notes: |
---|
| 11 | * This file manages the benchmark timer used by the RTEMS Timing Test |
---|
| 12 | * Suite. Each measured time period is demarcated by calls to |
---|
[89866d84] | 13 | * benchmark_timer_initialize() and benchmark_timer_read(). benchmark_timer_read() usually returns |
---|
| 14 | * the number of microseconds since benchmark_timer_initialize() exitted. |
---|
[3d6669cc] | 15 | * |
---|
[6128a4a] | 16 | * It is important that the timer start/stop overhead be determined |
---|
[3d6669cc] | 17 | * when porting or modifying this code. |
---|
| 18 | */ |
---|
| 19 | |
---|
| 20 | #include <rtems.h> |
---|
| 21 | #include <bsp.h> |
---|
[14102e1e] | 22 | #include <rtems/btimer.h> |
---|
[3d6669cc] | 23 | #include <ep7312.h> |
---|
| 24 | |
---|
[2a7f710f] | 25 | uint16_t tstart; |
---|
[89866d84] | 26 | bool benchmark_timer_find_average_overhead; |
---|
[3d6669cc] | 27 | |
---|
[89866d84] | 28 | void benchmark_timer_initialize( void ) |
---|
[3d6669cc] | 29 | { |
---|
| 30 | *EP7312_SYSCON1 |= EP7312_SYSCON1_TC2_512KHZ; |
---|
| 31 | *EP7312_TC2D = 0xffff; |
---|
| 32 | } |
---|
| 33 | |
---|
| 34 | /* |
---|
[89866d84] | 35 | * The following controls the behavior of benchmark_timer_read(). |
---|
[3d6669cc] | 36 | * |
---|
| 37 | * AVG_OVEREHAD is the overhead for starting and stopping the timer. It |
---|
| 38 | * is usually deducted from the number returned. |
---|
| 39 | * |
---|
| 40 | * LEAST_VALID is the lowest number this routine should trust. Numbers |
---|
| 41 | * below this are "noise" and zero is returned. |
---|
| 42 | */ |
---|
| 43 | |
---|
| 44 | #define AVG_OVERHEAD 0 /* It typically takes X.X microseconds */ |
---|
| 45 | /* (Y countdowns) to start/stop the timer. */ |
---|
| 46 | /* This value is in microseconds. */ |
---|
| 47 | #define LEAST_VALID 1 /* Don't trust a clicks value lower than this */ |
---|
| 48 | |
---|
[8fbe2e6] | 49 | benchmark_timer_t benchmark_timer_read( void ) |
---|
[3d6669cc] | 50 | { |
---|
[2a7f710f] | 51 | uint16_t t; |
---|
| 52 | uint32_t total; |
---|
[3d6669cc] | 53 | t = *EP7312_TC2D; |
---|
| 54 | |
---|
| 55 | /* |
---|
| 56 | * Total is calculated by taking into account the number of timer overflow |
---|
| 57 | * interrupts since the timer was initialized and clicks since the last |
---|
| 58 | * interrupts. |
---|
| 59 | */ |
---|
| 60 | |
---|
[2a7f710f] | 61 | total = (uint32_t)0x0000ffff - t; /* result is 1/512000 = ~2 uS */ |
---|
[3d6669cc] | 62 | total = (total * 1953) / 1000; /* convert to uS */ |
---|
[b5059b3] | 63 | if ( benchmark_timer_find_average_overhead == true ) |
---|
[3d6669cc] | 64 | return total; /* in XXX microsecond units */ |
---|
| 65 | else { |
---|
| 66 | if ( total < LEAST_VALID ) |
---|
| 67 | return 0; /* below timer resolution */ |
---|
| 68 | /* |
---|
| 69 | * Somehow convert total into microseconds |
---|
| 70 | */ |
---|
| 71 | return (total - AVG_OVERHEAD); |
---|
| 72 | } |
---|
| 73 | } |
---|
| 74 | |
---|
[89866d84] | 75 | void benchmark_timer_disable_subtracting_average_overhead( |
---|
[ee1af04] | 76 | bool find_flag |
---|
[3d6669cc] | 77 | ) |
---|
| 78 | { |
---|
[89866d84] | 79 | benchmark_timer_find_average_overhead = find_flag; |
---|
[3d6669cc] | 80 | } |
---|