source: rtems/c/src/lib/libcpu/arm/at91rm9200/timer/timer.c @ 7d6a5e2

4.104.114.95
Last change on this file since 7d6a5e2 was 7d6a5e2, checked in by Joel Sherrill <joel.sherrill@…>, on 08/31/08 at 16:49:33

2008-08-31 Joel Sherrill <joel.sherrill@…>

  • at91rm9200/timer/timer.c, lpc22xx/timer/timer.c, mc9328mxl/timer/timer.c, s3c2400/timer/timer.c, s3c24xx/timer/timer.c: Rename timer driver methods to follow RTEMS programming conventions.
  • Property mode set to 100644
File size: 3.0 KB
Line 
1/*
2 * Cogent CSB337 Timer driver
3 *
4 * This uses timer 0 for timing measurments.
5 *
6 * Copyright (c) 2004 by Jay Monkman <jtm@lopingdog.com>
7 *     
8 *  The license and distribution terms for this file may be
9 *  found in the file LICENSE in this distribution or at
10 *
11 *  http://www.rtems.com/license/LICENSE.
12 *
13 * Notes:
14 *  This file manages the benchmark timer used by the RTEMS Timing Test
15 *  Suite.  Each measured time period is demarcated by calls to
16 *  benchmark_timerinitialize() and benchmark_timerread().  benchmark_timerread() usually returns
17 *  the number of microseconds since benchmark_timerinitialize() exitted.
18 *
19 *  It is important that the timer start/stop overhead be determined
20 *  when porting or modifying this code.
21 *
22 *  $Id$
23 */
24
25#include <rtems.h>
26#include <bsp.h>
27#include <at91rm9200.h>
28#include <at91rm9200_pmc.h>
29
30uint16_t tstart;
31rtems_boolean benchmark_timerfind_average_overhead;
32uint32_t tick_time;
33/*
34 * Set up TC0 -
35 *   timer_clock2 (MCK/8)
36 *   capture mode - this shouldn't matter
37 */
38void benchmark_timerinitialize( void )
39{
40    uint32_t tmr_freq;
41
42    /* since we are using timer_clock2, divide mck by 8 */
43    tmr_freq = at91rm9200_get_mck() / 8;
44
45    TC_TC0_REG(TC_CMR) = TC_CMR_TCCLKS(1);   /* timer_clock2 */
46    TC_TC0_REG(TC_CCR) = (TC_CCR_CLKEN       /* enable the counter */
47                          | TC_CCR_SWTRG);   /* start it up */
48
49    /* tick time in nanoseconds */
50    tick_time = 1000000000/tmr_freq;
51
52}
53
54/*
55 *  The following controls the behavior of benchmark_timerread().
56 *
57 *  AVG_OVEREHAD is the overhead for starting and stopping the timer.  It
58 *  is usually deducted from the number returned.
59 *
60 *  LEAST_VALID is the lowest number this routine should trust.  Numbers
61 *  below this are "noise" and zero is returned.
62 */
63
64#define AVG_OVERHEAD      0  /* It typically takes X.X microseconds */
65                             /* (Y countdowns) to start/stop the timer. */
66                             /* This value is in microseconds. */
67#define LEAST_VALID       1  /* Don't trust a clicks value lower than this */
68
69int benchmark_timerread( void )
70{
71  uint16_t t;
72  uint32_t total;
73  t = TC_TC0_REG(TC_CV);
74
75  /*
76   *  Total is calculated by taking into account the number of timer overflow
77   *  interrupts since the timer was initialized and clicks since the last
78   *  interrupts.
79   */
80
81  total = t * tick_time;
82
83  if ( benchmark_timerfind_average_overhead == 1 )
84    return total;          /* in nanosecond units */
85  else {
86    if ( total < LEAST_VALID )
87      return 0;            /* below timer resolution */
88  /*
89   *  Somehow convert total into microseconds
90   */
91      return (total - AVG_OVERHEAD);
92    }
93}
94
95/*
96 *  Empty function call used in loops to measure basic cost of looping
97 *  in Timing Test Suite.
98 */
99
100rtems_status_code benchmark_timerempty_function( void )
101{
102  return RTEMS_SUCCESSFUL;
103}
104
105void benchmark_timerdisable_subtracting_average_overhead(
106  rtems_boolean find_flag
107)
108{
109  benchmark_timerfind_average_overhead = find_flag;
110}
111
Note: See TracBrowser for help on using the repository browser.