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

4.104.114.84.95
Last change on this file since f849f3e was f849f3e, checked in by Joel Sherrill <joel.sherrill@…>, on 03/14/01 at 17:19:53

2001-02-22 Joel Sherrill <joel@…>

  • The Generic Mongoose-V BSP uses only the peripherals found on the Synova Mongoose-V CPU. This is a radiation hardened CPU based on the LSI Logic 33K.
  • .cvsignore, ChangeLog?, Makefile.am, README, bsp_specs, configure.in, clock/.cvsignore, clock/Makefile.am, clock/clockdrv.c, console/.cvsignore, console/Makefile.am, console/conscfg.c, include/.cvsignore, include/Makefile.am, include/bsp.h, start/.cvsignore, start/Makefile.am, start/regs.S, start/start.S, startup/.cvsignore, startup/Makefile.am, startup/bspstart.c, startup/linkcmds, timer/.cvsignore, timer/Makefile.am, timer/timer.c, wrapup/.cvsignore, wrapup/Makefile.am: New files.
  • Property mode set to 100644
File size: 2.5 KB
Line 
1/*
2 *  This file implements a benchmark timer using a MONGOOSE-V 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
22#if defined(USE_TIMER2_FOR_CLOCK)
23#define TIMER_BASE   MONGOOSEV_TIMER1_BASE
24#define TIMER_VECTOR MONGOOSEV_IRQ_TIMER1
25#else
26#define TIMER_BASE   MONGOOSEV_TIMER2_BASE
27#define TIMER_VECTOR MONGOOSEV_IRQ_TIMER2
28#endif
29
30void Timer_initialize()
31{
32  /*
33   *  Programming the compare register as the maximum value should let
34   *  it run long enough and accurate enough not to require an interrupt.
35   *  but if it ever does generate an interrupt, we will simply fault.
36   *
37   *  NOTE:  This is similar to the clock driver initialization
38   *         with the exception that the divider is disabled and
39   *         the compare register is set to the maximum value.
40   */
41
42  MONGOOSEV_WRITE_REGISTER(
43    TIMER_BASE,
44    MONGOOSEV_TIMER_INITIAL_COUNTER_REGISTER,
45    0xffffffff
46  );
47  MONGOOSEV_WRITE_REGISTER(
48    TIMER_BASE,
49    MONGOOSEV_TIMER_CONTROL_REGISTER,
50    MONGOOSEV_TIMER_CONTROL_COUNTER_ENABLE
51  );
52}
53
54#define AVG_OVERHEAD      0  /* It typically takes N instructions */
55                             /*     to start/stop the timer. */
56#define LEAST_VALID       1  /* Don't trust a value lower than this */
57                             /* mongoose-v can count cycles. :) */
58#include <bspIo.h>
59
60int Read_timer()
61{
62  rtems_unsigned32  clicks;
63  rtems_unsigned32  total;
64  rtems_unsigned32  tcr;
65
66  clicks = MONGOOSEV_READ_REGISTER(
67    TIMER_BASE,
68    MONGOOSEV_TIMER_INITIAL_COUNTER_REGISTER
69  );
70  total = 0xffffffff - clicks;
71
72  tcr = MONGOOSEV_READ_REGISTER( TIMER_BASE, MONGOOSEV_TIMER_CONTROL_REGISTER );
73  if ( tcr & MONGOOSEV_TIMER_CONTROL_TIMEOUT )
74    printk( "MG5 timer overran\n" );
75
76  if ( Timer_driver_Find_average_overhead == 1 )
77    return total;          /* in cycle units */
78
79  if ( total < LEAST_VALID )
80    return 0;            /* below timer resolution */
81
82  return total - AVG_OVERHEAD;
83}
84
85rtems_status_code Empty_function( void )
86{
87  return RTEMS_SUCCESSFUL;
88}
89
90void Set_find_average_overhead(
91  rtems_boolean find_flag
92)
93{
94  Timer_driver_Find_average_overhead = find_flag;
95}
Note: See TracBrowser for help on using the repository browser.