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