summaryrefslogtreecommitdiffstats
path: root/c/src/lib/libbsp/arm/raspberrypi/misc/timer.c
blob: e90af08290ea9fab19d9c7d3937ae2b6faa28e9e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/**
 * @file
 *
 * @ingroup raspberrypi
 *
 * @brief Benchmark timer support.
 */

/*
 * Copyright (c) 2013 by Alan Cudmore
 *
 *  The license and distribution terms for this file may be
 *  found in the file LICENSE in this distribution or at
 *
 *  http://www.rtems.org/license/LICENSE
 *
 */

#include <rtems.h>
#include <rtems/btimer.h>
#include <bsp/raspberrypi.h>

static bool benchmark_timer_find_average_overhead = false;

static uint64_t benchmark_timer_base;

void benchmark_timer_initialize(void)
{
  benchmark_timer_base = BCM2835_REG(BCM2835_GPU_TIMER_CLO);
}

benchmark_timer_t benchmark_timer_read(void)
{
  uint32_t delta = BCM2835_REG(BCM2835_GPU_TIMER_CLO) - benchmark_timer_base;

  if (benchmark_timer_find_average_overhead)
  {
    return delta;
  }
  else
  {
    return BCM2835_REG(BCM2835_GPU_TIMER_CLO);
  }
}

void benchmark_timer_disable_subtracting_average_overhead(bool find_average_overhead)
{
  benchmark_timer_find_average_overhead = find_average_overhead;
}