source: rtems/c/src/lib/libbsp/sparc/leon2/timer/timer.c @ 6cd2074

4.115
Last change on this file since 6cd2074 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.0 KB
Line 
1/**
2 * @file
3 * @ingroup sparc_leon2
4 * @brief Implement a benchmark timer using timer 2
5 */
6
7/*  timer.c
8 *
9 *  This file implements a benchmark timer using timer 2.
10 *
11 *  COPYRIGHT (c) 1989-1998.
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 *  Ported to LEON implementation of the SPARC by On-Line Applications
19 *  Research Corporation (OAR) under contract to the European Space
20 *  Agency (ESA).
21 *
22 *  LEON modifications of respective RTEMS file: COPYRIGHT (c) 1995.
23 *  European Space Agency.
24 */
25
26
27#include <bsp.h>
28#include <rtems/btimer.h>
29
30bool benchmark_timer_find_average_overhead;
31
32bool benchmark_timer_is_initialized = false;
33
34void benchmark_timer_initialize(void)
35{
36  /*
37   *  Timer runs long and accurate enough not to require an interrupt.
38   */
39
40  if ( benchmark_timer_is_initialized == false ) {
41
42    /* approximately 1 us per countdown */
43    LEON_REG.Timer_Counter_2 = 0xffffff;
44    LEON_REG.Timer_Reload_2 = 0xffffff;
45
46  } else {
47    benchmark_timer_is_initialized = true;
48  }
49
50  LEON_REG.Timer_Control_2 = (
51    LEON_REG_TIMER_COUNTER_ENABLE_COUNTING |
52      LEON_REG_TIMER_COUNTER_LOAD_COUNTER
53  );
54
55}
56
57#define AVG_OVERHEAD      3  /* It typically takes 3.0 microseconds */
58                             /*     to start/stop the timer. */
59#define LEAST_VALID       2  /* Don't trust a value lower than this */
60
61benchmark_timer_t benchmark_timer_read(void)
62{
63  uint32_t total;
64
65  total = LEON_REG.Timer_Counter_2;
66
67  total = 0xffffff - total;
68
69  if ( benchmark_timer_find_average_overhead == true )
70    return total;          /* in one microsecond units */
71
72  if ( total < LEAST_VALID )
73    return 0;            /* below timer resolution */
74
75  return total - AVG_OVERHEAD;
76}
77
78void benchmark_timer_disable_subtracting_average_overhead(
79  bool find_flag
80)
81{
82  benchmark_timer_find_average_overhead = find_flag;
83}
Note: See TracBrowser for help on using the repository browser.