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

4.104.115
Last change on this file since 5b301ab was e53fbe8d, checked in by Ralf Corsepius <ralf.corsepius@…>, on 09/05/08 at 05:03:36

Convert to "bool".

  • 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.rtems.com/license/LICENSE.
10 *
11 *  $Id$
12 */
13
14#include <assert.h>
15
16#include <bsp.h>
17
18bool benchmark_timer_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 benchmark_timer_initialize(void)
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 benchmark_timer_read(void)
60{
61  uint32_t          clicks;
62  uint32_t          total;
63  uint32_t          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 ( benchmark_timer_find_average_overhead == true )
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
87void benchmark_timer_disable_subtracting_average_overhead(
88  bool find_flag
89)
90{
91  benchmark_timer_find_average_overhead = find_flag;
92}
93
94/* eof */
Note: See TracBrowser for help on using the repository browser.