source: rtems/c/src/lib/libcpu/a29k/timer/timer.c @ 948a069

Last change on this file since 948a069 was 948a069, checked in by Joel Sherrill <joel.sherrill@…>, on 09/04/03 at 17:32:05

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

  • clock/ckinit.c, timer/timer.c, timer/timerisr.c: Removed incorrect statement about copyright assignment.
  • Property mode set to 100644
File size: 2.8 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 *
14 *  $Id$
15 */
16
17#ifndef lint
18static char _sccsid[] = "@(#)timer.c 05/07/96     1.4\n";
19#endif
20
21#include <rtems.h>
22
23#define CLOCKS_PER_MICROSECOND ( CPU_CLOCK_RATE_MHZ )
24#define TIMER_MAX_VALUE 0xffffffff
25
26static unsigned32 read_timer( void )
27{
28  return 0; /* do something with real hardware here */
29}
30
31static rtems_boolean Timer_driver_Find_average_overhead;
32static unsigned32 Timer_initial_value = 0;
33
34void Timer_initialize( void )
35{
36   Timer_initial_value = read_timer();
37
38  /*
39   *  Somehow start the timer
40   */
41
42  /* Timer is always running */
43}
44
45/*
46 *  The following controls the behavior of Read_timer().
47 *
48 *  AVG_OVEREHAD is the overhead for starting and stopping the timer.  It
49 *  is usually deducted from the number returned.
50 *
51 *  LEAST_VALID is the lowest number this routine should trust.  Numbers
52 *  below this are "noise" and zero is returned.
53 */
54
55#define AVG_OVERHEAD      8  /* It typically takes X.X microseconds */
56                             /* (Y countdowns) to start/stop the timer. */
57                             /* This value is in cycles. */
58#define LEAST_VALID       1  /* Don't trust a clicks value lower than this */
59
60int Read_timer( void )
61{
62  unsigned64 clicks;
63  unsigned32 total;
64
65  /*
66   *  Read the timer and see how many clicks it has been since we started.
67   */
68
69  clicks = read_timer();   /* XXX: read some HW here */
70  if (clicks < Timer_initial_value)
71  {
72      clicks += TIMER_MAX_VALUE;
73  }
74  clicks -= Timer_initial_value;
75
76  /*
77   *  Total is calculated by taking into account the number of timer overflow
78   *  interrupts since the timer was initialized and clicks since the last
79   *  interrupts.
80   */
81#if 0 /* leave total in number of cycles */
82   total = clicks / CLOCKS_PER_MICROSECOND;
83#else
84   total = clicks;
85#endif
86
87  if ( Timer_driver_Find_average_overhead == 1 )
88    return total;          /* in # cycles units */
89  else {
90    if ( total < LEAST_VALID )
91      return 0;            /* below timer resolution */
92  /*
93   *  leave total in cycles
94   */
95      return (total - AVG_OVERHEAD);
96    }
97}
98
99/*
100 *  Empty function call used in loops to measure basic cost of looping
101 *  in Timing Test Suite.
102 */
103
104rtems_status_code Empty_function( void )
105{
106  return RTEMS_SUCCESSFUL;
107}
108
109void Set_find_average_overhead(
110  rtems_boolean find_flag
111)
112{
113  Timer_driver_Find_average_overhead = find_flag;
114}
115
Note: See TracBrowser for help on using the repository browser.