source: rtems/c/src/lib/libbsp/arm/edb7312/timer/timer.c @ 14102e1e

4.115
Last change on this file since 14102e1e was 14102e1e, checked in by Ralf Corsepius <ralf.corsepius@…>, on 02/09/11 at 11:38:36

2011-02-09 Ralf Corsépius <ralf.corsepius@…>

  • timer/timer.c: Include <rtems/btimer.h>. Fix benchmark_timer_read() definition.
  • Property mode set to 100644
File size: 2.4 KB
Line 
1/*
2 * Cirrus EP7312 Timer driver
3 *
4 * Copyright (c) 2002 by Jay Monkman <jtm@smoothsmoothie.com>
5 *
6 *  The license and distribution terms for this file may be
7 *  found in the file LICENSE in this distribution or at
8 *
9 *  http://www.rtems.com/license/LICENSE.
10 *
11 * Notes:
12 *  This file manages the benchmark timer used by the RTEMS Timing Test
13 *  Suite.  Each measured time period is demarcated by calls to
14 *  benchmark_timer_initialize() and benchmark_timer_read().  benchmark_timer_read() usually returns
15 *  the number of microseconds since benchmark_timer_initialize() exitted.
16 *
17 *  It is important that the timer start/stop overhead be determined
18 *  when porting or modifying this code.
19 *
20 *  $Id$
21*/
22
23#include <rtems.h>
24#include <bsp.h>
25#include <rtems/btimer.h>
26#include <ep7312.h>
27
28uint16_t         tstart;
29bool benchmark_timer_find_average_overhead;
30
31void benchmark_timer_initialize( void )
32{
33    *EP7312_SYSCON1 |= EP7312_SYSCON1_TC2_512KHZ;
34    *EP7312_TC2D = 0xffff;
35}
36
37/*
38 *  The following controls the behavior of benchmark_timer_read().
39 *
40 *  AVG_OVEREHAD is the overhead for starting and stopping the timer.  It
41 *  is usually deducted from the number returned.
42 *
43 *  LEAST_VALID is the lowest number this routine should trust.  Numbers
44 *  below this are "noise" and zero is returned.
45 */
46
47#define AVG_OVERHEAD      0  /* It typically takes X.X microseconds */
48                             /* (Y countdowns) to start/stop the timer. */
49                             /* This value is in microseconds. */
50#define LEAST_VALID       1  /* Don't trust a clicks value lower than this */
51
52uint32_t benchmark_timer_read( void )
53{
54  uint16_t         t;
55  uint32_t         total;
56  t = *EP7312_TC2D;
57
58  /*
59   *  Total is calculated by taking into account the number of timer overflow
60   *  interrupts since the timer was initialized and clicks since the last
61   *  interrupts.
62   */
63
64  total = (uint32_t)0x0000ffff - t;  /* result is 1/512000 = ~2 uS */
65  total = (total * 1953) / 1000;   /* convert to uS */
66  if ( benchmark_timer_find_average_overhead == true )
67    return total;          /* in XXX microsecond units */
68  else {
69    if ( total < LEAST_VALID )
70      return 0;            /* below timer resolution */
71  /*
72   *  Somehow convert total into microseconds
73   */
74      return (total - AVG_OVERHEAD);
75    }
76}
77
78void benchmark_timer_disable_subtracting_average_overhead(
79  bool find_flag
80)
81{
82  benchmark_timer_find_average_overhead = find_flag;
83}
Note: See TracBrowser for help on using the repository browser.