source: rtems/c/src/lib/libbsp/arm/edb7312/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: 2.4 KB
Line 
1/*
2 * Cirrus EP7312 Timer driver
3 *
4 * Copyright (c) 2002 by Jay Monkman <jtm@smoothsmoothie.com>
5 *
6 *  The license and distribution terms for this file may be
7 *  found in the file LICENSE in this distribution or at
8 *  http://www.rtems.org/license/LICENSE.
9 *
10 * Notes:
11 *  This file manages the benchmark timer used by the RTEMS Timing Test
12 *  Suite.  Each measured time period is demarcated by calls to
13 *  benchmark_timer_initialize() and benchmark_timer_read().  benchmark_timer_read() usually returns
14 *  the number of microseconds since benchmark_timer_initialize() exitted.
15 *
16 *  It is important that the timer start/stop overhead be determined
17 *  when porting or modifying this code.
18*/
19
20#include <rtems.h>
21#include <bsp.h>
22#include <rtems/btimer.h>
23#include <ep7312.h>
24
25uint16_t         tstart;
26bool benchmark_timer_find_average_overhead;
27
28void benchmark_timer_initialize( void )
29{
30    *EP7312_SYSCON1 |= EP7312_SYSCON1_TC2_512KHZ;
31    *EP7312_TC2D = 0xffff;
32}
33
34/*
35 *  The following controls the behavior of benchmark_timer_read().
36 *
37 *  AVG_OVEREHAD is the overhead for starting and stopping the timer.  It
38 *  is usually deducted from the number returned.
39 *
40 *  LEAST_VALID is the lowest number this routine should trust.  Numbers
41 *  below this are "noise" and zero is returned.
42 */
43
44#define AVG_OVERHEAD      0  /* It typically takes X.X microseconds */
45                             /* (Y countdowns) to start/stop the timer. */
46                             /* This value is in microseconds. */
47#define LEAST_VALID       1  /* Don't trust a clicks value lower than this */
48
49benchmark_timer_t benchmark_timer_read( void )
50{
51  uint16_t         t;
52  uint32_t         total;
53  t = *EP7312_TC2D;
54
55  /*
56   *  Total is calculated by taking into account the number of timer overflow
57   *  interrupts since the timer was initialized and clicks since the last
58   *  interrupts.
59   */
60
61  total = (uint32_t)0x0000ffff - t;  /* result is 1/512000 = ~2 uS */
62  total = (total * 1953) / 1000;   /* convert to uS */
63  if ( benchmark_timer_find_average_overhead == true )
64    return total;          /* in XXX microsecond units */
65  else {
66    if ( total < LEAST_VALID )
67      return 0;            /* below timer resolution */
68  /*
69   *  Somehow convert total into microseconds
70   */
71      return (total - AVG_OVERHEAD);
72    }
73}
74
75void benchmark_timer_disable_subtracting_average_overhead(
76  bool find_flag
77)
78{
79  benchmark_timer_find_average_overhead = find_flag;
80}
Note: See TracBrowser for help on using the repository browser.