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

4.115
Last change on this file since 8fbe2e6 was 8fbe2e6, checked in by Joel Sherrill <joel.sherrill@…>, on 09/04/14 at 13:59:49

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
RevLine 
[8fbe2e6]1/**
2 *  @file
3 *  @brief IDT 4650 Timer Driver.
[f198c63]4 *
[8fbe2e6]5 *  This file manages the benchmark timer used by the RTEMS Timing Test
6 *  Suite.
7 */
8
9/*
[f198c63]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 *
[08311cc3]27 *  COPYRIGHT (c) 1989-1999.
[f198c63]28 *  On-Line Applications Research Corporation (OAR).
29 *
[98e4ebf5]30 *  The license and distribution terms for this file may be
31 *  found in the file LICENSE in this distribution or at
[c499856]32 *  http://www.rtems.org/license/LICENSE.
[f198c63]33 */
34
35#include <rtems.h>
[8fbe2e6]36#include <rtems/btimer.h>
[f198c63]37
38#define CLOCKS_PER_MICROSECOND ( CPU_CLOCK_RATE_MHZ )
39#define TIMER_MAX_VALUE 0xffffffff
40
[35f97010]41extern uint32_t   mips_read_timer( void );
[f198c63]42
[63e23b6e]43static bool benchmark_timer_find_average_overhead;
[290da88f]44static uint32_t   benchmark_timer_initial_value = 0;
[f198c63]45
[a903b7b]46void benchmark_timer_initialize( void )
[f198c63]47{
[290da88f]48   benchmark_timer_initial_value = mips_read_timer();
[f198c63]49  /*
50   *  Somehow start the timer
51   */
52
53  /* Timer on 4650 is always running */
54}
55
56/*
[a903b7b]57 *  The following controls the behavior of benchmark_timer_read().
[f198c63]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
[8fbe2e6]71benchmark_timer_t benchmark_timer_read( void )
[f198c63]72{
[35f97010]73  uint64_t   clicks;
74  uint32_t   total;
[f198c63]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 */
[290da88f]81  if (clicks < benchmark_timer_initial_value)
[f198c63]82  {
83      clicks += TIMER_MAX_VALUE;
84  }
[290da88f]85  clicks -= benchmark_timer_initial_value;
[f198c63]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
[a903b7b]98  if ( benchmark_timer_find_average_overhead == 1 )
[f198c63]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
[63e23b6e]110void benchmark_timer_disable_subtracting_average_overhead(bool find_flag)
[f198c63]111{
[a903b7b]112  benchmark_timer_find_average_overhead = find_flag;
[f198c63]113}
Note: See TracBrowser for help on using the repository browser.