source: rtems/c/src/lib/libcpu/a29k/timer/timer.c @ 4c46630

4.104.114.84.95
Last change on this file since 4c46630 was 4c46630, checked in by Joel Sherrill <joel.sherrill@…>, on 01/31/00 at 15:15:10

Patch rtems-rc-20000118-1.diff from Ralf Corsepius <corsepiu@…>
that contains:

  • cleanups to configuration files
  • A reworked gccnewlib.spec.in: I have reformated it for enhanced readability and added more rtems-base packages. It now should be free of any installation conflicts (If there still remain some, they should be regarded as bugs).
  • A fix to the bin2boot RTEMS_BSP issue (make RTEMS_BSP="pc386 pc486" now works).
  • removes libbsp/bare/wrapup
  • Further cleanups
  • Property mode set to 100644
File size: 3.1 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#ifndef lint
23static char _sccsid[] = "@(#)timer.c 05/07/96     1.4\n";
24#endif
25
26#include <rtems.h>
27#include <bsp.h>
28
29#define CLOCKS_PER_MICROSECOND ( CPU_CLOCK_RATE_MHZ )
30#define TIMER_MAX_VALUE 0xffffffff
31
32static unsigned32 read_timer( void )
33{
34  return 0; /* do something with real hardware here */
35}
36
37static rtems_boolean Timer_driver_Find_average_overhead;
38static unsigned32 Timer_initial_value = 0;
39
40void Timer_initialize( void )
41{
42   Timer_initial_value = read_timer();
43
44  /*
45   *  Somehow start the timer
46   */
47
48  /* Timer on 4650 is always running */
49}
50
51/*
52 *  The following controls the behavior of Read_timer().
53 *
54 *  AVG_OVEREHAD is the overhead for starting and stopping the timer.  It
55 *  is usually deducted from the number returned.
56 *
57 *  LEAST_VALID is the lowest number this routine should trust.  Numbers
58 *  below this are "noise" and zero is returned.
59 */
60
61#define AVG_OVERHEAD      8  /* It typically takes X.X microseconds */
62                             /* (Y countdowns) to start/stop the timer. */
63                             /* This value is in cycles. */
64#define LEAST_VALID       1  /* Don't trust a clicks value lower than this */
65
66int Read_timer( void )
67{
68  unsigned64 clicks;
69  unsigned32 total;
70
71  /*
72   *  Read the timer and see how many clicks it has been since we started.
73   */
74
75  clicks = read_timer();   /* XXX: read some HW here */
76  if (clicks < Timer_initial_value)
77  {
78      clicks += TIMER_MAX_VALUE;
79  }
80  clicks -= Timer_initial_value;
81
82  /*
83   *  Total is calculated by taking into account the number of timer overflow
84   *  interrupts since the timer was initialized and clicks since the last
85   *  interrupts.
86   */
87#if 0 /* leave total in number of cycles */
88   total = clicks / CLOCKS_PER_MICROSECOND;
89#else
90   total = clicks;
91#endif
92
93  if ( Timer_driver_Find_average_overhead == 1 )
94    return total;          /* in # cycles units */
95  else {
96    if ( total < LEAST_VALID )
97      return 0;            /* below timer resolution */
98  /*
99   *  leave total in cycles
100   */
101      return (total - AVG_OVERHEAD);
102    }
103}
104
105/*
106 *  Empty function call used in loops to measure basic cost of looping
107 *  in Timing Test Suite.
108 */
109
110rtems_status_code Empty_function( void )
111{
112  return RTEMS_SUCCESSFUL;
113}
114
115void Set_find_average_overhead(
116  rtems_boolean find_flag
117)
118{
119  Timer_driver_Find_average_overhead = find_flag;
120}
121
Note: See TracBrowser for help on using the repository browser.