source: rtems/c/src/lib/libcpu/arm/at91rm9200/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.7 KB
RevLine 
[af85485]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>
[359e537]7 *
[af85485]8 *  The license and distribution terms for this file may be
9 *  found in the file LICENSE in this distribution or at
[c499856]10 *  http://www.rtems.org/license/LICENSE.
[af85485]11 *
12 * Notes:
13 *  This file manages the benchmark timer used by the RTEMS Timing Test
14 *  Suite.  Each measured time period is demarcated by calls to
[18bfc42]15 *  benchmark_timer_initialize() and benchmark_timer_read().  benchmark_timer_read() usually returns
16 *  the number of microseconds since benchmark_timer_initialize() exitted.
[af85485]17 *
[359e537]18 *  It is important that the timer start/stop overhead be determined
[af85485]19 *  when porting or modifying this code.
20 */
21
22#include <rtems.h>
23#include <bsp.h>
24#include <at91rm9200.h>
25#include <at91rm9200_pmc.h>
26
[15ebe58b]27uint16_t tstart;
[3551166d]28bool benchmark_timer_find_average_overhead;
[15ebe58b]29uint32_t tick_time;
[af85485]30/*
[359e537]31 * Set up TC0 -
[af85485]32 *   timer_clock2 (MCK/8)
33 *   capture mode - this shouldn't matter
34 */
[18bfc42]35void benchmark_timer_initialize( void )
[af85485]36{
[15ebe58b]37    uint32_t tmr_freq;
[af85485]38
39    /* since we are using timer_clock2, divide mck by 8 */
40    tmr_freq = at91rm9200_get_mck() / 8;
41
42    TC_TC0_REG(TC_CMR) = TC_CMR_TCCLKS(1);   /* timer_clock2 */
43    TC_TC0_REG(TC_CCR) = (TC_CCR_CLKEN       /* enable the counter */
44                          | TC_CCR_SWTRG);   /* start it up */
45
46    /* tick time in nanoseconds */
47    tick_time = 1000000000/tmr_freq;
48
49}
50
51/*
[18bfc42]52 *  The following controls the behavior of benchmark_timer_read().
[af85485]53 *
54 *  AVG_OVEREHAD is the overhead for starting and stopping the timer.  It
55 *  is usually deducted from the number returned.
56 *
57 *  LEAST_VALID is the lowest number this routine should trust.  Numbers
58 *  below this are "noise" and zero is returned.
59 */
60
61#define AVG_OVERHEAD      0  /* It typically takes X.X microseconds */
62                             /* (Y countdowns) to start/stop the timer. */
63                             /* This value is in microseconds. */
64#define LEAST_VALID       1  /* Don't trust a clicks value lower than this */
65
[18bfc42]66int benchmark_timer_read( void )
[af85485]67{
[15ebe58b]68  uint16_t t;
69  uint32_t total;
[af85485]70  t = TC_TC0_REG(TC_CV);
71
72  /*
73   *  Total is calculated by taking into account the number of timer overflow
74   *  interrupts since the timer was initialized and clicks since the last
75   *  interrupts.
76   */
77
78  total = t * tick_time;
79
[18bfc42]80  if ( benchmark_timer_find_average_overhead == 1 )
[af85485]81    return total;          /* in nanosecond units */
82  else {
83    if ( total < LEAST_VALID )
84      return 0;            /* below timer resolution */
85  /*
86   *  Somehow convert total into microseconds
87   */
88      return (total - AVG_OVERHEAD);
89    }
90}
91
[3551166d]92void benchmark_timer_disable_subtracting_average_overhead(bool find_flag)
[af85485]93{
[18bfc42]94  benchmark_timer_find_average_overhead = find_flag;
[af85485]95}
96
Note: See TracBrowser for help on using the repository browser.