source: rtems/c/src/lib/libbsp/no_cpu/no_bsp/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: 2.5 KB
Line 
1/*  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 *  benchmark_timer_initialize() and benchmark_timer_read().  benchmark_timer_read() usually returns
6 *  the number of microseconds since benchmark_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.rtems.org/license/LICENSE.
17 */
18
19#include <rtems.h>
20#include <rtems/btimer.h>
21#include <bsp.h>
22
23uint32_t         Timer_interrupts;
24bool benchmark_timer_find_average_overhead;
25
26void benchmark_timer_initialize( void )
27{
28
29  /*
30   *  Timer has never overflowed.  This may not be necessary on some
31   *  implemenations of timer but ....
32   */
33
34  Timer_interrupts = 0;
35
36  /*
37   *  Somehow start the timer
38   */
39}
40
41/*
42 *  The following controls the behavior of benchmark_timer_read().
43 *
44 *  AVG_OVEREHAD is the overhead for starting and stopping the timer.  It
45 *  is usually deducted from the number returned.
46 *
47 *  LEAST_VALID is the lowest number this routine should trust.  Numbers
48 *  below this are "noise" and zero is returned.
49 */
50
51#define AVG_OVERHEAD      0  /* It typically takes X.X microseconds */
52                             /* (Y countdowns) to start/stop the timer. */
53                             /* This value is in microseconds. */
54#define LEAST_VALID       1  /* Don't trust a clicks value lower than this */
55
56benchmark_timer_t benchmark_timer_read( void )
57{
58  uint32_t         clicks;
59  uint32_t         total;
60
61  /*
62   *  Read the timer and see how many clicks it has been since we started.
63   */
64
65  clicks = 0;   /* XXX: read some HW here */
66
67  /*
68   *  Total is calculated by taking into account the number of timer overflow
69   *  interrupts since the timer was initialized and clicks since the last
70   *  interrupts.
71   */
72
73  total = clicks * 0;
74
75  if ( benchmark_timer_find_average_overhead == true )
76    return total;          /* in XXX microsecond units */
77  else {
78    if ( total < LEAST_VALID )
79      return 0;            /* below timer resolution */
80  /*
81   *  Somehow convert total into microseconds
82   */
83      return (total - AVG_OVERHEAD);
84    }
85}
86
87void benchmark_timer_disable_subtracting_average_overhead(
88  bool find_flag
89)
90{
91  benchmark_timer_find_average_overhead = find_flag;
92}
Note: See TracBrowser for help on using the repository browser.