source: rtems/c/src/lib/libcpu/mips/timer/timer.c @ 707f5c7

4.104.114.84.95
Last change on this file since 707f5c7 was f817b02, checked in by Joel Sherrill <joel.sherrill@…>, on 11/04/99 at 18:05:09

The files in libcpu should not be directly dependent on any BSP. In
particular, using bsp.h, or getting information from the BSP which
should properly be obtained from RTEMS is forbidden. This is
necessary to strengthen the division between the BSP independent
parts of RTEMS and the BSPs themselves. This started after
comments and analysis by Ralf Corsepius <corsepiu@…>.
The changes primarily eliminated the need to include bsp.h and
peeking at BSP_Configuration. The use of Cpu_table in each
BSP needs to be eliminated.

  • Property mode set to 100644
File size: 3.9 KB
Line 
1/*  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-1998.
31 *  On-Line Applications Research Corporation (OAR).
32 *  Copyright assigned to U.S. Government, 1994.
33 *
34 *  The license and distribution terms for this file may be
35 *  found in the file LICENSE in this distribution or at
36 *  http://www.OARcorp.com/rtems/license.html.
37 *
38 *  $Id$
39 */
40
41/*
42 *  Rather than deleting this, it is commented out to (hopefully) help
43 *  the submitter send updates.
44 *
45 *  static char _sccsid[] = "@(#)timer.c 08/20/96     1.5\n";
46 */
47
48
49#include <rtems.h>
50
51#define CLOCKS_PER_MICROSECOND ( CPU_CLOCK_RATE_MHZ )
52#define TIMER_MAX_VALUE 0xffffffff
53
54extern unsigned32 mips_read_timer( void );
55
56static rtems_boolean Timer_driver_Find_average_overhead;
57static unsigned32 Timer_initial_value = 0;
58
59void Timer_initialize( void )
60{
61   Timer_initial_value = mips_read_timer();
62  /*
63   *  Somehow start the timer
64   */
65
66  /* Timer on 4650 is always running */
67}
68
69/*
70 *  The following controls the behavior of Read_timer().
71 *
72 *  AVG_OVEREHAD is the overhead for starting and stopping the timer.  It
73 *  is usually deducted from the number returned.
74 *
75 *  LEAST_VALID is the lowest number this routine should trust.  Numbers
76 *  below this are "noise" and zero is returned.
77 */
78
79#define AVG_OVERHEAD      8  /* It typically takes X.X microseconds */
80                             /* (Y countdowns) to start/stop the timer. */
81                             /* This value is in cycles. */
82#define LEAST_VALID       1  /* Don't trust a clicks value lower than this */
83
84int Read_timer( void )
85{
86  unsigned64 clicks;
87  unsigned32 total;
88
89  /*
90   *  Read the timer and see how many clicks it has been since we started.
91   */
92
93  clicks = mips_read_timer();   /* XXX: read some HW here */
94  if (clicks < Timer_initial_value)
95  {
96      clicks += TIMER_MAX_VALUE;
97  }
98  clicks -= Timer_initial_value;
99
100  /*
101   *  Total is calculated by taking into account the number of timer overflow
102   *  interrupts since the timer was initialized and clicks since the last
103   *  interrupts.
104   */
105#if 0 /* leave total in number of cycles */
106   total = clicks / CLOCKS_PER_MICROSECOND;
107#else
108   total = clicks;
109#endif
110
111  if ( Timer_driver_Find_average_overhead == 1 )
112    return total;          /* in # cycles units */
113  else {
114    if ( total < LEAST_VALID )
115      return 0;            /* below timer resolution */
116  /*
117   *  leave total in cycles
118   */
119      return (total - AVG_OVERHEAD);
120    }
121}
122
123/*
124 *  Empty function call used in loops to measure basic cost of looping
125 *  in Timing Test Suite.
126 */
127
128rtems_status_code Empty_function( void )
129{
130  return RTEMS_SUCCESSFUL;
131}
132
133void Set_find_average_overhead(
134  rtems_boolean find_flag
135)
136{
137  Timer_driver_Find_average_overhead = find_flag;
138}
139
Note: See TracBrowser for help on using the repository browser.