source: rtems/bsps/or1k/generic_or1k/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: 1.5 KB
Line 
1/**
2 * @file
3 *
4 * @ingroup generic_or1k
5 *
6 * @brief Benchmark timer support.
7 */
8
9/*
10 * Copyright (c) 2014-2015 by Hesham ALMatary
11 *
12 *  The license and distribution terms for this file may be
13 *  found in the file LICENSE in this distribution or at
14 *  http://www.rtems.org/license/LICENSE
15 */
16
17#include <rtems.h>
18#include <rtems/btimer.h>
19#include <bsp/generic_or1k.h>
20#include <rtems/score/or1k-utility.h>
21
22#define OR1K_NANOSECONDS_PER_CLK_CYCLE 10
23
24static bool benchmark_timer_find_average_overhead = false;
25static uint64_t benchmark_timer_base;
26
27void benchmark_timer_initialize(void)
28{
29  benchmark_timer_base = _OR1K_mfspr(CPU_OR1K_SPR_TTCR);
30}
31
32#define AVG_OVERHEAD  0
33#define LEAST_VALID   1
34
35benchmark_timer_t benchmark_timer_read( void )
36{
37  uint64_t         clicks;
38  uint64_t         total;
39  uint64_t         delta;
40  /*
41   *  Read the timer and see how many clicks (clock cycles)
42   *  has passed since timer initialization.
43   */
44  clicks = _OR1K_mfspr(CPU_OR1K_SPR_TTCR);
45
46  delta = clicks - benchmark_timer_base;
47
48  /* total in nanoseconds */
49  total = OR1K_NANOSECONDS_PER_CLK_CYCLE * (delta);
50
51  if ( benchmark_timer_find_average_overhead == true )
52    return total;          /* in nanoseconds microsecond units */
53  else {
54    if ( total < LEAST_VALID )
55      return 0;            /* below timer resolution */
56
57      return (total - AVG_OVERHEAD);
58  }
59}
60
61void benchmark_timer_disable_subtracting_average_overhead(bool find_flag)
62{
63  benchmark_timer_find_average_overhead = find_flag;
64}
Note: See TracBrowser for help on using the repository browser.