source: rtems/c/src/lib/libbsp/lm32/shared/milkymist_timer/timer.c @ c499856

4.115
Last change on this file since c499856 was c499856, checked in by Chris Johns <chrisj@…>, on 03/20/14 at 21:10:47

Change all references of rtems.com to rtems.org.

  • Property mode set to 100644
File size: 2.2 KB
Line 
1/*  timer.c
2 *
3 *  This file manages the benchmark timer used by the RTEMS Timing
4 *  Test Suite.  Each measured time period is demarcated by calls to
5 *  benchmark_timer_initialize() and benchmark_timer_read().
6 *  benchmark_timer_read() usually returns the number of microseconds
7 *  since benchmark_timer_initialize() exitted.
8 *
9 *  NOTE: It is important that the timer start/stop overhead be
10 *        determined when porting or modifying this code.
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 *  COPYRIGHT (c) Yann Sionneau <yann.sionneau@telecom-sudparis.eu> (GSoC 2010)
17 *  Telecom SudParis
18 */
19
20#include <rtems.h>
21#include <bsp.h>
22#include <rtems/btimer.h>
23#include "../include/system_conf.h"
24#include "../../shared/clock/clock.h"
25
26bool benchmark_timer_find_average_overhead;
27
28void benchmark_timer_initialize(void)
29{
30  MM_WRITE(MM_TIMER1_COMPARE, 0xffffffff);
31  MM_WRITE(MM_TIMER1_COUNTER, 0);
32  MM_WRITE(MM_TIMER1_CONTROL, TIMER_ENABLE);
33}
34
35/*
36 *  The following controls the behavior of benchmark_timer_read().
37 *
38 *  AVG_OVEREHAD is the overhead for starting and stopping the timer.  It
39 *  is usually deducted from the number returned.
40 *
41 *  LEAST_VALID is the lowest number this routine should trust.  Numbers
42 *  below this are "noise" and zero is returned.
43 */
44
45#define AVG_OVERHEAD      4  /* It typically takes X.X microseconds */
46                             /* (Y countdowns) to start/stop the timer. */
47                             /* This value is in microseconds. */
48#define LEAST_VALID       4  /* Don't trust a clicks value lower than this */
49
50uint32_t benchmark_timer_read(void)
51{
52  uint32_t ticks;
53  uint32_t total;
54
55  ticks = MM_READ(MM_TIMER1_COUNTER);
56  if (ticks == 0xffffffff)
57    printk("Timer overflow!\n");
58
59  total = ticks / (MM_READ(MM_FREQUENCY) / 1000000);
60
61  if (benchmark_timer_find_average_overhead)
62    return total;
63  else
64  {
65    if (total < LEAST_VALID)
66      return 0;
67
68    return (total - AVG_OVERHEAD);
69  }
70}
71
72void benchmark_timer_disable_subtracting_average_overhead(
73  bool find_flag
74)
75{
76  benchmark_timer_find_average_overhead = find_flag;
77}
Note: See TracBrowser for help on using the repository browser.