1 | /* timer.c |
---|
2 | * |
---|
3 | * This file manages the interval timer on the PA-RISC. |
---|
4 | * |
---|
5 | * NOTE: It is important that the timer start/stop overhead be |
---|
6 | * determined when porting or modifying this code. |
---|
7 | * |
---|
8 | * COPYRIGHT (c) 1989-1999. |
---|
9 | * On-Line Applications Research Corporation (OAR). |
---|
10 | * |
---|
11 | * The license and distribution terms for this file may be |
---|
12 | * found in the file LICENSE in this distribution or at |
---|
13 | * http://www.OARcorp.com/rtems/license.html. |
---|
14 | * |
---|
15 | * $Id$ |
---|
16 | */ |
---|
17 | |
---|
18 | #include <bsp.h> |
---|
19 | #include <time.h> |
---|
20 | #include <sys/time.h> |
---|
21 | |
---|
22 | struct timeval Timer_start; |
---|
23 | struct timeval Timer_stop; |
---|
24 | struct timezone Time_zone; |
---|
25 | |
---|
26 | rtems_boolean Timer_driver_Find_average_overhead; |
---|
27 | |
---|
28 | void Timer_initialize() |
---|
29 | { |
---|
30 | gettimeofday( &Timer_start, &Time_zone ); |
---|
31 | } |
---|
32 | |
---|
33 | #define AVG_OVERHEAD 0 /* It typically takes xxx microseconds */ |
---|
34 | /* (XX countdowns) to start/stop the timer. */ |
---|
35 | #define LEAST_VALID 10 /* Don't trust a value lower than this */ |
---|
36 | |
---|
37 | int Read_timer() |
---|
38 | { |
---|
39 | int total; |
---|
40 | |
---|
41 | gettimeofday( &Timer_stop, &Time_zone ); |
---|
42 | |
---|
43 | if ( Timer_stop.tv_sec == Timer_start.tv_sec ) |
---|
44 | total = Timer_stop.tv_usec - Timer_start.tv_usec; |
---|
45 | else { |
---|
46 | total = 1000000 - Timer_start.tv_usec; |
---|
47 | total += (Timer_stop.tv_sec - Timer_start.tv_sec - 1) * 1000000; |
---|
48 | total += Timer_stop.tv_usec; |
---|
49 | } |
---|
50 | |
---|
51 | if ( Timer_driver_Find_average_overhead == 1 ) |
---|
52 | return total; /* in countdown units */ |
---|
53 | else { |
---|
54 | if ( total < LEAST_VALID ) |
---|
55 | return 0; /* below timer resolution */ |
---|
56 | return total - AVG_OVERHEAD; |
---|
57 | } |
---|
58 | } |
---|
59 | |
---|
60 | rtems_status_code Empty_function( void ) |
---|
61 | { |
---|
62 | return RTEMS_SUCCESSFUL; |
---|
63 | } |
---|
64 | |
---|
65 | void Set_find_average_overhead( |
---|
66 | rtems_boolean find_flag |
---|
67 | ) |
---|
68 | { |
---|
69 | Timer_driver_Find_average_overhead = find_flag; |
---|
70 | } |
---|