source: rtems/c/src/lib/libbsp/unix/posix/timer/timer.c @ 3ea5288

4.104.114.84.9
Last change on this file since 3ea5288 was 3ea5288, checked in by Joel Sherrill <joel.sherrill@…>, on Jul 18, 1995 at 9:11:57 PM

fixed for Linux

  • 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#include <sys/time.h>
23
24struct timeval  Timer_start;
25struct timeval  Timer_stop;
26struct timezone Time_zone;
27
28rtems_boolean   Timer_driver_Find_average_overhead;
29
30void Timer_initialize()
31{
32   gettimeofday( &Timer_start, &Time_zone );
33}
34
35#define AVG_OVERHEAD      0  /* It typically takes xxx microseconds */
36                             /* (XX countdowns) to start/stop the timer. */
37#define LEAST_VALID       10 /* Don't trust a value lower than this */
38
39int Read_timer()
40{
41  int total;
42
43  gettimeofday( &Timer_stop, &Time_zone );
44
45  if ( Timer_stop.tv_sec == Timer_start.tv_sec )
46    total = Timer_stop.tv_usec - Timer_start.tv_usec;
47  else {
48    total  = 1000000 - Timer_start.tv_usec;
49    total += (Timer_stop.tv_sec - Timer_start.tv_sec - 1) * 1000000;
50    total += Timer_stop.tv_usec;
51  }
52
53  if ( Timer_driver_Find_average_overhead == 1 )
54      return total;          /* in countdown units */
55  else {
56    if ( total < LEAST_VALID )
57        return 0;            /* below timer resolution */
58    return total - AVG_OVERHEAD;
59  }
60}
61
62rtems_status_code Empty_function( void )
63{
64  return RTEMS_SUCCESSFUL;
65}
66
67void Set_find_average_overhead(
68  rtems_boolean find_flag
69)
70{
71  Timer_driver_Find_average_overhead = find_flag;
72}
Note: See TracBrowser for help on using the repository browser.