source: rtems/c/src/lib/libbsp/mips/genmongoosev/timer/timer.c @ 3774c7f

4.104.114.84.95
Last change on this file since 3774c7f was 3774c7f, checked in by Joel Sherrill <joel.sherrill@…>, on Feb 1, 2002 at 7:30:54 PM

2001-02-01 Greg Menke <gregory.menke@…>

  • include/lr33000.h, include/lr330x0.h, include/r3000.h, start/mg5.h: New files missed in previous commit.
  • timer/timer.c: Use rtems/bspIo.h not just bspIo.h.
  • Property mode set to 100644
File size: 2.6 KB
Line 
1/*
2 *  This file implements a benchmark timer using a MONGOOSE-V timer.
3 *
4 *  COPYRIGHT (c) 1989-2001.
5 *  On-Line Applications Research Corporation (OAR).
6 *
7 *  The license and distribution terms for this file may be
8 *  found in found in the file LICENSE in this distribution or at
9 *  http://www.OARcorp.com/rtems/license.html.
10 *
11 *  $Id$
12 */
13
14#include <assert.h>
15
16#include <bsp.h>
17
18rtems_boolean Timer_driver_Find_average_overhead;
19
20#if defined(USE_TIMER2_FOR_CLOCK)
21#define TIMER_BASE   MONGOOSEV_TIMER1_BASE
22#define TIMER_VECTOR MONGOOSEV_IRQ_TIMER1
23#else
24#define TIMER_BASE   MONGOOSEV_TIMER2_BASE
25#define TIMER_VECTOR MONGOOSEV_IRQ_TIMER2
26#endif
27
28void Timer_initialize()
29{
30  /*
31   *  Programming the compare register as the maximum value should let
32   *  it run long enough and accurate enough not to require an interrupt.
33   *  but if it ever does generate an interrupt, we will simply fault.
34   *
35   *  NOTE:  This is similar to the clock driver initialization
36   *         with the exception that the divider is disabled and
37   *         the compare register is set to the maximum value.
38   */
39
40   MONGOOSEV_WRITE_REGISTER( TIMER_BASE, MONGOOSEV_TIMER_CONTROL_REGISTER, 0);
41
42   MONGOOSEV_WRITE_REGISTER( TIMER_BASE,
43                             MONGOOSEV_TIMER_INITIAL_COUNTER_REGISTER,
44                             0xffffffff );
45
46   MONGOOSEV_WRITE_REGISTER( TIMER_BASE,
47                             MONGOOSEV_TIMER_CONTROL_REGISTER,
48                             MONGOOSEV_TIMER_CONTROL_COUNTER_ENABLE );
49
50}
51
52#define AVG_OVERHEAD      0  /* It typically takes N instructions */
53                             /*     to start/stop the timer. */
54
55#define LEAST_VALID       1  /* Don't trust a value lower than this */
56                             /* mongoose-v can count cycles. :) */
57#include <rtems/bspIo.h>
58
59int Read_timer()
60{
61  rtems_unsigned32  clicks;
62  rtems_unsigned32  total;
63  rtems_unsigned32  tcr;
64
65  clicks = MONGOOSEV_READ_REGISTER( TIMER_BASE,
66                                    MONGOOSEV_TIMER_INITIAL_COUNTER_REGISTER );
67  total = 0xffffffff - clicks;
68
69  tcr = MONGOOSEV_READ_REGISTER( TIMER_BASE, MONGOOSEV_TIMER_CONTROL_REGISTER );
70
71  MONGOOSEV_WRITE_REGISTER( TIMER_BASE, 
72                            MONGOOSEV_TIMER_CONTROL_REGISTER, 
73                            0 );
74
75  if ( tcr & MONGOOSEV_TIMER_CONTROL_TIMEOUT )
76    printk( "MG5 timer overran\n" );
77
78  if ( Timer_driver_Find_average_overhead == 1 )
79    return total;          /* in cycle units */
80
81  if ( total < LEAST_VALID )
82    return 0;            /* below timer resolution */
83
84  return (total - AVG_OVERHEAD) / CPU_CLOCK_RATE_MHZ;
85}
86
87rtems_status_code Empty_function( void )
88{
89  return RTEMS_SUCCESSFUL;
90}
91
92void Set_find_average_overhead(
93  rtems_boolean find_flag
94)
95{
96  Timer_driver_Find_average_overhead = find_flag;
97}
98
99
100/* eof */
Note: See TracBrowser for help on using the repository browser.