source: rtems/c/src/lib/libbsp/mips/jmr3904/timer/timer.c @ 8fbe2e6

4.115
Last change on this file since 8fbe2e6 was 8fbe2e6, checked in by Joel Sherrill <joel.sherrill@…>, on 09/04/14 at 13:59:49

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.2 KB
Line 
1/*
2 *  This file implements a benchmark timer using a TX39 timer.
3 *
4 *  NOTE: On the simulator, the count directly reflects instructions.
5 *
6 *  COPYRIGHT (c) 1989-2000.
7 *  On-Line Applications Research Corporation (OAR).
8 *
9 *  The license and distribution terms for this file may be
10 *  found in the file LICENSE in this distribution or at
11 *  http://www.rtems.org/license/LICENSE.
12 */
13
14#include <assert.h>
15
16#include <bsp.h>
17#include <rtems/btimer.h>
18
19bool benchmark_timer_find_average_overhead;
20
21void benchmark_timer_initialize(void)
22{
23  /*
24   *  Programming the compare register as the maximum value should let
25   *  it run long enough and accurate enough not to require an interrupt.
26   *  but if it ever does generate an interrupt, we will simply fault.
27   *
28   *  NOTE:  This is similar to the clock driver initialization
29   *         with the exception that the divider is disabled and
30   *         the compare register is set to the maximum value.
31   */
32
33  TX3904_TIMER_WRITE( TX3904_TIMER1_BASE, TX3904_TIMER_TCR,   0x20 );
34  TX3904_TIMER_WRITE( TX3904_TIMER1_BASE, TX3904_TIMER_CCDR, 0x3 );
35  TX3904_TIMER_WRITE( TX3904_TIMER1_BASE, TX3904_TIMER_TRR, 0x0 );
36  TX3904_TIMER_WRITE( TX3904_TIMER1_BASE, TX3904_TIMER_CPRA, 0xFFFFFFFF );
37  TX3904_TIMER_WRITE( TX3904_TIMER1_BASE, TX3904_TIMER_TISR, 0x00 );
38  TX3904_TIMER_WRITE( TX3904_TIMER1_BASE, TX3904_TIMER_ITMR, 0x0001 );
39  TX3904_TIMER_WRITE( TX3904_TIMER1_BASE, TX3904_TIMER_TCR,   0xe0 );
40}
41
42#define AVG_OVERHEAD      0  /* It typically takes N instructions */
43                             /*     to start/stop the timer. */
44#define LEAST_VALID       1  /* Don't trust a value lower than this */
45                             /* tx39 simulator can count instructions. :) */
46
47benchmark_timer_t benchmark_timer_read(void)
48{
49  uint32_t          total;
50
51  total = TX3904_TIMER_READ( TX3904_TIMER1_BASE, TX3904_TIMER_TRR );
52
53  if ( benchmark_timer_find_average_overhead == true )
54    return total;          /* in one microsecond units */
55
56  if ( total < LEAST_VALID )
57    return 0;            /* below timer resolution */
58
59  return total - AVG_OVERHEAD;
60}
61
62void benchmark_timer_disable_subtracting_average_overhead(
63  bool find_flag
64)
65{
66  benchmark_timer_find_average_overhead = find_flag;
67}
Note: See TracBrowser for help on using the repository browser.