source:
rtems/c/src/lib/libbsp/powerpc/ppcn_60x/timer/timer.c
@
bad8092c
Last change on this file since bad8092c was bad8092c, checked in by Ralf Corsepius <ralf.corsepius@…>, on 03/31/04 at 03:49:17 | |
---|---|
|
|
File size: 1.6 KB |
Line | |
---|---|
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 | * |
13 | * The license and distribution terms for this file may in |
14 | * the file LICENSE in this distribution or at |
15 | * http://www.rtems.com/license/LICENSE. |
16 | * |
17 | * $Id$ |
18 | */ |
19 | |
20 | #include <assert.h> |
21 | |
22 | #include <bsp.h> |
23 | |
24 | uint64_t Timer_driver_Start_time; |
25 | |
26 | rtems_boolean Timer_driver_Find_average_overhead; |
27 | |
28 | /* |
29 | * Timer_initialize |
30 | */ |
31 | void Timer_initialize() |
32 | { |
33 | |
34 | /* |
35 | * Timer runs long and accurate enough not to require an interrupt. |
36 | */ |
37 | |
38 | Timer_driver_Start_time = PPC_Get_timebase_register(); |
39 | } |
40 | |
41 | /* |
42 | * Read_timer |
43 | */ |
44 | int Read_timer() |
45 | { |
46 | uint64_t clicks; |
47 | uint64_t total64; |
48 | uint32_t total; |
49 | |
50 | /* approximately CLOCK_SPEED clicks per microsecond */ |
51 | |
52 | clicks = PPC_Get_timebase_register(); |
53 | |
54 | assert( clicks > Timer_driver_Start_time ); |
55 | |
56 | total64 = clicks - Timer_driver_Start_time; |
57 | |
58 | assert( total64 <= 0xffffffff ); /* fits into a uint32_t */ |
59 | |
60 | total = (uint32_t) total64; |
61 | |
62 | if ( Timer_driver_Find_average_overhead == 1 ) |
63 | return total; /* in "clicks" of the decrementer units */ |
64 | |
65 | if ( total < BSP_TIMER_LEAST_VALID ) |
66 | return 0; /* below timer resolution */ |
67 | |
68 | return BSP_Convert_decrementer(total - BSP_TIMER_AVG_OVERHEAD); |
69 | } |
70 | |
71 | rtems_status_code Empty_function( void ) |
72 | { |
73 | return RTEMS_SUCCESSFUL; |
74 | } |
75 | |
76 | void Set_find_average_overhead( |
77 | rtems_boolean find_flag |
78 | ) |
79 | { |
80 | Timer_driver_Find_average_overhead = find_flag; |
81 | } |
Note: See TracBrowser
for help on using the repository browser.