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

4.115
Last change on this file since af3048a was af3048a, checked in by Ralf Corsepius <ralf.corsepius@…>, on 02/09/11 at 06:41:41

2011-02-09 Ralf Corsépius <ralf.corsepius@…>

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