1 | /* timer.c |
---|
2 | * |
---|
3 | * This file implements a benchmark timer using the General Purpose Timer. |
---|
4 | * |
---|
5 | * Notes: |
---|
6 | * |
---|
7 | * BSP_TIMER_AVG_OVERHEAD and BSP_TIMER_LEAST_VALID are required to be |
---|
8 | * provided in bsp.h |
---|
9 | * |
---|
10 | * COPYRIGHT (c) 1989-1997. |
---|
11 | * On-Line Applications Research Corporation (OAR). |
---|
12 | * Copyright assigned to U.S. Government, 1994. |
---|
13 | * |
---|
14 | * The license and distribution terms for this file may in |
---|
15 | * the file LICENSE in this distribution or at |
---|
16 | * http://www.OARcorp.com/rtems/license.html. |
---|
17 | * |
---|
18 | * $Id$ |
---|
19 | */ |
---|
20 | |
---|
21 | #include <assert.h> |
---|
22 | #include <rtems.h> |
---|
23 | #include <libcpu/cpu.h> |
---|
24 | |
---|
25 | rtems_unsigned64 Timer_driver_Start_time; |
---|
26 | |
---|
27 | rtems_boolean Timer_driver_Find_average_overhead = 0; |
---|
28 | unsigned clicks_overhead = 0; |
---|
29 | |
---|
30 | /* |
---|
31 | * Timer Get overhead |
---|
32 | */ |
---|
33 | |
---|
34 | int Timer_get_clicks_overhead() |
---|
35 | { |
---|
36 | rtems_unsigned64 clicks; |
---|
37 | |
---|
38 | PPC_Set_timebase_register((unsigned64) 0); |
---|
39 | clicks = PPC_Get_timebase_register(); |
---|
40 | assert(clicks <= 0xffffffff); |
---|
41 | clicks_overhead = (unsigned) clicks; |
---|
42 | return clicks_overhead; |
---|
43 | } |
---|
44 | |
---|
45 | /* |
---|
46 | * Timer_initialize |
---|
47 | */ |
---|
48 | void Timer_initialize() |
---|
49 | { |
---|
50 | |
---|
51 | /* |
---|
52 | * Timer runs long and accurate enough not to require an interrupt. |
---|
53 | */ |
---|
54 | |
---|
55 | if (clicks_overhead == 0) clicks_overhead = Timer_get_clicks_overhead(); |
---|
56 | PPC_Set_timebase_register((unsigned64) 0); |
---|
57 | } |
---|
58 | |
---|
59 | |
---|
60 | /* |
---|
61 | * Read_timer |
---|
62 | */ |
---|
63 | |
---|
64 | extern int BSP_Convert_decrementer( unsigned32 ); |
---|
65 | |
---|
66 | int Read_timer() |
---|
67 | { |
---|
68 | rtems_unsigned64 total64; |
---|
69 | rtems_unsigned32 total; |
---|
70 | |
---|
71 | /* approximately CLOCK_SPEED clicks per microsecond */ |
---|
72 | |
---|
73 | total64 = PPC_Get_timebase_register(); |
---|
74 | |
---|
75 | assert( total64 <= 0xffffffff ); /* fits into a unsigned32 */ |
---|
76 | |
---|
77 | total = (rtems_unsigned32) total64; |
---|
78 | |
---|
79 | if ( Timer_driver_Find_average_overhead == 1 ) |
---|
80 | return total; /* in "clicks" of the decrementer units */ |
---|
81 | |
---|
82 | return (int) BSP_Convert_decrementer(total - clicks_overhead); |
---|
83 | } |
---|
84 | |
---|
85 | unsigned long long Read_long_timer() |
---|
86 | { |
---|
87 | rtems_unsigned64 total64; |
---|
88 | |
---|
89 | total64 = PPC_Get_timebase_register(); |
---|
90 | return BSP_Convert_decrementer(total64 - clicks_overhead); |
---|
91 | } |
---|
92 | |
---|
93 | rtems_status_code Empty_function( void ) |
---|
94 | { |
---|
95 | return RTEMS_SUCCESSFUL; |
---|
96 | } |
---|
97 | |
---|
98 | void Set_find_average_overhead( |
---|
99 | rtems_boolean find_flag |
---|
100 | ) |
---|
101 | { |
---|
102 | Timer_driver_Find_average_overhead = find_flag; |
---|
103 | } |
---|