source: rtems/c/src/lib/libcpu/mips/timer/timer.c @ 8fbe2e6

4.11
Last change on this file since 8fbe2e6 was 8fbe2e6, checked in by Joel Sherrill <joel.sherrill@…>, on Sep 4, 2014 at 1:59:49 PM

Use correct prototype of benchmark_timer_read()

This change starts with removing the effectively empty file
timerdrv.h. The prototypes for benchmark_timer_XXX() were in
btimer.h which was not universally used. Thus every use of
timerdrv.h had to be changed to btimer.h. Then the prototypes
for benchmark_timer_read() had to be adjusted to return
benchmark_timer_t rather than int or uint32_t.

I took this opportunity to also correct the file headers to
separate the copyright from the file description comments which
is needed to ensure the copyright isn't propagated into Doxygen
output.

  • Property mode set to 100644
File size: 3.3 KB
Line 
1/**
2 *  @file
3 *  @brief IDT 4650 Timer Driver.
4 *
5 *  This file manages the benchmark timer used by the RTEMS Timing Test
6 *  Suite.
7 */
8
9/*
10 *  Author:     Craig Lebakken <craigl@transition.com>
11 *
12 *  COPYRIGHT (c) 1996 by Transition Networks Inc.
13 *
14 *  To anyone who acknowledges that this file is provided "AS IS"
15 *  without any express or implied warranty:
16 *      permission to use, copy, modify, and distribute this file
17 *      for any purpose is hereby granted without fee, provided that
18 *      the above copyright notice and this notice appears in all
19 *      copies, and that the name of Transition Networks not be used in
20 *      advertising or publicity pertaining to distribution of the
21 *      software without specific, written prior permission.
22 *      Transition Networks makes no representations about the suitability
23 *      of this software for any purpose.
24 *
25 *  derived from src/lib/libbsp/no_cpu/no_bsp/timer/timer.c
26 *
27 *  COPYRIGHT (c) 1989-1999.
28 *  On-Line Applications Research Corporation (OAR).
29 *
30 *  The license and distribution terms for this file may be
31 *  found in the file LICENSE in this distribution or at
32 *  http://www.rtems.org/license/LICENSE.
33 */
34
35#include <rtems.h>
36#include <rtems/btimer.h>
37
38#define CLOCKS_PER_MICROSECOND ( CPU_CLOCK_RATE_MHZ )
39#define TIMER_MAX_VALUE 0xffffffff
40
41extern uint32_t   mips_read_timer( void );
42
43static bool benchmark_timer_find_average_overhead;
44static uint32_t   benchmark_timer_initial_value = 0;
45
46void benchmark_timer_initialize( void )
47{
48   benchmark_timer_initial_value = mips_read_timer();
49  /*
50   *  Somehow start the timer
51   */
52
53  /* Timer on 4650 is always running */
54}
55
56/*
57 *  The following controls the behavior of benchmark_timer_read().
58 *
59 *  AVG_OVEREHAD is the overhead for starting and stopping the timer.  It
60 *  is usually deducted from the number returned.
61 *
62 *  LEAST_VALID is the lowest number this routine should trust.  Numbers
63 *  below this are "noise" and zero is returned.
64 */
65
66#define AVG_OVERHEAD      8  /* It typically takes X.X microseconds */
67                             /* (Y countdowns) to start/stop the timer. */
68                             /* This value is in cycles. */
69#define LEAST_VALID       1  /* Don't trust a clicks value lower than this */
70
71benchmark_timer_t benchmark_timer_read( void )
72{
73  uint64_t   clicks;
74  uint32_t   total;
75
76  /*
77   *  Read the timer and see how many clicks it has been since we started.
78   */
79
80  clicks = mips_read_timer();   /* XXX: read some HW here */
81  if (clicks < benchmark_timer_initial_value)
82  {
83      clicks += TIMER_MAX_VALUE;
84  }
85  clicks -= benchmark_timer_initial_value;
86
87  /*
88   *  Total is calculated by taking into account the number of timer overflow
89   *  interrupts since the timer was initialized and clicks since the last
90   *  interrupts.
91   */
92#if 0 /* leave total in number of cycles */
93   total = clicks / CLOCKS_PER_MICROSECOND;
94#else
95   total = clicks;
96#endif
97
98  if ( benchmark_timer_find_average_overhead == 1 )
99    return total;          /* in # cycles units */
100  else {
101    if ( total < LEAST_VALID )
102      return 0;            /* below timer resolution */
103  /*
104   *  leave total in cycles
105   */
106      return (total - AVG_OVERHEAD);
107    }
108}
109
110void benchmark_timer_disable_subtracting_average_overhead(bool find_flag)
111{
112  benchmark_timer_find_average_overhead = find_flag;
113}
Note: See TracBrowser for help on using the repository browser.