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