source: rtems/c/src/lib/libcpu/arm/at91rm9200/timer/timer.c @ 8fbe2e6

4.11
Last change on this file since 8fbe2e6 was 8fbe2e6, checked in by Joel Sherrill <joel.sherrill@…>, on Sep 4, 2014 at 1:59:49 PM

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: 2.4 KB
Line 
1/**
2 * @file
3 * @brief Cogent CSB337 Timer driver
4 *
5 * This uses timer 0 for timing measurments.
6 */
7
8/*
9 *  Copyright (c) 2004 by Jay Monkman <jtm@lopingdog.com>
10 *
11 *  The license and distribution terms for this file may be
12 *  found in the file LICENSE in this distribution or at
13 *  http://www.rtems.org/license/LICENSE.
14 */
15
16#include <bsp.h>
17#include <rtems.h>
18#include <rtems/btimer.h>
19#include <at91rm9200.h>
20#include <at91rm9200_pmc.h>
21
22uint16_t tstart;
23bool benchmark_timer_find_average_overhead;
24uint32_t tick_time;
25/*
26 * Set up TC0 -
27 *   timer_clock2 (MCK/8)
28 *   capture mode - this shouldn't matter
29 */
30void benchmark_timer_initialize( void )
31{
32    uint32_t tmr_freq;
33
34    /* since we are using timer_clock2, divide mck by 8 */
35    tmr_freq = at91rm9200_get_mck() / 8;
36
37    TC_TC0_REG(TC_CMR) = TC_CMR_TCCLKS(1);   /* timer_clock2 */
38    TC_TC0_REG(TC_CCR) = (TC_CCR_CLKEN       /* enable the counter */
39                          | TC_CCR_SWTRG);   /* start it up */
40
41    /* tick time in nanoseconds */
42    tick_time = 1000000000/tmr_freq;
43
44}
45
46/*
47 *  The following controls the behavior of benchmark_timer_read().
48 *
49 *  AVG_OVEREHAD is the overhead for starting and stopping the timer.  It
50 *  is usually deducted from the number returned.
51 *
52 *  LEAST_VALID is the lowest number this routine should trust.  Numbers
53 *  below this are "noise" and zero is returned.
54 */
55
56#define AVG_OVERHEAD      0  /* It typically takes X.X microseconds */
57                             /* (Y countdowns) to start/stop the timer. */
58                             /* This value is in microseconds. */
59#define LEAST_VALID       1  /* Don't trust a clicks value lower than this */
60
61benchmark_timer_t benchmark_timer_read( void )
62{
63  uint16_t t;
64  uint32_t total;
65  t = TC_TC0_REG(TC_CV);
66
67  /*
68   *  Total is calculated by taking into account the number of timer overflow
69   *  interrupts since the timer was initialized and clicks since the last
70   *  interrupts.
71   */
72
73  total = t * tick_time;
74
75  if ( benchmark_timer_find_average_overhead == 1 )
76    return total;          /* in nanosecond units */
77  else {
78    if ( total < LEAST_VALID )
79      return 0;            /* below timer resolution */
80  /*
81   *  Somehow convert total into microseconds
82   */
83      return (total - AVG_OVERHEAD);
84    }
85}
86
87void benchmark_timer_disable_subtracting_average_overhead(bool find_flag)
88{
89  benchmark_timer_find_average_overhead = find_flag;
90}
91
Note: See TracBrowser for help on using the repository browser.