source: rtems/c/src/lib/libbsp/or1k/or1ksim/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: 1.5 KB
RevLine 
[fd57015]1/**
2 * @file
3 *
4 * @ingroup or1ksim
5 *
6 * @brief Benchmark timer support.
7 */
8
9/*
10 * Copyright (c) 2014 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/or1ksim.h>
20#include <rtems/score/or1k-utility.h>
21
22#define OR1KSIM_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
[8fbe2e6]35benchmark_timer_t benchmark_timer_read( void )
[fd57015]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 = OR1KSIM_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.