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

4.104.114.84.95
Last change on this file since 4d6b3b6 was 4d6b3b6, checked in by Joel Sherrill <joel.sherrill@…>, on Jan 12, 2001 at 1:28:27 PM

2001-01-12 Joel Sherrill <joel@…>

  • include/bsp.h, timer/timer.c: Updated so timer appears to work and support tm27. I would prefer to time a software interrupt rather than an use an extra timer though.
  • Property mode set to 100644
File size: 2.3 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 found in the file LICENSE in this distribution or at
11 *  http://www.OARcorp.com/rtems/license.html.
12 *
13 *  $Id$
14 */
15
16#include <assert.h>
17
18#include <bsp.h>
19
20rtems_boolean Timer_driver_Find_average_overhead;
21
22void Timer_initialize()
23{
24  /*
25   *  Programming the compare register as the maximum value should let
26   *  it run long enough and accurate enough not to require an interrupt.
27   *  but if it ever does generate an interrupt, we will simply fault.
28   *
29   *  NOTE:  This is similar to the clock driver initialization
30   *         with the exception that the divider is disabled and
31   *         the compare register is set to the maximum value.
32   */
33
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, 0x8001 );
39  TX3904_TIMER_WRITE( TX3904_TIMER1_BASE, TX3904_TIMER_TCR,   0x20 );
40  TX3904_TIMER_WRITE( TX3904_TIMER1_BASE, TX3904_TIMER_TCR,   0xe0 );
41}
42
43#define AVG_OVERHEAD      0  /* It typically takes N instructions */
44                             /*     to start/stop the timer. */
45#define LEAST_VALID       1  /* Don't trust a value lower than this */
46                             /* tx39 simulator can count instructions. :) */
47
48int Read_timer()
49{
50  rtems_unsigned32  total;
51
52  TX3904_TIMER_WRITE( TX3904_TIMER1_BASE, TX3904_TIMER_TCR,   0x03 );
53  total = TX3904_TIMER_READ( TX3904_TIMER1_BASE, TX3904_TIMER_TRR );
54
55  if ( Timer_driver_Find_average_overhead == 1 )
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
64rtems_status_code Empty_function( void )
65{
66  return RTEMS_SUCCESSFUL;
67}
68
69void Set_find_average_overhead(
70  rtems_boolean find_flag
71)
72{
73  Timer_driver_Find_average_overhead = find_flag;
74}
Note: See TracBrowser for help on using the repository browser.