source: rtems/c/src/lib/libbsp/unix/posix/timer/timer.c @ 6cc85032

4.104.114.84.9
Last change on this file since 6cc85032 was 6cc85032, checked in by Joel Sherrill <joel.sherrill@…>, on Jul 12, 1995 at 8:44:47 PM

fix oversites in libbsp/unix/posix

  • Property mode set to 100644
File size: 1.8 KB
Line 
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, 1990, 1991, 1992, 1993, 1994.
9 *  On-Line Applications Research Corporation (OAR).
10 *  All rights assigned to U.S. Government, 1994.
11 *
12 *  This material may be reproduced by or for the U.S. Government pursuant
13 *  to the copyright license under the clause at DFARS 252.227-7013.  This
14 *  notice must appear in all copies of this file and its derivatives.
15 *
16 *  $Id$
17 */
18
19#include <rtems.h>
20
21#include <time.h>
22
23struct timeval  Timer_start;
24struct timeval  Timer_stop;
25struct timezone Time_zone;
26
27rtems_boolean   Timer_driver_Find_average_overhead;
28
29void Timer_initialize()
30{
31   gettimeofday( &Timer_start, &Time_zone );
32}
33
34#define AVG_OVERHEAD      0  /* It typically takes xxx microseconds */
35                             /* (XX countdowns) to start/stop the timer. */
36#define LEAST_VALID       10 /* Don't trust a value lower than this */
37
38int Read_timer()
39{
40  int total;
41
42  gettimeofday( &Timer_stop, &Time_zone );
43
44  if ( Timer_stop.tv_sec == Timer_start.tv_sec )
45    total = Timer_stop.tv_usec - Timer_start.tv_usec;
46  else {
47    total  = 1000000 - Timer_start.tv_usec;
48    total += (Timer_stop.tv_sec - Timer_start.tv_sec - 1) * 1000000;
49    total += Timer_stop.tv_usec;
50  }
51
52  if ( Timer_driver_Find_average_overhead == 1 )
53      return total;          /* in countdown units */
54  else {
55    if ( total < LEAST_VALID )
56        return 0;            /* below timer resolution */
57    return total - AVG_OVERHEAD;
58  }
59}
60
61rtems_status_code Empty_function( void )
62{
63  return RTEMS_SUCCESSFUL;
64}
65
66void Set_find_average_overhead(
67  rtems_boolean find_flag
68)
69{
70  Timer_driver_Find_average_overhead = find_flag;
71}
Note: See TracBrowser for help on using the repository browser.