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

4.104.114.84.9
Last change on this file since ef380d3f was ef380d3f, checked in by Joel Sherrill <joel.sherrill@…>, on Mar 14, 2001 at 5:24:09 PM

2001-03-14 Joel Sherrill <joel@…>

  • clock/clockdrv.c, console/conscfg.c, include/bsp.h, start/start.S, startup/bspstart.c, timer/timer.c: Comments corrected.
  • Property mode set to 100644
File size: 2.4 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(
41    TIMER_BASE,
42    MONGOOSEV_TIMER_INITIAL_COUNTER_REGISTER,
43    0xffffffff
44  );
45  MONGOOSEV_WRITE_REGISTER(
46    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#define LEAST_VALID       1  /* Don't trust a value lower than this */
55                             /* mongoose-v can count cycles. :) */
56#include <bspIo.h>
57
58int Read_timer()
59{
60  rtems_unsigned32  clicks;
61  rtems_unsigned32  total;
62  rtems_unsigned32  tcr;
63
64  clicks = MONGOOSEV_READ_REGISTER(
65    TIMER_BASE,
66    MONGOOSEV_TIMER_INITIAL_COUNTER_REGISTER
67  );
68  total = 0xffffffff - clicks;
69
70  tcr = MONGOOSEV_READ_REGISTER( TIMER_BASE, MONGOOSEV_TIMER_CONTROL_REGISTER );
71  if ( tcr & MONGOOSEV_TIMER_CONTROL_TIMEOUT )
72    printk( "MG5 timer overran\n" );
73
74  if ( Timer_driver_Find_average_overhead == 1 )
75    return total;          /* in cycle units */
76
77  if ( total < LEAST_VALID )
78    return 0;            /* below timer resolution */
79
80  return total - AVG_OVERHEAD;
81}
82
83rtems_status_code Empty_function( void )
84{
85  return RTEMS_SUCCESSFUL;
86}
87
88void Set_find_average_overhead(
89  rtems_boolean find_flag
90)
91{
92  Timer_driver_Find_average_overhead = find_flag;
93}
Note: See TracBrowser for help on using the repository browser.