OpenCores
URL https://opencores.org/ocsvn/openrisc_me/openrisc_me/trunk

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [rtos/] [rtems/] [c/] [src/] [lib/] [libcpu/] [a29k/] [timer/] [timer.c] - Blame information for rev 173

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 30 unneback
/*  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: timer.c,v 1.2 2001-09-27 12:01:20 chris Exp $
20
 */
21
 
22
#ifndef lint
23
static 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
 
32
static unsigned32 read_timer( void )
33
{
34
  return 0; /* do something with real hardware here */
35
}
36
 
37
static rtems_boolean Timer_driver_Find_average_overhead;
38
static unsigned32 Timer_initial_value = 0;
39
 
40
void 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
 
66
int 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
 
110
rtems_status_code Empty_function( void )
111
{
112
  return RTEMS_SUCCESSFUL;
113
}
114
 
115
void Set_find_average_overhead(
116
  rtems_boolean find_flag
117
)
118
{
119
  Timer_driver_Find_average_overhead = find_flag;
120
}
121
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.