source: rtems/bsps/sparc/leon2/btimer/btimer.c @ e0dd8a5a

5
Last change on this file since e0dd8a5a was e0dd8a5a, checked in by Sebastian Huber <sebastian.huber@…>, on 04/20/18 at 10:08:42

bsps: Move benchmark timer to bsps

This patch is a part of the BSP source reorganization.

Update #3285.

  • 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.