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

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [rtos/] [rtems/] [c/] [src/] [lib/] [libcpu/] [mips64orion/] [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 contains the initialization code for the IDT 4650 timer driver.
4
 *
5
 *  Author:     Craig Lebakken <craigl@transition.com>
6
 *
7
 *  COPYRIGHT (c) 1996 by Transition Networks Inc.
8
 *
9
 *  To anyone who acknowledges that this file is provided "AS IS"
10
 *  without any express or implied warranty:
11
 *      permission to use, copy, modify, and distribute this file
12
 *      for any purpose is hereby granted without fee, provided that
13
 *      the above copyright notice and this notice appears in all
14
 *      copies, and that the name of Transition Networks not be used in
15
 *      advertising or publicity pertaining to distribution of the
16
 *      software without specific, written prior permission.
17
 *      Transition Networks makes no representations about the suitability
18
 *      of this software for any purpose.
19
 *
20
 *  derived from src/lib/libbsp/no_cpu/no_bsp/timer/timer.c
21
 *
22
 *  This file manages the benchmark timer used by the RTEMS Timing Test
23
 *  Suite.  Each measured time period is demarcated by calls to
24
 *  Timer_initialize() and Read_timer().  Read_timer() usually returns
25
 *  the number of microseconds since Timer_initialize() exitted.
26
 *
27
 *  NOTE: It is important that the timer start/stop overhead be
28
 *        determined when porting or modifying this code.
29
 *
30
 *  COPYRIGHT (c) 1989-1999.
31
 *  On-Line Applications Research Corporation (OAR).
32
 *
33
 *  The license and distribution terms for this file may be
34
 *  found in the file LICENSE in this distribution or at
35
 *  http://www.OARcorp.com/rtems/license.html.
36
 *
37
 *  $Id: timer.c,v 1.2 2001-09-27 12:01:22 chris Exp $
38
 */
39
 
40
/*
41
 *  Rather than deleting this, it is commented out to (hopefully) help
42
 *  the submitter send updates.
43
 *
44
 *  static char _sccsid[] = "@(#)timer.c 08/20/96     1.5\n";
45
 */
46
 
47
 
48
#include <rtems.h>
49
 
50
#define CLOCKS_PER_MICROSECOND ( CPU_CLOCK_RATE_MHZ )
51
#define TIMER_MAX_VALUE 0xffffffff
52
 
53
extern unsigned32 mips_read_timer( void );
54
 
55
static rtems_boolean Timer_driver_Find_average_overhead;
56
static unsigned32 Timer_initial_value = 0;
57
 
58
void Timer_initialize( void )
59
{
60
   Timer_initial_value = mips_read_timer();
61
  /*
62
   *  Somehow start the timer
63
   */
64
 
65
  /* Timer on 4650 is always running */
66
}
67
 
68
/*
69
 *  The following controls the behavior of Read_timer().
70
 *
71
 *  AVG_OVEREHAD is the overhead for starting and stopping the timer.  It
72
 *  is usually deducted from the number returned.
73
 *
74
 *  LEAST_VALID is the lowest number this routine should trust.  Numbers
75
 *  below this are "noise" and zero is returned.
76
 */
77
 
78
#define AVG_OVERHEAD      8  /* It typically takes X.X microseconds */
79
                             /* (Y countdowns) to start/stop the timer. */
80
                             /* This value is in cycles. */
81
#define LEAST_VALID       1  /* Don't trust a clicks value lower than this */
82
 
83
int Read_timer( void )
84
{
85
  unsigned64 clicks;
86
  unsigned32 total;
87
 
88
  /*
89
   *  Read the timer and see how many clicks it has been since we started.
90
   */
91
 
92
  clicks = mips_read_timer();   /* XXX: read some HW here */
93
  if (clicks < Timer_initial_value)
94
  {
95
      clicks += TIMER_MAX_VALUE;
96
  }
97
  clicks -= Timer_initial_value;
98
 
99
  /*
100
   *  Total is calculated by taking into account the number of timer overflow
101
   *  interrupts since the timer was initialized and clicks since the last
102
   *  interrupts.
103
   */
104
#if 0 /* leave total in number of cycles */
105
   total = clicks / CLOCKS_PER_MICROSECOND;
106
#else
107
   total = clicks;
108
#endif
109
 
110
  if ( Timer_driver_Find_average_overhead == 1 )
111
    return total;          /* in # cycles units */
112
  else {
113
    if ( total < LEAST_VALID )
114
      return 0;            /* below timer resolution */
115
  /*
116
   *  leave total in cycles
117
   */
118
      return (total - AVG_OVERHEAD);
119
    }
120
}
121
 
122
/*
123
 *  Empty function call used in loops to measure basic cost of looping
124
 *  in Timing Test Suite.
125
 */
126
 
127
rtems_status_code Empty_function( void )
128
{
129
  return RTEMS_SUCCESSFUL;
130
}
131
 
132
void Set_find_average_overhead(
133
  rtems_boolean find_flag
134
)
135
{
136
  Timer_driver_Find_average_overhead = find_flag;
137
}
138
 

powered by: WebSVN 2.1.0

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