source: rtems/c/src/lib/libcpu/bfin/timer/timer.c @ c080c343

4.11
Last change on this file since c080c343 was c499856, checked in by Chris Johns <chrisj@…>, on Mar 20, 2014 at 9:10:47 PM

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

  • Property mode set to 100644
File size: 2.5 KB
Line 
1/*  Timer for Blackfin
2 *
3 *  This file manages the benchmark timer used by the RTEMS Timing Test
4 *  Suite.  Each measured time period is demarcated by calls to
5 *  benchmark_timer_initialize() and benchmark_timer_read().  benchmark_timer_read() usually returns
6 *  the number of microseconds since benchmark_timer_initialize() exitted.
7 *
8 *  Copyright (c) 2006 by Atos Automacao Industrial Ltda.
9 *             written by Alain Schaefer <alain.schaefer@easc.ch>
10 *                    and Antonio Giovanini <antonio@atos.com.br>
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
17
18#include <rtems.h>
19#include <bsp.h>
20
21
22uint32_t         Timer_interrupts;
23bool benchmark_timer_find_average_overhead;
24
25/*
26 * benchmark_timer_initialize
27 *
28 * Blackfin processor has a counter for clock cycles.
29 */
30void benchmark_timer_initialize( void )
31{
32
33  /*reset counters*/
34  __asm__ ("R2 = 0;");
35  __asm__ ("CYCLES = R2;");
36  __asm__ ("CYCLES2 = R2;");
37  /*start counters*/
38  __asm__ ("R2 = SYSCFG;");
39  __asm__ ("BITSET(R2,1);");
40  __asm__ ("SYSCFG = R2");
41
42}
43
44/*
45 *  The following controls the behavior of benchmark_timer_read().
46 *
47 *  AVG_OVEREHAD is the overhead for starting and stopping the timer.  It
48 *  is usually deducted from the number returned.
49 *
50 *  LEAST_VALID is the lowest number this routine should trust.  Numbers
51 *  below this are "noise" and zero is returned.
52 */
53
54#define AVG_OVERHEAD      0  /* It typically takes X.X microseconds */
55                             /* (Y countdowns) to start/stop the timer. */
56                             /* This value is in microseconds. */
57#define LEAST_VALID       1  /* Don't trust a clicks value lower than this */
58
59int benchmark_timer_read( void )
60{
61  uint32_t          clicks;
62  uint32_t          total;
63  register uint32_t cycles __asm__ ("R2");
64
65  /* stop counter */
66  __asm__ ("R2 = SYSCFG;");
67  __asm__ ("BITCLR(R2,1);");
68  __asm__ ("SYSCFG = R2;");
69  __asm__ ("R2 = CYCLES;");
70
71
72  clicks = cycles; /* Clock cycles */
73
74  /* converting to microseconds */
75  total = clicks / (CCLK/1000000);
76
77  if ( benchmark_timer_find_average_overhead == 1 )
78    return total;          /* in XXX microsecond units */
79  else {
80    if ( total < LEAST_VALID )
81      return 0;            /* below timer resolution */
82  /*
83   *  Somehow convert total into microseconds
84   */
85      return (total - AVG_OVERHEAD);
86    }
87}
88
89void benchmark_timer_disable_subtracting_average_overhead(bool find_flag)
90{
91  benchmark_timer_find_average_overhead = find_flag;
92}
Note: See TracBrowser for help on using the repository browser.