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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [rtems/] [c/] [src/] [lib/] [libbsp/] [no_cpu/] [no_bsp/] [timer/] [timer.c] - Blame information for rev 30

Go to most recent revision | 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-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.OARcorp.com/rtems/license.html.
17
 *
18
 *  $Id: timer.c,v 1.2 2001-09-27 12:00:27 chris Exp $
19
 */
20
 
21
#include <rtems.h>
22
#include <bsp.h>
23
 
24
rtems_unsigned32 Timer_interrupts;
25
rtems_boolean Timer_driver_Find_average_overhead;
26
 
27
void 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
 
57
int 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
 
93
rtems_status_code Empty_function( void )
94
{
95
  return RTEMS_SUCCESSFUL;
96
}
97
 
98
void Set_find_average_overhead(
99
  rtems_boolean find_flag
100
)
101
{
102
  Timer_driver_Find_average_overhead = find_flag;
103
}
104
 

powered by: WebSVN 2.1.0

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