source: rtems/c/src/lib/libbsp/unix/posix/timer/timer.c @ 98e4ebf5

4.104.114.84.95
Last change on this file since 98e4ebf5 was 98e4ebf5, checked in by Joel Sherrill <joel.sherrill@…>, on 10/08/97 at 15:45:54

Fixed typo in the pointer to the license terms.

  • 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-1997.
9 *  On-Line Applications Research Corporation (OAR).
10 *  Copyright assigned to U.S. Government, 1994.
11 *
12 *  The license and distribution terms for this file may be
13 *  found in the file LICENSE in this distribution or at
14 *  http://www.OARcorp.com/rtems/license.html.
15 *
16 *  $Id$
17 */
18
19/* For solaris 2.4 */
20#define __EXTENSIONS__
21
22#include <bsp.h>
23#include <time.h>
24#include <sys/time.h>
25
26struct timeval  Timer_start;
27struct timeval  Timer_stop;
28struct timezone Time_zone;
29
30rtems_boolean   Timer_driver_Find_average_overhead;
31
32void Timer_initialize()
33{
34   gettimeofday( &Timer_start, &Time_zone );
35}
36
37#define AVG_OVERHEAD      0  /* It typically takes xxx microseconds */
38                             /* (XX countdowns) to start/stop the timer. */
39#define LEAST_VALID       10 /* Don't trust a value lower than this */
40
41int Read_timer()
42{
43  int total;
44
45  gettimeofday( &Timer_stop, &Time_zone );
46
47  if ( Timer_stop.tv_sec == Timer_start.tv_sec )
48    total = Timer_stop.tv_usec - Timer_start.tv_usec;
49  else {
50    total  = 1000000 - Timer_start.tv_usec;
51    total += (Timer_stop.tv_sec - Timer_start.tv_sec - 1) * 1000000;
52    total += Timer_stop.tv_usec;
53  }
54
55  if ( Timer_driver_Find_average_overhead == 1 )
56      return total;          /* in countdown units */
57  else {
58    if ( total < LEAST_VALID )
59        return 0;            /* below timer resolution */
60    return total - AVG_OVERHEAD;
61  }
62}
63
64rtems_status_code Empty_function( void )
65{
66  return RTEMS_SUCCESSFUL;
67}
68
69void Set_find_average_overhead(
70  rtems_boolean find_flag
71)
72{
73  Timer_driver_Find_average_overhead = find_flag;
74}
Note: See TracBrowser for help on using the repository browser.