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

Last change on this file since 3e6211b was 3e6211b, checked in by Joel Sherrill <joel.sherrill@…>, on Sep 4, 2003 at 6:45:40 PM

2003-09-04 Joel Sherrill <joel@…>

  • clock/clock.c, console/console.c, include/bsp.h, shmsupp/addrconv.c, shmsupp/cause_intr.c, shmsupp/getcfg.c, shmsupp/lock.c, shmsupp/mpisr.c, startup/bspclean.c, startup/bspstart.c, startup/exit.c, startup/setvec.c, timer/timer.c: URL for license changed.
  • Property mode set to 100644
File size: 1.7 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-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.rtems.com/license/LICENSE.
14 *
15 *  $Id$
16 */
17
18#include <bsp.h>
19#include <time.h>
20#include <sys/time.h>
21
22struct timeval  Timer_start;
23struct timeval  Timer_stop;
24struct timezone Time_zone;
25
26rtems_boolean   Timer_driver_Find_average_overhead;
27
28void 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
37int 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
60rtems_status_code Empty_function( void )
61{
62  return RTEMS_SUCCESSFUL;
63}
64
65void Set_find_average_overhead(
66  rtems_boolean find_flag
67)
68{
69  Timer_driver_Find_average_overhead = find_flag;
70}
Note: See TracBrowser for help on using the repository browser.