source: rtems/c/src/lib/libbsp/no_cpu/no_bsp/timer/timer.c @ ac7d5ef0

4.104.114.84.95
Last change on this file since ac7d5ef0 was ac7d5ef0, checked in by Joel Sherrill <joel.sherrill@…>, on 05/11/95 at 17:39:37

Initial revision

  • Property mode set to 100644
File size: 2.7 KB
Line 
1/*  timer.c
2 *
3 *  This file manages the benchmark timer used by the RTEMS Timing Test
4 *  Suite.  Each measured time period is demarcated by calls to
5 *  Timer_initialize() and Read_timer().  Read_timer() usually returns
6 *  the number of microseconds since Timer_initialize() exitted.
7 *
8 *  NOTE: It is important that the timer start/stop overhead be
9 *        determined when porting or modifying this code.
10 *
11 *  COPYRIGHT (c) 1989, 1990, 1991, 1992, 1993, 1994.
12 *  On-Line Applications Research Corporation (OAR).
13 *  All rights assigned to U.S. Government, 1994.
14 *
15 *  This material may be reproduced by or for the U.S. Government pursuant
16 *  to the copyright license under the clause at DFARS 252.227-7013.  This
17 *  notice must appear in all copies of this file and its derivatives.
18 *
19 *  $Id$
20 */
21
22#include <rtems.h>
23#include <bsp.h>
24
25rtems_unsigned32 Timer_interrupts;
26rtems_boolean Timer_driver_Find_average_overhead;
27
28void Timer_initialize( void )
29{
30
31  /*
32   *  Timer has never overflowed.  This may not be necessary on some
33   *  implemenations of timer but ....
34   */
35
36  Timer_interrupts = 0;
37
38  /*
39   *  Somehow start the timer
40   */
41}
42
43/*
44 *  The following controls the behavior of Read_timer().
45 *
46 *  AVG_OVEREHAD is the overhead for starting and stopping the timer.  It
47 *  is usually deducted from the number returned.
48 *
49 *  LEAST_VALID is the lowest number this routine should trust.  Numbers
50 *  below this are "noise" and zero is returned.
51 */
52
53#define AVG_OVERHEAD      0  /* It typically takes X.X microseconds */
54                             /* (Y countdowns) to start/stop the timer. */
55                             /* This value is in microseconds. */
56#define LEAST_VALID       1  /* Don't trust a clicks value lower than this */
57
58int Read_timer( void )
59{
60  rtems_unsigned32 clicks;
61  rtems_unsigned32 total;
62
63  /*
64   *  Read the timer and see how many clicks it has been since we started.
65   */
66
67  clicks = 0;   /* XXX: read some HW here */
68
69  /*
70   *  Total is calculated by taking into account the number of timer overflow
71   *  interrupts since the timer was initialized and clicks since the last
72   *  interrupts.
73   */
74
75  total = clicks * 0;
76
77  if ( Timer_driver_Find_average_overhead == 1 )
78    return total;          /* in XXX microsecond units */
79  else {
80    if ( total < LEAST_VALID )
81      return 0;            /* below timer resolution */
82  /*
83   *  Somehow convert total into microseconds
84   */
85      return (total - AVG_OVERHEAD);
86    }
87}
88
89/*
90 *  Empty function call used in loops to measure basic cost of looping
91 *  in Timing Test Suite.
92 */
93
94rtems_status_code Empty_function( void )
95{
96  return RTEMS_SUCCESSFUL;
97}
98
99void Set_find_average_overhead(
100  rtems_boolean find_flag
101)
102{
103  Timer_driver_Find_average_overhead = find_flag;
104}
105
Note: See TracBrowser for help on using the repository browser.