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

Last change on this file since b547e84 was b547e84, checked in by Joel Sherrill <joel.sherrill@…>, on 09/04/03 at 18:44:56

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

  • clock/ckinit.c, console/console.c, include/bsp.h, shmsupp/addrconv.c, shmsupp/getcfg.c, shmsupp/lock.c, shmsupp/mpisr.c, startup/bspclean.c, startup/bspstart.c, startup/linkcmds, startup/main.c, startup/setvec.c, timer/timer.c, timer/timerisr.c: URL for license changed.
  • Property mode set to 100644
File size: 2.6 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-1999.
12 *  On-Line Applications Research Corporation (OAR).
13 *
14 *  The license and distribution terms for this file may be
15 *  found in the file LICENSE in this distribution or at
16 *  http://www.rtems.com/license/LICENSE.
17 *
18 *  $Id$
19 */
20
21#include <rtems.h>
22#include <bsp.h>
23
24rtems_unsigned32 Timer_interrupts;
25rtems_boolean Timer_driver_Find_average_overhead;
26
27void Timer_initialize( void )
28{
29
30  /*
31   *  Timer has never overflowed.  This may not be necessary on some
32   *  implemenations of timer but ....
33   */
34
35  Timer_interrupts = 0;
36
37  /*
38   *  Somehow start the timer
39   */
40}
41
42/*
43 *  The following controls the behavior of Read_timer().
44 *
45 *  AVG_OVEREHAD is the overhead for starting and stopping the timer.  It
46 *  is usually deducted from the number returned.
47 *
48 *  LEAST_VALID is the lowest number this routine should trust.  Numbers
49 *  below this are "noise" and zero is returned.
50 */
51
52#define AVG_OVERHEAD      0  /* It typically takes X.X microseconds */
53                             /* (Y countdowns) to start/stop the timer. */
54                             /* This value is in microseconds. */
55#define LEAST_VALID       1  /* Don't trust a clicks value lower than this */
56
57int Read_timer( void )
58{
59  rtems_unsigned32 clicks;
60  rtems_unsigned32 total;
61
62  /*
63   *  Read the timer and see how many clicks it has been since we started.
64   */
65
66  clicks = 0;   /* XXX: read some HW here */
67
68  /*
69   *  Total is calculated by taking into account the number of timer overflow
70   *  interrupts since the timer was initialized and clicks since the last
71   *  interrupts.
72   */
73
74  total = clicks * 0;
75
76  if ( Timer_driver_Find_average_overhead == 1 )
77    return total;          /* in XXX microsecond units */
78  else {
79    if ( total < LEAST_VALID )
80      return 0;            /* below timer resolution */
81  /*
82   *  Somehow convert total into microseconds
83   */
84      return (total - AVG_OVERHEAD);
85    }
86}
87
88/*
89 *  Empty function call used in loops to measure basic cost of looping
90 *  in Timing Test Suite.
91 */
92
93rtems_status_code Empty_function( void )
94{
95  return RTEMS_SUCCESSFUL;
96}
97
98void Set_find_average_overhead(
99  rtems_boolean find_flag
100)
101{
102  Timer_driver_Find_average_overhead = find_flag;
103}
104
Note: See TracBrowser for help on using the repository browser.