source: rtems/c/src/lib/libbsp/or1k/or1ksim/timer/timer.c @ fd57015

4.11
Last change on this file since fd57015 was fd57015, checked in by Hesham ALMatary <heshamelmatary@…>, on Aug 20, 2014 at 5:23:20 PM

Add new (first) OpenRISC BSP called or1ksim.

This BSP is intended to run on or1ksim (the main OpenRISC emulator).
Fixed version according to Joel comments from the mailing list.

  • Property mode set to 100644
File size: 1.5 KB
Line 
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
35uint32_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 = 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.